Windows How do I make a countdown timer?

Discussion in 'Programming' started by BenjiPlaysYT, Nov 10, 2016.

  1. BenjiPlaysYT

    BenjiPlaysYT Guest

    Hi GMC,
    I would like to know how to make a timer that lasts 30 seconds and when them 30 seconds are up it will run a command but I don't want to use the alarms because I need more than 12 alarms for my game. I also want to know how to draw the countdown timer.

    Thank you
     
  2. stephen2017

    stephen2017 Guest

    Alarms are instance based so if you have 12 alarms for your game those alarms are for that game. If you create another object with no sprite and call it timer. It can have seperate alarms. then just add that to your room
     
    BenjiPlaysYT likes this.
  3. BenjiPlaysYT

    BenjiPlaysYT Guest

    Ok thank you :)
     
  4. Roderick

    Roderick Member

    Joined:
    Jun 22, 2016
    Posts:
    580
    You can also easily mimic an alarm in your Step code:

    Code:
    if (start_timer == true) {timer = room_speed * 30;}
    
    if (timer > 0) {timer--;}
    
    if (timer == 0)
    {
     do alarm stuff
     timer = -1; // This is important, or the timer will trigger every step once it runs out
    }
    
     
    BenjiPlaysYT likes this.
  5. BenjiPlaysYT

    BenjiPlaysYT Guest

    Thank you :p
     
  6. Soso

    Soso Member

    Joined:
    Oct 8, 2016
    Posts:
    75
    Timer = room_speed * 30;

    That will last 30secs
     
  7. Roderick

    Roderick Member

    Joined:
    Jun 22, 2016
    Posts:
    580
    That's just going to create a variable that tells you how many steps are in 30 seconds. You still need to implement code that makes it count down, as I explained above.
     
  8. Soso

    Soso Member

    Joined:
    Oct 8, 2016
    Posts:
    75
    Lol Oh i didn't realize you set the time in the step event i use the create event
     
  9. SOliD

    SOliD Member

    Joined:
    Nov 13, 2016
    Posts:
    5
    I want to show a message for a specific amount of time and idk how pls help...
     
  10. JML

    JML Wabbajackalope

    Joined:
    Jun 22, 2016
    Posts:
    349
    ok solid here is some code that will show a message, i didnt know how you wanted that message to appear so i both have its alpha change to make it fade and using the image scale to grow it, this basically will cover all the bases and you can change things as needed.

    also it will appear in the exact middle of the screen and you need to have a font object in the folder so take all of this into consideration

    Code:
    
    //create event
    xa = 0
    ya = 0
    aa = 0
    grow = 0
    shrink = 0
    
    //draw event
    
    if grow = 0 and shrink = 0
    {
    xa += .05
    ya += .05
    aa += .05
    
    if xa >= 1
    {
    grow = 1
    xa = 1
    ya = 1
    aa = 1
    }}
    
    if grow = 1 and shrink = 0
    {
    ti += 1
    if ti >= 60*30 //change this to the room speed times the amount of time, in a 60 fps room this would be 30 seconds
    {
    shrink = 1
    }}
    
    if shrink = 1 and grow = 1
    {
    xa -= .05
    ya -= .05
    aa -= .05
    
    if xa <= 0
    {
    grow = 0
    xa = 0
    ya = 0
    aa = 0
    }}
    
    if shrink = 1 and grow = 0
    {
    // do what ever you want to here for now though
    instance_destroy()
    }
    
    draw_set_font(font);
    draw_set_halign(fa_center);
    draw_set_valign(fa_center);
    
    draw_text_colour(room_width/2, room_height/2, "Hello World!", xa,ya,0,c_black,c_black,c_black,c_black, aa);
    
    

    good luck everyone
     
  11. Maximus

    Maximus Guest

    for converting steps to minutes and seconds:
    Code:
    minutes = floor(steps/room_speed/60);
    seconds = (steps/room_speed) mod 60;
    time_string = string(minutes) + ":" + string(seconds);
    
     
    Finn likes 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