GML- adding a clock/game time

N

Navaneeth

Guest
Hey guys!!! I'm a bit new to GML so forgive me for any mistakes.....Alright, has anyone played the game escapists...They have this in- game clock which I hope to recreate for a game that I'm working on...How do I go about doing this??? Should I just run a long for loop of some sort of or is there an easier way?????Thank you for all your replies.bye!!
 

Fabseven

Member
Didnot play this game but you could create and obj obj_time with
- à variable Time on thé create event
And à realtime variable
- in step évent
Time++
If(Time % room_speed == 0)
{
Realtime++
}

In draw gui évent
Draw_text(10,10, string(realtime))

You could also calculate minute and seconde before drawning (to draw mm:SS)
 

KurtBlissZ

Member
Here's my sloppy explanation of doing a timer ;P.
Code:
/// string_countdown(steps)
var steps = argument0;
var mins = 0;
var secs = 0;

//Get secs
while steps > 60 {secs+=1; steps-=60;}

//Get mins
while secs > 60 {mins+=1; secs-=60;}

if secs<10 secs='0'+string(secs);

//Return string
return(string(mins)+':'+string(secs));
Though it will work at a clock to if you want to change it just add or decrease a timer variable by
timer += (room_speed / 60); (I use timer-=1*_delta for my game since I'm using delta timing :p) if that dont work then it may be (60 / room_speed) ;p. Then just use the timer variable like this.

draw_text(0,0,string_countdown(timer));
 
N

Never Mind

Guest
I like the code that's been posted I just wanted to share another approach

Step Event:
-------------------------------------------------------------------------------
seconds += (delta_time*0.000001)*room_speed;
if seconds >= 60
{
seconds -= 60;
minutes += 1;
}
if minutes>= 60
{
minutes= -=60;
hours+= 1;
}
-------------------------------------------------------------------------------
Draw Event:
-------------------------------------------------------------------------------
draw_text( 100, 100, hours + ":" + minutes + ":" + seconds );
-------------------------------------------------------------------------------
 
Top