Tasks are functions that Triggers process during a trigger run.
Creating a task
Create a function, then add it to a trigger like so:
var myTaskFunc = function(params...) {
// task code here
}
function anotherTaskFunc(params...) {
// task code here
}
// add two tasks to "myTrigger":
Pulse("myTrigger").addTask(myTaskFunc).addTask(anotherTaskFunc);
// You can also just add anonymous functions
Pulse("myTrigger").addTask(function(params...) {
// task code here
});
There are several parameters to the trigger.addTask() function that you should check out, such as setting a task scope and indicating that tasks should be player-iterated.
Task parameters
When the trigger processes a task, it passes in a bunch of parameters as follows:
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 runs.
Does not get saved when user saves a game.
0.1
triggerData
Object
A trigger-level data container, allowing tasks within that trigger to share data between themselves.
Does not get saved when user saves a game.
0.1
runData
Variant
Any data that is passed in when a trigger run starts - see trigger() for more info.
0.1
timeRemaining
Number
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.
0.1
triggerName
String
The name of the trigger that's processing the task.
0.1
Task return values
Tasks can optionally return 'true' to indicate they're not finished yet.
Value
Type
Notes
Pulse Version
undefined
null
false
Anything that equates to Boolean false
If that 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 task.
0.1
true
Boolean
If the task returns true (or anything that equates to true), the trigger will deem the task to be incomplete, eg. due to time constraints.
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 runs.
0.1
<error>
Any exception
The trigger will abort the current run.
Planned for 0.2
Notes
When a trigger runs (see trigger()) it will run 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) are stored in taskData, triggerData or runData, it's possible those objects have been destroyed before a task gets round to processing them so ensure you have good Error Handling around any code that processes game objects within a task.
Availability
Requires:
Warzone 3.1 or above
Pulse 0.1 or above
Yeast 0.1 or above
Some changes to return values are planned for Pulse v0.2.