Game Development Community

dev|Pro Game Development Curriculum

Arcade style score formatting

by Jeff Murray · 09/05/2006 (11:22 pm) · 6 comments

In my playGui.gui, right at the bottom below //--- OBJECT WRITE END ---, I have a function that gets called to format the string used to display the score with:

function formatString(%string,%zeros){
	
%count = strlen(%string);
	
	 while (%count<%zeros){
		%newString=%newString@"0";
		%count++;		
	}

	%newString=%newString@%string;	
	return %newString;	
}

Obviously, pass in the string and the length of the string you'd like to make (ie. how many zeros you'd like it to add!!) You can see how the function is called in my little score updater script below:

function clientCmdClientScoreChanged(%Score){

        ScoreAmount.setText(formatString(%score,9)); // Where 9 is the length of the score in chars
       
}

That was the end of my little post ... just a tiny function to make your lives easier and your scores more funky ... then I decided, well, why not just keep going and see if we can cover basic scoring too? Here goes ...

Remember, I'm pretty new to this, so be kind if I miss anything ;)

It's basically a modified version of Tim Newells' awesome ammo resource

------------------ REALLY BASIC SCORING ----------------------------------------------------------

First up, make sure you added those two functions above to the very bottom of your playGui.gui script. Once you're sure ...

In server/scripts/game.cs at the bottom of the GameConnection::createPlayer function, add in:

commandToClient(%this, 'ClientScoreChanged', 0);

This resets the score to zero when the player is first added.

Now go into clientConnection.cs and, if you already have an incScore function in there, just add this after the %this.score += %delta; line:

commandToClient(%this, 'ClientScoreChanged', %this.score);

Just incase you don't have that GameConnection::incScore function already, you can add this one (otherwise just skip this bit, as you should have added the right stuff in the last step!! :p):

function GameConnection::incScore(%this,%delta)
{
   
   %this.score += %delta;
   commandToClient(%this, 'ClientScoreChanged', %this.score);
    
}

Finally, we want to add the score when something happens ... you can do this anywhere you need to on the server-side ... but if you are using AI, you can easily add this into player.cs in the Armor::damage function just after the line

if (%obj.getState() $= "Dead"){

%sourceClient.incScore(10); // where 10 is, of course, the number of points to add to players score

It should add score (and show up in the gui) whenever a player is killed.

I think that covers it ... if not, let me know :)

Enjoy!

#1
02/25/2007 (6:36 pm)
Hi,

I am a relatively new user. I am trying to create a game for kids. The purpose is to move variuos objects into a basket. I want it so that when they move a particular object inside, they get a score. Once all items are accounted for, I would like the server to send a victory command.



This is some how simlar to the game in the gettign started guide , except i dont want my objects to disappear, when touched.

Any help would be appreciated. Am stuck!!


Irura
#2
03/12/2007 (1:14 am)
HI
i tried to implement this tutorial for myself but it did not work
i am trying to use it for a game where there are many bots and the player kills them to earn points
i followed all the instructions in here to do so but it did not satisfy my needs since it does not give the required results

can you please help me in proper implementation of it and guide me in doing what i want to
thanking you
#3
11/21/2007 (12:12 pm)
hey how would I get the player score to always appear in the HUD? I'm a newbie at this stuff
I've got some AIGuard bots and what I'd like is to have it show the number of bots killed by the player in the corner of the screen all the time
#4
12/23/2007 (9:28 pm)
I get an error on the console, several, but the main ones are that it doesn't know what ScoreAmount is
I'm not a good coder yet and am not sure what I need to change it to or add, thanks
#5
12/23/2007 (11:05 pm)
ah in the playGui.gui gotta add a new GuiTextCtrl and then set its name to ScoreAmount...
also needed the code below to be in the right place, at the end of playGui.cs in client/scripts

function clientCmdClientScoreChanged(%Score){

ScoreAmount.setText(formatString(%score,9)); // Where 9 is the length of the score in chars

}
#6
12/23/2007 (11:23 pm)
Got it to work but only after I REALLY compared it THOROUGHLY with the ammo resource at http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1786
This score resource is leaving out a few important details and steps but if you compare the two you can get it, it took me a while though and a lot of messing around but dang it feels good to see it work! I've wanted this for quite some time.