0 Favourites

Timer is affected by framerate?

This forum is currently in read-only mode.
• 3 posts
• I'm using "Timer%7=1" in a condition, to do something every X miliseconds (I can't use the actual "every x miliseconds" event since for some reason it stuffs up the picking).

However, on unlimited framerate the event is trigged a billion times faster? I thought the timer wouldn't be affected by framerate like how timedelta isn't?

• There were lots of threads and discussions about this. May search for them if you want to read more about it. It is the simple fact that nothing gets triggered faster than a frame. If a game runs with 60 fps, then the shortest timespan that can be distinguished is 1/60 (ca 16.67 ms)

So your event is triggered every 16.67ms and only if at that time the timer modulo divided by 7 is 1 the event will actually be executed:

frame 1 timer = 0 | timer%7 = 0

frame 2 timer = 16 | timer%7 = 2

frame 3 timer = 33 | timer%7 = 5

frame 4 timer = 50 | timer%7 = 1 <-first executed event

Of course, the hits will raise if in unlimited framerate, because with something like 1000 fps the shortest timespan is 1/1000 = 1 ms, and therefore timer%7 will match 1 much more often.

Just don't use timespans shorter than the framerate and use a range rather than a definite value (e.g. see it valid if timer%x is lower than 5 or something)