ID:154319
 
Since I'm "philosophizing" about how to "design" this better...

I have a proc in my upcomming game that starts the timer variable ticking away at what is supposedly 10 tick incriments. The problem I've seen is that, while running the game and watching the timer, it seems to stall every few seconds for just a little longer than it should.

So, I was curious to ask what other "more efficient" ways are there to get the timing right on here?

proc/Timer()
for()
sleep(10)
if(timer >= 0) timer++
Echelon wrote:
Since I'm "philosophizing" about how to "design" this better...

I have a proc in my upcomming game that starts the timer variable ticking away at what is supposedly 10 tick incriments. The problem I've seen is that, while running the game and watching the timer, it seems to stall every few seconds for just a little longer than it should.

So, I was curious to ask what other "more efficient" ways are there to get the timing right on here?

proc/Timer()
for()
sleep(10)
if(timer >= 0) timer++

You can't guarantee when a sleep() or spawn() will occur...various factors may cause them to happen at slightly random times.

This is why I'm a broken record on recommending always using an event loop instead, so you have exact control over the order of operations in your game.

byond://Deadron.SimpleLoop
As Deadron points out, sleep() and spawn() aren't accurate measures of time. If you want accurate time, you should investigate world.realtime, world.time, and time2text() in the Reference.
In response to Shadowdarke
Shadowdarke wrote:
As Deadron points out, sleep() and spawn() aren't accurate measures of time. If you want accurate time, you should investigate world.realtime, world.time, and time2text() in the Reference.

Alas, realtime isn't accurate at the tick level either.
In response to Deadron
Deadron wrote:
Shadowdarke wrote:
As Deadron points out, sleep() and spawn() aren't accurate measures of time. If you want accurate time, you should investigate world.realtime, world.time, and time2text() in the Reference.

Alas, realtime isn't accurate at the tick level either.

Alas, it isn't accurate at pretty much any level. The constraints of floating point make it pretty much useless for any serious application, because it rounds to 6.4 seconds.

In fact this has been a pain with my map algorithm in Incursion, because I try to measure the time it takes to build the map, but that measurement has to be in ticks (which are deplorably inaccurate for computationally expensive algorithms) using world.time, or in 6.4-second increments using world.realtime.

Lummox JR