AngelScript will use a messaging system, and ZScript may switch to using one as well, depending on if it seems like the effort is worth it (i.e., if it looks like AngelScript will take a while to get up and running).

This thread is to discuss how scripts will work in the messaging system, and to hash out the details of this system.

First, a quick overview. Instead of scripts with run() methods, in the future scripts will have a collection of message handlers/callbacks. Here is an initial, very minimal set of proposed messages that more or less replicate current ZScript functionality. Ultimately, many more message types could be supported (feel free to suggest):

Every script type
OnCreate -- called when the object to which the FFC is associated is first created (at the beginning of the game for global scripts; when Link enters the screen for screen and ffc scripts, etc)
OnDestroy -- called when the object to which the FFC is associated is destroyed (when Link leaves the screen for screen and ffc scripts, etc)
EveryFrame -- called at the beginning of each frame (immediately preceding when current scripts that called WaitFrame() execute)
OnDraw -- called at the end of each frame (immediately preceding when current scripts that called WaitDraw() execute)

Item scripts
OnPickedUp -- called when an instance of the item is picked up
OnUsed -- called when the item is used from the inventory

...

Once a callback starts to run, its execution context exists independently of the execution of any other of the script's callbacks. Waitframe() suspends execution until the start of the next frame, WaitDraw() until the end of the current frame, etc. So, for example, if a candle script has an OnUsed callback that creates fire and animates it for several iterations, if Link uses the candle item a second time, a second and completely independent instance of the OnUsed callback starts to run (and can spawn and control its own fire weapon, etc.)

It seems like every script should have control over what messages it is listening for, and which ones it is ignoring (so for instance, a blue candle script could disable OnUsed until Link leaves the screen after the first time it is used, etc.)

Instead of using Misc[] for storing local state, each script will have its own set of local variables, declared within the script, and shared by all instances of all running callbacks of that script.

Old Script Compatibility

If messages are implemented into ZScript, ensuring compatibility of old scripts seems straightforward. Each old global and ffc script (script that includes a Run() method and no callbacks) gets a default OnCreate callback that calls Run(), and a default OnDestroy callback that calls Quit(). Each old item pickup script gets an OnPickedUp that calls Run(), and item use scripts gets OnUsed() callbacks that call Run().