Event Scheduling

by Stephen001
A library to provide global and local game events management and scheduling.
Event management deals with the problem of having recurring "events" in a typical game. These might be day/night cycles, timed buff effects, auto-expiring traps etc.

Commonly in BYOND you would implement these by using spawn(), delaying appropriately. The issue this has is this places the procedure into the care of the BYOND scheduler, where it cannot be subsequently cancelled until it executes. Many spawn()ed procedures place an un-necessary burden on the BYOND scheduler, which has other duties to perform.

Having a separate event scheduler (or many) written in DM allows the programmer more flexibility on what gets executed, what can be cancelled, freezing all events that are scheduled and so on. This library provides a general mechanism to do just that.

Please bear in mind this library is new, and will develop a more rounded set of features as time progresses.

The library currently supports the following:
  • Scheduling events
  • Cancelling events
  • Starting and stopping schedulers, to "freeze" event firing
  • Events scheduled in multiple schedulers at once
  • Re-scheduling events
  • Event priority (the higher the priority, the more important the event)
  • Some common event types, such as Periodic Timers


This library depends on the following libraries, and requires that you download them first. An include.txt file is provided, so if you download via the BYOND pager, these are automatically included:

Your EventScheduler object starts with __running set to 1, which I do believe is not what you intended, since this would result in not being able to use EventScheduler.start() to actually start to looping process.

edit: was this fixed, actually? I had an older one. just downloaded the most recent version, and it seems to be fixed...
Also, maybe a built-in "reschedule" function could be added? Something that just calls cancel() and then schedule(), maybe?
Yup, that's on the cards for the next version, mostly as there is a little possibility for doing it more efficiently than cancel and schedule could do it. As a first go, I can definitely add that though.
Another request I have is for event priority.

I'm writing a little project that uses effects, and I wanted to use this event scheduler for scheduling effect fading. I also eventually had the idea to use it for "pulsing." Something like a poison effect, which deals damage every X ticks.

The only problem is, if we have an effect that has say, a duration of 40 ticks, and we want it to pulse 4 times (10 tick intervals), we end up with a problem on the very last tick. Because it is lower priority than the fade (because it was added last), the fade will be called before the pulser.

This means the 4th pulse will never fire.

The best means of fixing this I can think of is to add an event priority to the scheduler. Other than that, I can see checking for the pulser in the fader event, and if the pulser is scheduled for the same tick, pulsing, and then manually canceling it.
I can certainly add priority, I'll have to see what effect that has on scheduling (not much I would guess).
Great library, but it's too hard to find. I understand it's in your blog posts, but one can't be expected to go through every member's posts. Anyways, again, this is a great library. Here's to hoping you release more!
It is currently in the development main page:


And has a single tag, events. Do you have any ideas on ways I can improve the visibility at all? I'd love to be able to do so.
In response to Stephen001
You can add a 'data structure' tag. Since events are priority-based, you can essentially say it can serve as a priority queue, which is a data structure.
Mmm yeah, but you wouldn't use the library as that, particularly. It's implementation contains a priority queue, which isn't really the same as providing one to library users.
In response to Stephen001
You should also make a post on how to properly use this library and the benefits you get from it, with maybe a demo portraying everything you've talked about?
I suppose I could provide something of a testimonial's section also http://www.byond.com/members/ Valekor?command=view_post&post=110521&first_unread=1