Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Tasks are functions that Process Instances execute in sequence when they run. |
Creating a task
Create a function, then add it to a Process Instance like so:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
var myTask1 = function(taskData,processData,runData,timeRemaining,triggerName,taskName) { // task code here } function myTask2(...params...) { // task code here } // add two tasks to "foo" process instance: Processes("foo").addTask(myTask1).addTask(myTask2); // Note: See instance.addTask() for more info on the .addTask() params // You can also just add anonymous functions Processes("foo").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 instance.addTask() function that you should check out, such as defining the task name and setting a task scope.
Task parameters
When the process instance executes a task, it passes in the following parameters:
Parameter | Type | Notes | Pulse Version |
---|---|---|---|
taskData | Object | A data 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 |
processData | Object | A data container associated 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 | Variant | 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 |
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. Your task can use this to limit it's running time. If your task runs out of time, it can store where it's up to on the taskData object and return | 0.1 |
triggerName | String | The name of the process isntance that's executing the task. | 0.1 |
taskName | String | The name of the task (specified or determined during instance.addTask()) | 0.1 |
Task return values
Tasks can optionally return 'true' to indicate they're not finished yet.
Value | Type | Notes | Pulse Version |
---|---|---|---|
| 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 process instance will move on to the next task. | 0.1 |
true | Boolean | If the task returns In this scenario, the process instance will wait until a subsequent game tick and then execute the incomplete task again. Your task can store where it was up to, etc., on the taskData or runData object so that it can pick up where it left off next time it runs. Just remember to clear down that info after the task completes. | 0.1 |
PROCESS_STATE_ABORT | Constant | If the task returns this constant, the current process run will be aborted. | 0.1 |
<error> | Any exception | The trigger will abort the current run. | Planned for 0.2 |
Notes
When a process instance runs it will run each of its tasks in the order they were added. 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, processData 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.
Div | ||
---|---|---|
| ||
AvailabilityRequires:
Some changes to return values are planned for Pulse Process v0.2. |