Pfap
Member
The below code is good to copy and paste into one object and when placed in a room will run. I'm hoping somebody could review my code and hopefully tell me where I'm going wrong or just being stupid and then point me in the right direction.
I'm trying to make a count down timer that rolls the minutes down when the seconds hit 0 and then rolls the hours down when the minutes hit 0.
Here is the create event:
This is the alarm[0] event:
Finally this is the draw event:
I'm having trouble figuring out how to manipulate the minutes.
I feel it needs to be something like minutes_remain = (draw_time/60)/24;
I'm trying to make a count down timer that rolls the minutes down when the seconds hit 0 and then rolls the hours down when the minutes hit 0.
Here is the create event:
Code:
var year = 2019;
var month = 5;
var day = 20;
var hour = 20;
var minute = 20;
var second = 20;
// start time
var start_time = date_create_datetime(year,month,day,hour,minute,second);
// current time
var new_time = date_create_datetime(year,month,day,hour,minute,second);
// how many seconds have passed with the above code this will obviously be 0
seconds = date_second_span(start_time,new_time);
// how many minutes have passed also 0
var minutes = date_minute_span(start_time,new_time);
// how many hours have passed also 0
var hours = date_hour_span(start_time, new_time);
// 86,400 seconds is 24 hours
var draw_time = 86400-seconds;
//convert to hours
var hours_remain = (draw_time/60)/60;
//there are 1440 minutes in 24 hours which is what this is returning
var minutes_remain = draw_time/60;
var secs = draw_time%60;
var draw_hr = floor(hours_remain);
var draw_min = floor(minutes_remain);
var draw_secs = floor(secs);
var seconds_string = string(draw_secs);
if string_length(seconds_string) != 2{
seconds_string = "0"+seconds_string;
}
time_left = string(draw_hr) + ":" + string(draw_min) + ":" + seconds_string;
//this is a 1 second alarm
alarm[0] = 60;
Code:
//add to the amount of time that has passed
seconds += 1;
//update the timer
var draw_time = 86400-seconds;
//convert to hours
var hours_remain = (draw_time/60)/60;
//convert to minutes
var minutes_remain = draw_time/60;
show_debug_message(minutes_remain);
var secs = draw_time%60;
var draw_hr = floor(hours_remain);
var draw_min = floor(minutes_remain);
var draw_secs = floor(secs);
var seconds_string = string(draw_secs);
if string_length(seconds_string) != 2{
seconds_string = "0"+seconds_string;
}
time_left = string(draw_hr) + ":" + string(draw_min) + ":" + seconds_string;
if seconds < 86400{
alarm[0] = 60;
}
else{
// otherwise 24 hours has passed
time_left = "00:00:00"
}
Code:
draw_set_valign(fa_top);
draw_set_halign(fa_left);
draw_set_color(c_black);
draw_text(x,y,time_left);
I'm having trouble figuring out how to manipulate the minutes.
I feel it needs to be something like minutes_remain = (draw_time/60)/24;