August 04, 2017, 06:31:08 am

Imagine I have an event queue that triggers at some point, for example:

- Make player walk north a few tiles- Then make NPC walk south a few tiles- Then show a text box- Then wait a little- Then show another text box- Then make both player and NPC walk north at the same time (as if he was following the NPC)- End event when both reach their destination

To be honest, I'm not sure I've ever really known how to do this properly in a non-blocking way. You know, something that leverages the renderscript and updatescript in classic Sphere while not blocking anything else going on on the map. Now that miniSphere comes with its whole new and improved API, I'd like to know even more how to do this the proper way, but I'm not really even sure where to begin with this...

This is exactly what Scenario was designed for, and of course it's an official part of the Sphere now thanks to me.

The last standalone version of Scenario (3.8.1) actually included scenelets for moving persons around the map, but I removed them from the miniSphere version since the map engine is eventually going to be phased out. There's nothing stopping you from implementing them yourself, though. Anyway, how your example would look in Scenario is:

Note that the resync in the above example scene is actually redundant, since there's an implicit sync point at the end of a timeline (= the timeline won't end until all its forks have). I only put it there to illustrate its purpose.

Another question: can several of these run at the same time? For examples, for a few NPCs' moving paths in the background while the main event is happening in the foreground? And would that be as simple as constructing several Scenes and all running them non-blocking?

Another question: can several of these run at the same time? For examples, for a few NPCs' moving paths in the background while the main event is happening in the foreground? And would that be as simple as constructing several Scenes and all running them non-blocking?

Yep, it hooks into Thread, which in turn hooks into the Dispatch API so things get updated on every map update.

I actually use Scenario a lot for tweening menu animations and such. That wasn't what it was originally designed for, but fork and resync work great for coordinating fades, slide-ins, etc.