Game Development Community

Displaying the contents of a variable in the Hud

by Jeff Trier · in Torque Game Engine · 04/07/2003 (6:20 am) · 17 replies

I read through this ammo tutorial to see if I could figure out how to display a variable(GameScore) in in PlayGui... I am having no luck.

I know this has got to be simple and I am not grasping it.

Could someone push me in the right direction?

Thanks,
-Jeff

About the author

Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.


#1
04/07/2003 (6:29 am)
Try looking at this old tutorial - it takes info from the health meter, turns it into a number and displays the number on the health meter.

May be more than what you want but should give you a good idea of how the whole process works...

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2004
#3
04/07/2003 (6:42 am)
Jeff,

What are you looking to-do? display ammo/clip amounts in the HUD?

IE:

30/6 where 30 is the current ammo in the gun and you have 6 clips

If this is what your seeking, it should not be to difficult to-do. I would start by looking at the guiClockHud code and seeing how it is done.

I have not done it myself, but it has been done by others. Hopefully they will see this post and chime in accordingly.

-Ron
#4
04/07/2003 (6:49 am)
I am trying to display a score on the players hud that will increase when the player picks up different items.

What I have done is create a variable in the players datablock called "Score", and I have created a bonus item based off of the healthpack item.

datablock ItemData(PowerDot)
{
   // Mission editor category, this datablock will show up in the
   // specified category under the "shapes" root category.
   category = "Bonus";

   // Basic Item properties
   shapeFile = "~/data/shapes/Bonus/powerDot.dts";
   mass = 1;
   friction = 1;
   elasticity = 0.3;

   // Dynamic properties defined by the scripts
   repairAmount = 20;
   maxInventory = 0; // No pickup or throw
};

function PowerDot::onCollision(%this,%obj,%col)
{
   // Apply to score when collided by player
   // Works for all shapebase objects.
      if (%col.client)
	%col.client.Score += 1;

	%obj.delete();

	echo(%col.client.Score);
}

When the player collides into the item, it will successfully increment his score. I just can't seem to get it to display.

-Jeff
#5
04/07/2003 (7:03 am)
ah!!

try adding a

messageAll('MsgClientScoreChanged', "", %col.score, %col);

after

%col.client.Score += 1;

or maybe use incScore in server\scripts\clientConnection.cs

-Ron

another place to get a better idea would be to take a look at

onDeath in server\scripts\game.cs
#6
04/07/2003 (8:09 am)
Thanks Ron, it looks like incScore is the way to go if I want to maintain continuity.

One thing I noticed though, after reading the code in PlayerList.cs, I wanted to do a test to see how the stock scoreboard worked. I entered the game and killed myself via Suicide and then with a weapon, but the score didn't change in the scoreboard. Supposedly, it should have minused 1 from the score, and I didn't notice a "Don't -1 if score is 0" if statement.

Can you confirm this?

Thanks Ron,
-Jeff
#7
04/07/2003 (8:23 am)
Have a look at the onDeath() in server\scripts\game.cs their might be something in their that brings light to your inquery

-Ron
#8
04/07/2003 (9:44 am)
Hehe, thanks Ron.

Someday I will get used to all these nooks and crannies in the engine (I hope ;)).

I will have a look when I get home tonight.

Thanks again,
-Jeff
#9
04/07/2003 (9:49 am)
The players score is incremented every time there is a death that is attributed to him AND NOT him :) so he wont get any score change for his own death.

Of course, you could add a "deaths" count into the same data so that you had a ratio (actually quite a nice idea).

Phil.
#10
04/07/2003 (12:44 pm)
Ahh, I see. I will have to look at that.

What confuses me is I thought I remember seeing code which was meant to display a suicide message just before or after the incScore(-1) (I think in PlayerList.cs). I wish I had the code in front of me here at work so I could reference it more accuratly or show you where the confusion lays. hehe... ah well...

Thanks,
-Jeff
#11
04/07/2003 (2:10 pm)
Yes, there is some suicide code and it effectively takes 1 point from your score... or maybe I coded that in in my game? :\
I think it's in torque stock.
#12
04/07/2003 (2:14 pm)
Is that for shooting yourself or for Ctrl-K suicide?

I think it was for Ctrl-K suicide, a penalty for a quick respawn to protect your base in Tribes and Tribes 2
#13
04/07/2003 (3:01 pm)
I did both ctrl-k, and after I respawned I shot my foot until I died. No score change. Very odd.

EDIT:

Now I am wondering... Am I the only one with this "problem"? I suppose it's posible that I had unknowingly changed something that would disable the scoreboard. However, I haven't changed anything in that area.

-Jeff
#14
04/08/2003 (5:49 am)
Ok...

I got it semi working. I can add points to incScore with pickups, but it won't minus points if I die.

The reason why it wouldn't add points was because I was doing this:
%col.client.incScore(+1);
instead of this:
%col.client.incScore(1);

Aside from just not knowing why I don't lose points on death, since it seems to be working for others, I am fine with how it is. Losing points for death in this particular game isn't important.

Thanks,
-Jeff
#15
04/08/2003 (2:38 pm)
Ok, so now that I have established that I can add points to the player via incScore. I can't seem to get it to show up anywhere but in the PlayList.gui.

When the game loads up, it successfully displays "SCORE: 0" as per this line in function GameConnection::onClientEnterGame(%this): %this.setScoreAmountHud("0");

But when I grab a powerDot in the game, the 0 disappears.

Here is powerDot.cs, Item that is just a model that will add 10 pts to the players score when grabbed:
//-----------------------------------------------------------------------------
// Torque Game Engine
// 
// Copyright (c) 2001 GarageGames.Com
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Power Dot to be picked up and added to score
//-----------------------------------------------------------------------------

datablock ItemData(PowerDot)
{
   // Mission editor category, this datablock will show up in the
   // specified category under the "shapes" root category.
   category = "Bonus";

   // Basic Item properties
   shapeFile = "~/data/shapes/Bonus/powerDot.dts";
   mass = 1;
   friction = 1;
   elasticity = 0.3;

   // Dynamic properties defined by the scripts
   repairAmount = 20;
   maxInventory = 0; // No pickup or throw
};

function PowerDot::onCollision(%this,%obj,%col)
{
   // Apply to score when collided by player
   // Works for all shapebase objects.
	if (%col.client){
		echo("Dot Grabbed");
		%score = %col.client.incScore(10);
		echo(%score);
		%col.client.setScoreAmountHud(%score);
		echo(%col.client.setScoreAmountHud(%score));
		%obj.delete();
	}
}

function GameConnection::setScoreAmountHud(%client, %score){
echo("<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++GameConnection::setScoreAmountHud");
	commandToClient(%client, 'SetScoreAmountHud', %score);
}

This is put at the bottom of PlayGui.cs:
function clientCmdSetScoreAmountHud(%Score){
echo("<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++clientCmdSetScoreAmountHud");
	ScoreAmount.setText("Score: " @ %Score);
}

Here is a section of Console.txt that appears when I pick up a Dot:

Dot Grabbed

<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++GameConnection::setScoreAmountHud
<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++GameConnection::setScoreAmountHud

Mapping string: MsgClientScoreChanged to index: 19
<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++clientCmdSetScoreAmountHud
<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++clientCmdSetScoreAmountHud

Sorry if I am being lame, but I can't figure out why %score has no value.

EDIT: I hope I was being clear and I was't causing too much clutter with these examples. But honestly, I am very new and I am not sure what you need to see.

Thanks,
-Jeff
#16
04/09/2003 (4:00 am)
Figured it out, I was being lame... Thanks!

-Jeff
#17
07/31/2004 (8:52 pm)
Sorry for raising the dead but how did you "fix this" just wondering because I am at this point...
if your still around..
:)