Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: va!n on November 27, 2007
-
i want to display a timer in a game which may look like this:
00:00:00 the 1st 00 block are the minutes, the 2nd 00 block are the seconds and the last are the mseconds.
Now the way i thought how to calculate and draw this timing with formating the string is following but i am not sure if there is a better (optimized and faster) way.
if dig1 = 10 : dig1 = 0 : dig2 + 1 : endif
if dig2 = 6 : dig2 = 0 : dig3 + 1 : endif
if dig3 = 10 : dig3 = 0 : dig4 + 1 : endif
if dig4 = 6 : dig4= 0 : dig5 + 1 : endif
if dig5 = 10 : dig5= 0 : dig6 + 1 : endif
if dig6 = 6 : game_completed=true : endif
dig1 + 1
DrawString( Str(dig6) + Str(dig5) + ":" + Str(dig4) + Str(dig3) + ":" + Str(dig2) + Str(dig1) )
hope the source is correct, because i typed here while sitting not in front of my pc :P
I still thought if there is another (better and possible faster way) using pointers but i am not really sure atm...
-
In C, you can do
sprintf(timestring, "%02d:%02d:%02d", hours, minutes, seconds);
In BASIC, try looking up the docs for
Print Using
Jim
-
thx. when seeing the c codesnip i like C/CPP ;)