• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker (SOLVED)time clock showing "00" instead of "0"

A

Adjud

Guest
Hi,

I made a clock code for my game, everything functions beautifully except for the numbers displayed, i want it to display 12:00:00 instead its displaying "12:0:0".

here is the code:
obj controller Draw Event:
Code:
draw_text(700,40, string(chour) + ":" + string(cmin) + ":" + string(csec) + " " + mn);
objcontroller Create event (temporary place for it):

Code:
mn="AM"
clockset=0;
chour=12;
cmin=00;
csec=00;
day=1;
 

FrostyCat

Redemption Seeker
You have to actually pad those numbers with a script like this when you draw them. Declaring them as 00 or anything of the sort won't magically make string() pad them.

Import the script that I linked to, then do this:
Code:
draw_text(700, 40, string_lpad(chour, 2, "0") + ":" + string_lpad(cmin, 2, "0") + ":" + string_lpad(csec, 2, "0") + " " + mn);
 
A

Adjud

Guest
I created the script "string_lpad" i pasted the code from the link you gave and put the code you supplied up above in my draw event but its giving me this error:
upload_2020-1-17_14-9-46.png
 
R

robproctor83

Guest
your in gsm 2? you need to update that pad function

out += str;

should be

out += string(str);

I think...
 

FrostyCat

Redemption Seeker
Replace this line in string_lpad():
Code:
str = argument0;
With this:
Code:
str = string(argument0);
 

Nidoking

Member
You can also just use string_format(cmin, 2, 0) to make it a 2-character wide string, padding with 0 if necessary. No script needed.
 
Top