Getting points when picking up an item?
by Tom Feni · in General Discussion · 06/28/2004 (7:29 pm) · 18 replies
I have tried a few things but nothing seems to work.. I tried to tie into the scoreboard by using incScore but it wont recognize it.. :)
anyone know a simple code to add points to the score by picking up an item?
anyone know a simple code to add points to the score by picking up an item?
About the author
#2
but it wont go to the scoreboard.. : )
I am no coder so here is what I have..
and in game.cs
all it willd o is pick up the item and tell me about it..
but in the game.cs it wont even echo so I am assuming it skips over that part and misses my little echo statement..
am I way off?
06/29/2004 (6:07 am)
Well I can pick up the coins and it says "you have picked up a coin" but it wont go to the scoreboard.. : )
I am no coder so here is what I have..
coin.cs
//--------------------------------------------------
//
// Coin Data
//
//--------------------------------------------------
datablock ShapeBaseImageData(CoinImage)
{
shapeFile = "~/data/shapes/flowerIcon/flowerCoin.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/shapes/flowerIcon/flowerCoin.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)
{
}and in game.cs
// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}
%client.score += %item.scoreValue;
echo("you got a coin");all it willd o is pick up the item and tell me about it..
but in the game.cs it wont even echo so I am assuming it skips over that part and misses my little echo statement..
am I way off?
#3
06/29/2004 (6:11 am)
Have you tried implementing the score incrementation in the onCollision() method?
#4
hmmm..
*should it be %client, and %item or %this,%obj?
06/29/2004 (6:24 am)
Tried it, still wont go to points..function Coin::onCollision(%client,%item)
{
%client.score += %item.scoreValue;
echo("you got a coin");
}hmmm..
*should it be %client, and %item or %this,%obj?
#5
Or in this case..
06/29/2004 (6:26 am)
You should add it to ItemData::onPickup().Or in this case..
function Coin::onPickup(%this,%obj,%user,%amount)
{
if (%user.client)
{
messageClient(%user.client,'MsgCoin','\c0You got a coin');
%user.client.incScore(%this.scoreValue);
}
#6
and it gives points.. Woot!
but it doesnt pickup the coin and I dont get a saying.. :)
when I added your code it would error on the
do I need to add 'MsgCoin' somewhere?
06/29/2004 (6:47 am)
Ok did thisfunction Coin::onPickup(%this,%obj,%user,%amount)
{
if (%user.client){
%user.client.incScore(%this.scoreValue);
}
}and it gives points.. Woot!
but it doesnt pickup the coin and I dont get a saying.. :)
when I added your code it would error on the
messageClient(%user.client,'MsgCoin','\c0You got a coin');part
do I need to add 'MsgCoin' somewhere?
#7
then change msg line to.
06/29/2004 (7:20 am)
Ok add this above that code.%count = %obj.count;
if (%count $= "")
if (%this.maxInventory !$= "") {
if (!(%count = %this.maxInventory))
return;
}
else
%count = 1;
%user.incInventory(%this,%count);then change msg line to.
messageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1', %this.pickupName);
#8
now it picks up says I have a coin but now wont add to points.. :)
wooh! ok now it errors on
messageClient(%user.client, 'MsgItemPickup'#;#, '\c0You picked up '';, %this.pickupName);
error #;#
man this is both hard and fun trying to figure it out.. :)
full code
ignore this I am a moron..
when i deleted the ' error thing i foprgot to remove the ";"
trying again
06/29/2004 (7:49 am)
LOL, man this is nuts.. :)now it picks up says I have a coin but now wont add to points.. :)
wooh! ok now it errors on
messageClient(%user.client, 'MsgItemPickup'#;#, '\c0You picked up '';, %this.pickupName);
error #;#
man this is both hard and fun trying to figure it out.. :)
full code
function Coin::onCollision(%this,%obj,%user,%count)
{
%count = %obj.count;
if (%count $= "")
if (%this.maxInventory !$= ""){
if (!(%count = %this.maxInventory))
return;
}
else
%count = 1;
%user.incInventory(%this,%count);
}
function Coin::onPickup(%user,%this)
{
if (%user.client){
//messageClient(%user.client,'MsgCoin','\c0You got a coin');
messageClient(%user.client, 'MsgItemPickup';, '\c0You picked up '';, %this.pickupName);
%user.client.incScore(%this.scoreValue);
}
}ignore this I am a moron..
when i deleted the ' error thing i foprgot to remove the ";"
trying again
#9
%client.score += %item.scoreValue;
echo("you got a coin");
Now, your next problem is, you had your onCollision code all wrong, here is what it should be...
Give that a shot and see if it works for you.
EDIT: PS. I included some useful debug code that you can copy paste to other functions. You can and will learna tremendous amount about the flow of your functions if you echo them as you work with them. Also, don't be afraid to run a trace or two to get a very detailed description of what is happening during certain event's.
06/29/2004 (7:52 am)
Ok, first off, your datablock looks fine. next, take these lines out of game.cs%client.score += %item.scoreValue;
echo("you got a coin");
Now, your next problem is, you had your onCollision code all wrong, here is what it should be...
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("You got the coin");
return;
}
echo("Coin Pickup failed");
}Give that a shot and see if it works for you.
EDIT: PS. I included some useful debug code that you can copy paste to other functions. You can and will learna tremendous amount about the flow of your functions if you echo them as you work with them. Also, don't be afraid to run a trace or two to get a very detailed description of what is happening during certain event's.
#10
messageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1', %this.pickupName);
06/29/2004 (7:59 am)
Corrected message linemessageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1', %this.pickupName);
#11
06/29/2004 (8:02 am)
Here is the collision function I made for you with a new message line in it...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;
messageClient(%col.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!', %this.pickupName, %this.scoreValue);
return;
}
echo("Coin Pickup failed");
}
#12
man this is frustrating me.. :)
oh well.. I am waiting on the 3d game programming all in one book.. :)
so soon I will have a good resource to get this info.. :)
here is a pic of the error..

probably wont help much...
I have to get off and watch the kids so maybe I can get this later.. :)
06/29/2004 (8:37 am)
Ok added it and still get an error on the message part.. man this is frustrating me.. :)
oh well.. I am waiting on the 3d game programming all in one book.. :)
so soon I will have a good resource to get this info.. :)
here is a pic of the error..

probably wont help much...
I have to get off and watch the kids so maybe I can get this later.. :)
#13
Copy paste this line into it's place....
Also, make sure you change %user.client to %col.client or it wont message you.
06/29/2004 (8:50 am)
Actually it did, I copied and modified the original message line you had without noticing the other errors...Copy paste this line into it's place....
messageClient(%col.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!', %this.pickupName, %this.scoreValue);
Also, make sure you change %user.client to %col.client or it wont message you.
#14
this characther is the right character...
'
until the forum code changes it.
Replace every instance of...
´
with the ' character that is directly next to the ENTER key.
That should cure your problem.
You cannot copy paste this line into your game because the ' characters are being changed to the wrong character.....
messageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!', %this.pickupName, %this.scoreValue);
06/29/2004 (8:56 am)
Ok, the problem is the GG forums...this characther is the right character...
'
until the forum code changes it.
Replace every instance of...
´
with the ' character that is directly next to the ENTER key.
That should cure your problem.
You cannot copy paste this line into your game because the ' characters are being changed to the wrong character.....
messageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1 worth %2 points!!', %this.pickupName, %this.scoreValue);
#15
this works for the most part
but now it wont score.. :)
I fix one and another dies.. :)
06/29/2004 (10:23 am)
Weirder and weirder.. :)this works for the most part
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;
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");
}but now it wont score.. :)
I fix one and another dies.. :)
#16
it works now.. :)
code
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");
}
fun stuff
now to tie the gui into the main playgui so you can watch your coins add up.. :)
also tie into endgame so it ends at 1000 points.. :) or by time limit..
thanks for your help gonzo.. :)
I will put you in the credits.. :) for tech support..
06/29/2004 (11:00 am)
Fixed itit works now.. :)
code
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");
}
fun stuff
now to tie the gui into the main playgui so you can watch your coins add up.. :)
also tie into endgame so it ends at 1000 points.. :) or by time limit..
thanks for your help gonzo.. :)
I will put you in the credits.. :) for tech support..
#17
BTW, I suspect that the reason this scoring line didn't work for you....
%col.client.score += %this.scoreValue;
is because the variable %client.score never existed so the statement fails to execute.
meaning, when your client logs into the game, and gets his player and all that, if you initialized the variable using...
%client.score = 0;
Then the scoring line above should work perfectly. In my games I usually make sure to initialize every neccesary client variables before they ever even get into the game. That way such statements as the one above doesn't cause these types of bugs or glitches.
06/29/2004 (1:08 pm)
No problem. My email is in my profile. You can contact me through it if you need something debugged or need to ask some questions. I'm currently building two games so you don't have to worry about me stealing your ideas, lol. And I'd sign an NDA for you if it would make you more comfortable. Thanks for the credit, it's always nice to be recognized for ones contributions.BTW, I suspect that the reason this scoring line didn't work for you....
%col.client.score += %this.scoreValue;
is because the variable %client.score never existed so the statement fails to execute.
meaning, when your client logs into the game, and gets his player and all that, if you initialized the variable using...
%client.score = 0;
Then the scoring line above should work perfectly. In my games I usually make sure to initialize every neccesary client variables before they ever even get into the game. That way such statements as the one above doesn't cause these types of bugs or glitches.
#18
I changed the game type and it wont load.. lol
using the ctf code I played around resetting and adding code to see how to make it CoinCollect.. :)
but I must have missed something somewhere.. so I went nuts and changed everthing from starter.fps to coincollect or Toons.. :) so now its really borked.. lol
good thing i had a back up.. :)
so i went back to modeling for a bit..
my first weapon..

now to learn animations.. :)
* and the skins are not doen yet.. :)
its just place art for now.. :)
06/29/2004 (4:11 pm)
Well now I am in a big pile.. :)I changed the game type and it wont load.. lol
using the ctf code I played around resetting and adding code to see how to make it CoinCollect.. :)
but I must have missed something somewhere.. so I went nuts and changed everthing from starter.fps to coincollect or Toons.. :) so now its really borked.. lol
good thing i had a back up.. :)
so i went back to modeling for a bit..
my first weapon..

now to learn animations.. :)
* and the skins are not doen yet.. :)
its just place art for now.. :)
Torque Owner Gonzo T. Clown
%item.scoreValue = 5; (or whatever score)
And then use
%client.score += %item.scoreValue;
When you pick up the item.
Or you can use
%client.incScore(5);
Either one of those should work. If you are going to use lots of different items, I would use the first suggestion (%item.scoreValue) to set each items value so that you can catch them with one or two lines of code instead of having to check each item to see what it is and then score it accordingly.