Re: hoot.lua (Handles-free Object Oriented Timer)
Posted: Mon Aug 17, 2015 6:35 am
That's a good point. I have thought of this, and already implemented a fix that I'm using in my games. But I don't want to push it yet because it's a bit more complicated and I'm not sure it's the best solution.Tesselode wrote: I don't have specific code, but hoot wouldn't really work if you need to change the speed of or pause groups of timers. For example, I wouldn't be able to slow down or pause all of the timers in, say, the gameplay state, because the only way to group timers with hoot is by object.
All I did is simply give hoot.update a second optional argument which is your gamestate. None of the other code changes, hoot(self):set('whatever', 1) automatically gets tied to the current gamestate (still no handles! you don't need to make new hoot objects for each state)
So if you switch to a pause state, you can call hoot.update on your pause state and it won't affect gamestate timers.
And even if you had an overlay state that wanted to call gamestate's update in the background, that would still work as expected because gamestate.update would call hoot.update with the gamestate, changing its context
That's true. I've never actually needed to do this, so I'm not sure the best way how to handle it.Tesselode wrote: And also there aren't any functions for pausing a timer or updating a timer individually.
Technically hoot(self):get('whatever').delay += 1 works to add 1 second if you want to mess with the timer (I wish += existed in lua)
And I guess I could add hoot(self):get('whatever').pause/unpause()