Sometimes there's a need to sequence a number of actions, one after the other, for example in campaign scripts to unfold part of the plot.
In WZScript, there seems to be a pause() command, although I can't find it documented anywhere. Here's an excerpt from Goth's cam4 script:
showConsoleText(_("Sgt.Gibbs: Next objective is to the north. Then we'll cut eastward and rendevous with Team Two."), player); pause(50); showConsoleText(_("Sgt.Wilkes: -- Wilkes to Gibbs. You folks have got a horde of angry Scavengers headed your way from the north. --"), player); pause(50); showConsoleText(_("Sgt.Gibbs: Thanks for the heads up, Sergeant. We'll be ready!"), player);
If you did something like that in Javascript, the game would hang. So we're going to need to use queue(), but even then the code would be a mess because we'd need vast numbers of functions.
However, we can probably create a little API that will help us achieve our goals in a fairly clean manner. Using it would look something like this...
include("path/to/APIs/Sequence.js"); // define a sequence, probably store in in an external .js file and include() it Sequence.define("introSequence", processor, [ "Sgt.Gibbs: Next objective is to the north. Then we'll cut eastward and rendevous with Team Two.", 50, "Sgt.Wilkes: -- Wilkes to Gibbs. You folks have got a horde of angry Scavengers headed your way from the north. --", 50, "Sgt.Gibbs: Thanks for the heads up, Sergeant. We'll be ready!" ]); // start a sequence, eg. during an event function eventGameInit() { // various init Sequence(introSequence); // various other stuff }
The sequence above is simplified version of what Goth is doing in cam4 – the sequencer also needs to be able to handle function calls, because code is often running in between console messages (eg. to spawn droids, etc).
Sequence.define()
Defines a new sequence. Any number of sequences can be created, both during script initialisation or at any other time.
Sequence.define( name, processor, steps );
Parameters
Parameter | Type | Mandatory | Notes | API Version |
---|---|---|---|---|
name | String | A unique name for the sequence, for example "Intro Sequence" | ||
processor | Function | A function that will process steps in the sequence. See "Processor Function" for more info. | ||
steps | Array of Steps | An array containing the steps in the sequence. Also the name of a British pop band from the '90s. |
Anyway, that's the sort of thing Sequence API should handle. Currently working on a prototype...