Game Development Community

1s and 10s

by rennie moffat · in Torque Game Builder · 12/13/2010 (7:47 pm) · 8 replies

Hi there,
I have a simple question, but due to my newbish am asking your pros how to best do it. I am running a visible count, to count the number of strokes the user makes. Like golf, this count wil start at 0 and end when ever the player finishes. So it could go up to infiniti, but 99 will do. They way I am visually showing this via a HUD is to simply have a staticSprite with 10 frames. Frame 0 = 0 (shows the number 0), frame 1 = 1 and so on.

I have done this before but the difference here is that, in order to save time, I want to simply use 2 objects one to count the 1's, the other the 10's. What I have developed so far is this... but as you can see is time consuming. How through code, can I get the same results, minus the lines of code required in my method?

Thanks.
$s1L1BT = $s1L1BT + 1;
		%this.1s.setFrame($s1L1BT);
///once I hit 10, the two objects 1s and 10s must be adjusted
		if($s1L1BT == 10)
		{
			%this.1s.setFrame(0);
			%this.10s.setFrame(1);
			return;
		}
		else if($s1L1BT == 20)
		{
			%this.1s.setFrame(0);
			%this.10s.setFrame(2);
			return;
		}	
		else if($s1L1BT == 30)
		{
			%this.1s.setFrame(0);
			%this.10s.setFrame(3);
			return;
		}
///this pattern of course will continue on to 20, 30 and so on

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
12/13/2010 (8:16 pm)
something like

%this.1s.setFrame($s1L1BT % 10);
%this.10s.setFrame(mFloor($s1L1BT / 10));

should do the trick
#2
12/13/2010 (8:33 pm)
right. what is the "%" is the first line

($s1L1BT % 10);




:?
#3
12/13/2010 (10:07 pm)
% is modulus, which basically means "what is the remainder of x / y". So, 12 % 10 would equal 2.
#4
12/13/2010 (10:11 pm)
That is the modulus operator. Simply put, it gets the remainder from a divide operation:
12 / 10 = 1.2
12 % 10 = 2
22 % 10 = 2
32 % 10 = 2
36 % 10 = 6
40 % 10 = 0
Since everything in TorqueScript is a string, you could always get the character from the value:
%tens = getSubStr( $s1L1BT, 0, 1 );
%ones = getSubStr( $s1L1BT, 1, 1 );
#5
12/13/2010 (10:32 pm)
Oh great guys, the modulus. Nice.

and "getSubStr", the example gven in source is...
// Prints 2345
echo( getSubStr( "0123456789" , 2 , 4 ) );

how does this print 2345?



I see it as printing 1, 3.

:s
#6
12/13/2010 (10:57 pm)
remember that with torque script, it follows the logic of C++, so index values start at 0, not 1.

basically the above code says go to index 2 (3rd character) and get 4 characters following it.
#7
12/13/2010 (11:12 pm)
oh, ok, I was thinking, get character 2, and character 4. Thanks very much.


::)(
#8
12/16/2010 (4:49 pm)
Hi there,
this is kind of a continuation of this thread. The number I am calculating here, is a few game score/factors, put thru an equation i devised and voila, the final score. However, I multiply this number (still with in the formula) by a 1000, to get a number that is in the 1000s. Other wise the number I get instead of 5000 for example would be 5. Not what I am interested in. of course on the flip side, and why I am posting is that I could get a score of 5383, but if I do not multiply by a 1000 I still get 5.


Is there a way I can make sure my score value return has X amount of decimal points? So instead of a return of 5. I get a return of 5.383?



Edit,
on second thought this may be totally pointless.

Cheers!

:))((