1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GML- adding a clock/game time

Discussion in 'Programming' started by Navaneeth, Dec 28, 2016.

  1. Navaneeth

    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!!
  2. Fabseven

    Fabseven Member

    Oct 7, 2016
    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
    If(Time % room_speed == 0)

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

    You could also calculate minute and seconde before drawning (to draw mm:SS)
    Navaneeth likes this.
  3. KurtBlissZ

    KurtBlissZ Member

    Jun 21, 2016
    Here's my sloppy explanation of doing a timer ;P.
    /// 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
    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.

    Navaneeth likes this.
  4. Never Mind

    Never Mind Member

    Oct 17, 2016
    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 );
    Papa Doge, Jamgeo and Navaneeth like this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice