hoot.lua (Handles-free Object Oriented Timer)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
farzher
Prole
Posts: 42
Joined: Fri Jul 31, 2015 5:38 pm

Re: hoot.lua (Handles-free Object Oriented Timer)

Post by farzher »

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.
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.

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

Tesselode wrote: And also there aren't any functions for pausing a timer or updating a timer individually.
That's true. I've never actually needed to do this, so I'm not sure the best way how to handle it.

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()
butts
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests