flowtask
flowtask keyword declares a subflow
task.
Purpose
This keyword is used to declare a flow task.
Context
At the top level of rulesets
Syntax
flowtask flowTaskName
{
[property propertyName = value;]
[initialaction {action1 ... actionm}]
[finalaction {action1 ... actionn}]
[completionflag = value;]
body {ruleflow}
};
Description
A flow task is one of the three kinds of tasks available in a ruleflow. A flow task describes how task executions are chained together and under which conditions.
The ruleflow syntax is described in Grammar specification.
If a formal comment (
/**...*/) precedes the task definition, it is saved so that you can retrieve it later using the API.
A subflow task can have the following attributes:
- property
Use this attribute to define a user property on the task. The engine does not interpret this property. You can retrieve its value later using the API.
- initialaction, finalaction
A subflow task can have an initial or a final action, or both. Initial actions are executed before the task body. Final actions are executed after the task body. They consist of inline IRL code, such as IRL functions. They are similar to an IRL function with the
voidreturn type and no arguments.- body
The flow task body defines a ruleflow. It consists of task calls that are chained together through control statements. The control statements are:
fork,goto,if,sequence,switch,while(breakandcontinue)
Example
This example illustrates a flow task definition.
flowtask main
{
initialaction =
{
turn = Constants.Player2;
saved = new SavedGame(grid);
for (var i = 0; i < 7; i++) for (var j = 0; j < 6; j++)
insert(grid.array[i][j]);
};
finalaction =
{
grid = null;
move = null;
winner = Constants.None;
connect4 = null;
ending = false;
message = null;
};
body =
{
while(!ending)
{
if (turn == Constants.Player1) ChooseMovePlayer1;
else ChooseMovePlayer2;
CheckMove;
if (ending) break;
UpdateDistance;
ExpandObjects;
DetectConnect4;
if (ending) break;
DetectGridFull;
if (ending) break;
ChangeTurn;
}
EndOfGame;
}
};This task is executed in this order:
Its initial actions are executed first.
The body is executed.
The body consists of a
whileloop. Each loop corresponds to a move from a player in theConnect4game. If the move causes aConnect4object to be accomplished or the grid to be full, the game is finished and thewhileloop can be interrupted by abreakstatement. Here the ruleflow resumes after thewhileloop. In this particular example, theEndOfGametask is executed.When the flow finishes execution, the final actions of the task are executed.