Consider the fact that os.time is not the same as what love.timer.getTime returns; the equivalent would be os.clock... and even then, löve's implementation has more precision. (and is recommended to be used)soulmata wrote: ↑Sat Feb 11, 2023 7:47 am You can use modulo like this if you are getting os.time() instead of dt, because os.time() (at least on windows and linux) returns an INT. You can also, alternatively, floor the return of love.timer.getTime(), which I think would be more compatible with other platforms where what os.time() returns may not be consistent. I use it all over the place for simple animations (things that pulse on a frequency of 0.5 or 0.33hz, for instance). For anything that needs a frequency outside of that, use a timer instead.
You don't need the function to be aware of dt in this case as it can be using only local vars, but I tend to have a ton of timers that are all global anyway all over the place.
Instead of doing hackish stuff, just implement a fixed timestep if that's what you need for your game; your heartbeat example was one of those, kinda.
Actual implementations with counters were posted earlier in the thread.