Game Development Community

Noob question about scoring

by starwize · in Torque Game Engine · 04/06/2005 (10:59 am) · 5 replies

Ive searched the forums and found info about setting up scoring in starter.fps. I've made changes in two places: Item.cs and playGui.gui. This is what I added to my Item.cs:


datablock ShapeBaseImageData(CoinImage)
{
shapeFile = "~/data/models/items/kash1.dts";
item = Coin;

lightType = "PulsingLight";
lightColor = "1.0 0.2 0.2 1.0";
lightTime = "1000";
lightRadius = "7";
cloakable = false;
};

datablock ItemData(Coin)
{
category = "Coins";
image = CoinImage;
shapefile = "~/data/models/items/kash1.dts";
mass = 55;
elasticity = 0.2;
friction = 0.6;
pickupRadius = 3;
pickUpName = "a Coin";
computeCRC = true;


lightType = "PulsingLight";
lightColor = "1.0 0.2 0.2 1.0";
lightTime = "1000";
lightRadius = "7";

isInvincible = true;
scoreValue = 25;// (or whatever score)
};



function Coin::onCollision(%this,%obj,%col)
{
echo("Coin collision %this = " @ %this @ " %obj = " @ %obj @ " %col = " @ %col);
if (%col.getDataBlock().className $= Armor)

%col.client.incScore(%this.scoreValue);
echo("score");
messageClient(%col.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!', %this.pickupName, %this.scoreValue);
echo("picked up a coin");
%obj.respawn();
return;


echo("Coin Pickup failed");
}



Everything works (item pickup, message) except it isn't showing up on my score box (still shows '0'). In my playGui.gui, I have the following:

new GuiTextCtrl(Score) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "559 4";
extent = "100 20";
minExtent = "8 8";
visible = "1";
text = "0";
maxLength = "255";
helpTag = "0";
};

I can't figure out what I'm missing. Thanks in advance for any help.

#1
04/06/2005 (11:36 am)
Couple of things:

1) Do you have a function called "incScore" that you aren't showing?
2) The reason it isn't showing in your GUI window is because you've hard-coded your test to be "0". You need to link in the variable to be displayed in the GUI instead.

What you need to do is to have a function that updates your GUI with the appropriate value (or you can hard code it directly in).

It would look something like:

Score.setValue(%col.client.score); // (assuming %client.score is your actual count variable that contains the player's individual score).

EDIT: Fixed usage error in .setValue()
#2
04/06/2005 (1:21 pm)
No, I haven't define incScore anywhere. Where would I put this? I am also confused about updating the GUI with the current score. Where would I put this : Score.setValue = %col.client.score ? In Items.cs or somewhere else?
#3
04/06/2005 (1:32 pm)
I can't really "tell" you where to put it, it's all dependent on how you write your code.

You could put the Score.setValue line in the incScore() function you have to write, and you would probably need to write your incScore function as part of the script GameConnection:: namespace (GameConnection::incScore() ), but that's only because of how you showed us in your example.

Of course, you don't -need- to create an incScore function, you can do that inline if you like, but it is a good design technique to write access methods like that instead of simply changing the values directly. That's a completely different topic however related to Software Design principles!

For your immediate question (and this isn't well-designed code or anything, just the brute force answer):

function Coin::onCollision(%this,%obj,%col)
{
echo("Coin collision %this = " @ %this @ " %obj = " @ %obj @ " %col = " @ %col);
if (%col.getDataBlock().className $= Armor)

%col.client.Score += %this.scoreValue;
echo("score");
messageClient(%col.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!', %this.pickupName, %this.scoreValue);
echo("picked up a coin");
Score.setValue(%col.client.Score); // NOTE: I typoed in my previous example, this is the way to call setValue.
%obj.respawn();
return;


echo("Coin Pickup failed");
}
#4
04/06/2005 (1:49 pm)
Works like a champ now. Thanks very much for the help!!
#5
09/08/2005 (3:39 am)
From where i can find kash1.dts