Legacy GM Creating a level based timer system that saves best time

H

HenrikoNumberOne

Guest
Hello everyone! I am currently making my own level based 2D puzzle platforming game, and it's shaping up really well. Right now I'm trying to get a "level based timer system" to work, however I'm having some trouble understanding how I would do that. Let me explain how I need it to work;

"There is a HUD on the right side that tells you the level name, the current time you've got and the best time ever recorded on that specific level." - That's basically what I need. Here is a picture of what I've got:



I already got the name thing working, however I don't really understand how I'm supposed to make a timer that counts in seconds + milliseconds for every level, and which then set that time to a specific global.variable for that level which can then be saved using the save system I already have without having to do an insane amount of code and variable creation for every single level.

Any help would be much appreciated.

- Henriko
 
H

HenrikoNumberOne

Guest
Count the number of steps the level took and then multiply that by room speed and you have the time in seconds
Oh, well that's really handy. Although I still have no idea how to make the timer save the player's time on that level after they have completed it...
 

JackTurbo

Member
If you wanted to use global variable like you suggested then it would simply be a case of having one for each level and then when each level is finished comparing the time taken to the relevant global variable and overwriting it if it is less.
 

amusudan

Lousiest of Potatoes
Count the number of steps the level took and then multiply that by room speed and you have the time in seconds
Divide, not multiply.

if the room_speed is 30; 30 steps would equal 1 second.

so
time = step / room_speed;

the better way of handlign this is with delta_time (which messures the time in miliseconds since the last step).
just do
time += delta_time;
while you need to count the time.

then for seconds you will want to divide time by 1000000, because it's in miliseconds, and cut off the remainder.
time_seconds = time div 1000000;
time_miliseconds = time;
 

JackTurbo

Member
Divide, not multiply.

snip
Good catch! You're right divide not multiply.

As for delta time, I'd personally caution against it if the game's logic isnt also tied to delta-time.

Not that I am championing either frame-locked or delta-time approaches as a whole, frankly that is an argument I never really want to get involved in.

Rather I'd just suggest that the timer methodology should match which ever approach the game play logic is tied to, as that will ensure a truer reflection of the player's performance.
 
H

HenrikoNumberOne

Guest
If you wanted to use global variable like you suggested then it would simply be a case of having one for each level and then when each level is finished comparing the time taken to the relevant global variable and overwriting it if it is less.
Oh, so mean that I should create a separate object for each level that keeps track of the timing? Isn't there a neater / less messy way to do it?
 

JackTurbo

Member
Oh, so mean that I should create a separate object for each level that keeps track of the timing? Isn't there a neater / less messy way to do it?
No, you could do it in a single control object. I meant a variable for each level. There's a bunch of ways you could code this, which is best might depend on the number of levels in your game. My first thought is to use a switch statement based around room name, but there might be more efficient ways.

Although if you wanted to be neater still it'd be better to use a single array or ds_list to hold all the high scores instead of loads of globals.
 
Last edited:
H

HenrikoNumberOne

Guest
No, you could do it in a single control object. I meant a variable for each level. There's a bunch of ways you could code this, which is best might depend on the number of levels in your game. My first thought is to use a switch statement based around room name, but there might be more efficient ways.

Although if you wanted to be neater still it'd be better to use a single array or ds_list to hold all the high scores instead of loads of globals.
Oh, that sounds interesting. I'm still quite new to working only with code in Game Maker Studio, so I am not really too sure on how to use an array or a ds_list. Do you have any examples on how to set up something basic with that?
 
Top