Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Tasks are functions that Triggers process during a trigger Process Instances execute in sequence when they run. |
Creating a task
Create a function, then add it to a trigger like Process Instance like so:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
var myTaskFuncmyTask1 = function(params...taskData,processData,runData,processName,taskName,alert) { // task code here } function anotherTaskFuncmyTask2(...params...) { // task code here } // add two tasks to "myTriggerfoo" process instance: PulseProcesses("myTriggerfoo").addTask(myTaskFuncmyTask1).addTask(anotherTaskFuncmyTask2); // Note: See triggerinstance.addTask() for more info on the .addTask() params // You can also just add anonymous functions PulseProcesses("myTriggerfoo").addTask(function(...params...) { // task code here }); |
Note: Tasks are processed in the order in which they're added to the process instance.
There are several parameters to the triggerinstance.addTask() function that you should check out, such as defining the task name and setting a task scope and indicating that tasks should be player-iterated.
Task parameters
When the trigger processes process instance executes a task, it passes in a bunch of parameters as followsthe following parameters:
Parameter | Type | Notes | Pulse Version | player | Number||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
The player ID the task is to process, see Task Iteration for more info. | 0.1 | taskData | Object | A container where a task can store data to access next time it runsdata container associated with the current task, useful if you want to store data for subsequent executions of the task. Does not get saved when user saves a game. | 0.1 | |||||||||
triggerDataprocessData | Object | A trigger-level data container , allowing tasks within that trigger to share data between themselvesassociated with the process instance, useful if you want to share information between tasks. Does not get saved when user saves a game. | 0.1 | |||||||||||
runData | VariantAny | data that is passed in when a trigger run starts - see trigger() for more info A data container associated with the current process instance run. For example, it could contain information from the event that triggered the run. Tasks can also store information specific to the current run in this data container and then have instance.onEnd() event send the runData off to some other process or function. The runData object is deleted after each run, immediately after instance.onEnd() is fired. | 0.1 | |||||||||||
timeRemainingprocessName | NumberString | The number of millisecods remaining on this game tick before game lag will be noticed by end users. Not an exact figure, but usually fairly accurate.name of the process isntance that's executing the task. | 0.1 | |||||||||||
triggerNametaskName | String | The name of the trigger that's processing the tasktask (specified or determined during instance.addTask()) | 0.1 | |||||||||||
alert | Function | A function that lets you send a descriptive alert message, useful for debugging.
Parameters: | 0.1 |
Task return values
Tasks can optionally return 'true' to indicate they're not finished yet.
Value | Type | Notes | Pulse Version | ||
---|---|---|---|---|---|
undefined | Anything that equates to Boolean false | If that Undefined | If the task function does not return anything, | or returns something that equates to false, the task is deemed to be complete for this run and the trigger will move on to processing the next taskPROCESS_STATE_IDLE is assumed (see below). | 0.1 |
PROCESS_STATE_IDLE | Constant | Indicate that the task is complete. | 0.1 | ||
true | Boolean | If the task returns | Constant | Indicate that the task is incomplete. In this scenario, the trigger will stop processing any additional tasks on the current game tick, and on a subsequent game tick will resume processing tasks starting with the one that was incomplete.Your task can store where it was up to, etc., on the taskData object so that it can pick up where it left off next time it runsprocess run will be paused until a later game tick, at which time the task will be run again. See notes below for more info. | 0.1 |
PROCESS_STATE_ABORT | Constant | Indicate that the current process run should be aborted. | 0.1 | ||
<error> | Any exception | The trigger will abort Error | If the task causes an exception, the current process run will be aborted and a warning message displayed. | Planned for 0.21 |
Notes
When a trigger runs (see trigger()) it will run process instance runs it will execute each of its tasks in the order they were added to the trigger. If there isn't enough time left in the current game tick, some tasks may be deferred to a later game tick.
If game objects (anything derived from Base object Game objects) are stored in taskData, triggerData processData or runData, it's possible those objects have been destroyed before a task gets round to processing them so – so ensure you have good Error Handling around any code that processes game objects within a task.
Div | ||
---|---|---|
| ||
AvailabilityRequires:
|