• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

In search of the passing time...

luxo-JR

Member
Hello. I am on a project in which I would like to implement a notion of 'day' and 'night', with a sort of clock running. I have already thought about it a bit, but nothing has come. There is indeed the notion of 'interrupt' management. I looked in the documentation of GMS, the notion of timeline without more. Thank you
 

chamaeleon

Member
Use current_time for time elapsed since game start, and date_current_datetime() for real world time information. Use the available data to compute whatever you need.
 
Make your own. Going to be much less pain if you want to stop the timer, and stuff like that.
Doesn't have to be complicated, you can just use the alarms

GML:
#macro SECOND  60

function init_time(_h, _m, _s) constructor {
    seconds = _s;
    minutes = _m;
    hours = _h;
}

global.time = new init_time(0, 0, 0);

alarm[0] = SECOND;
GML:
//ALARM 0

//Update seconds
global.time[$"seconds"]++;

//Check if we're at the end of a minute or hour
if(global.time[$"seconds"] >= 60){
    global.time[$"seconds"] = 0;
    global.time[$"minutes"]++;
    
    if(global.time[$"minutes"] >= 60){
        global.time[$"minutes"] = 0;
        global.time[$"hours"]++;
    }
}

//Set this alarm to 1 second
alarm[0] = SECOND;
 

chamaeleon

Member
GML:
#macro SCALE_FACTOR 1
start_time = current_time;
global.time = { hours: 0, minutes: 0, seconds: 0 };
...
var elapsed = (current_time - start_time)/1000 * SCALE_FACTOR;
global.time.hours = elapsed div 3600;
global.time.minutes = (elapsed mod 3600) div 60;
global.time.seconds = elapsed mod 60;
 
I wouldn't do that, this is even kind of, dare I say, very unthought of, for a day-night system.
Time spent in the menus will count. You use the step event for something that can be calculated each 60 steps. No way to pause the timer once it starts going. Won't be able to save properly...
I could go on, if you're not convinced...
 

chamaeleon

Member
Of course you can (reset the start time when exiting a menu). The implication of stopping time is that you are now measuring spans of time, not a contiguous segment, which implies using an accumulator variable, obviously. But even so, no need for your nested if statements. Just use the same math I used but for your counter.
 
No, current_time is READ-ONLY, and you use it all over your stuff. You can't "pause" nor "reset" that. And why do you multiply by a macro equals to 1?!?
Aaaaanyway... whoever reads this has been warned, I consider my civic duty done here.
 

chamaeleon

Member
No, current_time is READ-ONLY, and you use it all over your stuff. You can't "pause" nor "reset" that. And why do you multiply by a macro equals to 1?!?
Aaaaanyway... whoever reads this has been warned, I consider my civic duty done here.
I realize current_time is read only. current_time is not my accumulator I mentioned. My accumulator is more akin to your seconds variable. current_time is used to get the a value that keeps increasing without having to manage it by incrementing it myself.
I'm not pausing or resetting current_time. I am pausing the use of time and when resuming the use of time record the start that at that point, letting me use the different between that recorded time and "now" value of current_time in conjunction with my accumulator.
I multiply by a macro of 1 to simulate real time, substitute with a different value for time elapsing faster or slower than real time (or use a variable if it shouldn't be fixed). Hence the name scale factor.
I have not bothered elaborating code due to lack of requirements from the opening post.
 

luxo-JR

Member
First of all, I see that this post caused a reaction ... I have read (even if I am French) your answers and I think that my question concerns the installation of a timer which follows the time which passes since the launching of the program, it comes into play when that a set time expires, 'day falls' and 'day is on' at predefined times. For now, it's just the day / night simulation that has an impact on the graphic atmosphere. A counter in the background and a track of the passing time for control. Jean-Francois
 
Top