flowtask

The 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.

Note:
  1. The ruleflow syntax is described in Grammar specification.

  2. 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 void return 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 (break and continue)

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:

  1. Its initial actions are executed first.

  2. The body is executed.

    The body consists of a while loop. Each loop corresponds to a move from a player in the Connect4 game. If the move causes a Connect4 object to be accomplished or the grid to be full, the game is finished and the while loop can be interrupted by a break statement. Here the ruleflow resumes after the while loop. In this particular example, the EndOfGame task is executed.

  3. When the flow finishes execution, the final actions of the task are executed.