Game Development Community

In-game Text to display score tutorial

by Stephen Sinclair · in Torque Game Engine · 05/02/2007 (12:57 pm) · 2 replies

Hi,

I have a simple question. I found a tutorial a while back on creating a text control in the mission using the GUI editor. The score updates and displays. I can't for like of me remember where that tutorial is. Anybody know where there is a good in-game score keeping tutorial that is basic? I am just now trying to figure out how to update a textbox on the screen while playing the game...


Thanks
Steve

#1
05/02/2007 (1:09 pm)
You could check out how the countdown before the race start is done in the starter.racing example.
#2
05/02/2007 (1:33 pm)
Felt like being a bit more helpfull so... Here's some code that should work

in common/server/clientConnection.cs at the bottom change the incScore function to look like this
function GameConnection::incScore(%this,%delta)
{
   %this.score += %delta;
   messageAll('MsgClientScoreChanged', "", %this.score, %this);
   messageClient(%this, 'MsgMyClientScoreChanged', "", %this.score); // add this line
}
in starter.fps/client/scripts/playerlist.cs below
addMessageCallback('MsgClientJoin', handleClientJoin);
addMessageCallback('MsgClientDrop', handleClientDrop);
addMessageCallback('MsgClientScoreChanged', handleClientScoreChanged);
add
addMessageCallback('MsgMyClientScoreChanged', handleMyClientScoreChanged);
after
function handleClientScoreChanged(%msgType, %msgString, %score, %clientId)
{
   PlayerListGui.updateScore(%clientId,%score);
}
add
function handleMyClientScoreChanged(%msgType, %msgString, %score)
{
   ScoreHud.updateScore(%score);
}
now create a new textCtrl and name it ScoreHud or something (if you use another name change the above function)
then add a new function for example in client/scripts/game.cs or client/scripts/playGui.cs like this
function ScoreHud::UpdateScore(%this, %score)
{
   %this.setText("Score = " @ %score);
}

edit: made unclear part more clear