clock/timer?

A

AngelThana

Guest
hello, i looked everywhere for something similar to what i am looking for, but all i found was a timer that goes by real time.
in the game im making, you have 10 days to do what has to be done, and each day is 5 minutes real time. i did the math for timing but i dont know how to code it in.
each game hour is 12.5 seconds, each game minute is 0.208333 seconds, and each second is 0.00347222 seconds.
im using game maker 8.1 because thats what we have at school.
any and all help is greatly appreciated

Carl Nylander

Member
I'd use hour then since it's the value with the least decimals. you need to count to "room_speed * 12.5" to go one hour so you can do that like this:

CREATE EVENT
Code:
``````time_count = 0
hour_value = room_speed * 12.5
hours = 0
days = 0``````
STEP EVENT
Code:
``````time_count += 1
if time_count >= hour_value {
time_count = 0
hours++
if hours > 23 {
hours = 0
days++
}
}``````

A

AngelThana

Guest
thank you, i had to tweak it a tiny bit for it to work (changed the "++" to "+= 1")
but i tested it and now it works

MarceloP

Member
If you want, you can also use Delta_Time. Which then you can even run while the screen is off, and the game is not in focus on Windows etc...
Delta time is a cool way of doing it...

I've built a clock to do things like that:

obj_clock:
Create:
Code:
``````/// @description Creates Clock
_timer_value = 0;
interval = 1; //One Second in real life, but if you want fractions you can do too, set it to 0.5 means half a second
counting = true;``````
Step:
Code:
``````/// @description Counting Step
if(counting){
var passed = 0;

_timer_value += delta_time;

passed = _timer_value/1000000;

if(passed >= interval){
passed = floor(passed/interval);
_timer_value = _timer_value%(1000000*interval);

while(passed > 0){
//EXECUTE HERE WHAT YOU WANT TO HAPPEN EVERY "interval" for every object you need
passed -= interval;
}
}
}``````
I also made a version of this with a broadcast list, but it would only complicate my sample for you xD
You can change it and broadcast this for all objects that need to have something called after a certain interval, and also you can sync them with time.
Anyway, DeltaTime is perfect for doing this, since you can be SURE that that's exactly the time that has passed, even though your game slow down at any given time, it will work perfectly.
Note: My sample does treat the time being bigger than expected. So if you minimize the game and come back after 22 days of your game time, the line "EXECUTE HERE..." will be called twice, and the remaning 2 days will keep counting from the second day.

Hope I've helped.

MarceloP

Member
I'm sorry as well, I thought that delta_time was also part of 8.1. I guess my solution may not work for you =(
But I'll leave the answer in the case of someone else trying to achieve the same thing on 1.4+