This AI is still in early stages of development.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 22 Current »

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:

var myTask1 = function(taskData,processData,runData,processName,taskName,alert) {
  // 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
});

(warning) 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:

ParameterTypeNotesPulse Version
taskDataObject

A data container associated with the current task, useful if you want to store data for subsequent executions of the task.

(info) Does not get saved when user saves a game.

0.1
processDataObject

A data container associated with the process instance, useful if you want to share information between tasks.

(info) Does not get saved when user saves a game.

0.1
runDataVariant

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
processNameStringThe name of the process isntance that's executing the task.0.1
taskNameStringThe name of the task (specified or determined during instance.addTask())0.1
alertFunction

A function that lets you send a descriptive alert message, useful for debugging.

Create alert messages from within a task
alert(msg, format);

Parameters:

  • msg – string containing the message to send
  • format – constant defining output format:
    • PROCESS_ALERT_CONSOLE – send msg to console() (default)
    • PROCESS_ALERT_DEBUG – send msg to debug()
    • PROCESS_ALERT_ERROR – throw an error message, also aborts the current run.
0.1

Task return values

Tasks can optionally return 'true' to indicate they're not finished yet.

ValueTypeNotesPulse Version
undefinedUndefinedIf the task function does not return anything, PROCESS_STATE_IDLE is assumed (see below).0.1

PROCESS_STATE_IDLE

Constant

Indicate that the task is complete.

0.1

PROCESS_STATE_RUNNING

Constant

Indicate that the task is incomplete.

In this scenario, the process 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_ABORTConstantIndicate that the current process run should be aborted.0.1
<error>Error

If the task causes an exception, the current process run will be aborted and a warning message displayed.

0.1

Notes

When a process instance runs it will execute 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 Game objects) 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.

Availability

Requires:

  • Warzone 3.1 or above
  • Process 0.2 or above

 

  • No labels