Game Development Community

score counter programming problems

by Christopher Tall · in Torque Game Engine · 06/07/2009 (1:02 pm) · 9 replies

I'm having a bit of trouble with a program I made for a game. In the game, there are ten items that I want the player to collect, and when he collects them, I want the item to disappear and add 1 to the score counter. Until of course he collects all 10, then a message will pop up. I made the score counter in the gui editor and it is on the top right of the screen. It simply says before any of the items are collected: "Items: 0". And the score counters name is simply: "ScoreCounter". The program works fine except, when the player bumps into the item, and the item dissapears, it does not add 1 to the score counter. I would like to know why it won't add 1 to the score counter every time the player gets an item. here is the code.



function Item::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
%client = %col.client;
%client.score++;
commandToClient(%client, 'SetScoreCounter', %client.score);
obj.delete();
%itemCount = Items.getCount();
if(%itemCount > 0)
return;
//otherwise display victory screen
commandToClient(%client, 'ShowVictory', %client.score);
}
}


Can anyone see why this code may be faulty?

#1
06/08/2009 (6:21 pm)
Well, No just this is the problem. I have some videotutorials in www.torquesil.com with some example with the problem that you have, I guess is the 6, indeed I changed the variable names to make a best example.
#2
06/09/2009 (1:22 pm)
Did you forget to define the SetScoreCounter and ShowVictory functions in a client side script? I have a client side script named clientGame.cs where I defined the functions:
function clientCmdSetScoreCounter(%score)
{
   ScoreCounter.setText("Score:" SPC %score);  
}

function clientCmdShowVictory(%score)
{
   MessageBoxYesNo("You Win!", "Your Score: " @ %score @ "nWould you like to restart the game?",
      "loadMyMission();", "quit();");  
}
#3
06/09/2009 (2:44 pm)
Yes, that is exactly what I wrote. That is my victory script. Although, instead of putting the("You Win!", "Your Score: " @ %score @, I put: ("You found all the skulls!, "You want to play again?",. I put it in a .cs file named ClientMsg.cs. I've looked over that script countless times to see if there is anything wrong with it. And both scripts are exactly as shown in the book.

#4
06/10/2009 (8:44 am)
The only other thing I can think of is if your client script isn't being executed. I call mine in the main.cs script in my game's base folder, in the initClient() function.
#5
06/11/2009 (2:24 pm)
Look at the console to see if you see any errors when loading up your game and also when you collide with the skulls - also, you may want to try and execute the function manually via the console to see if it even works. Try this and let us knows your results.
#6
06/13/2009 (1:42 pm)
Yes, there is an error in the console, I don't know why I didn't think to check before! It seems it's on line one of the clientMsg.cs file. That is not the file I thought would be the problem. But anyways here is what it says:

starter.fps/client/scripts/clientMsg.cs Line: 1 - parse error
>>> Advanced script error report. Line 1.
>>> Some error context, with ## on sides of error halt:
/rtf1/mac/ansicpg10000/cocoartf824/cocoasubrtf420
##{##/fonttbl/f0/fswiss/fcharset77 Helvetica;}
{/colorbl;/red255/green255/blue255;}
/margl1440/margr1440/vieww25100/viewh15040/viewkind0
/pard/tx720/tx1440/tx2160/tx2880/tx3600/tx4320/tx5040/tx5760/tx6480/
tx7200/tx7920/tx8640/ql/qnatural/pardirnatural

/f0/fs24 /cf0 funcion clientCmdSetScoreCounter(%score)/
>>> Error report complete.

And thats the whole thing, to me it mostly looks like jibberish, except for the end it gives part of my code, I'm guessing the part thats glitchy. But I don't see anything wrong with it. Thanks again.
#7
06/13/2009 (4:48 pm)
Quote:starter.fps/client/scripts/clientMsg.cs Line: 1 - parse error

It's telling you you eather have a semicolon in the wrong place, or you are missing one.
#8
10/05/2009 (5:18 pm)
Has anyone found the solution to this problem? I'm having the same issue. Please help!
#9
10/05/2009 (11:18 pm)
I figured it out. It's working now.