Windows How do I make a countdown timer?

B

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
 
S

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
 
B

BenjiPlaysYT

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
Ok thank you :)
 

Roderick

Member
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
}
 
B

BenjiPlaysYT

Guest
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
}
Thank you :p
 

Roderick

Member
Timer = room_speed * 30;

That will last 30secs
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.
 

Soso

Member
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.
Lol Oh i didn't realize you set the time in the step event i use the create event
 
S

SOliD

Guest
I want to show a message for a specific amount of time and idk how pls help...
 
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
 
M

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);
 
here you go

GML:
//Create event

room_speed = 30
timer = room_speed *5

//Step event

timer -= 1

if (timer == 0)
{
    room_goto_next()
}
 
I want to make it so that when I play my game, a video pops up and after the video ends it sends you to the next room.
Another way to do it is to set a timer when the game starts so that after 2.3 seconds (duration of the video), close the video and go to next room.
This is my code:

room_speed = 30
timer = room_speed *5

//Step event

timer -= 180

if (timer == 0)
{
video_close()(); // Stop the video playback
room_goto(rm_menu);
}

However, the video doesnt close after the timer.
 
Top