Destination orientation, asynchronous or synchronous

This control structure adds a target orientation to the Script language, starts a procedure that runs asynchronously.

It works with global variables or objects. The syntax is as follows:

to ...condition... for durée [, délai ]
  ...processus...
/to

The compiler also recognizes single-line syntax:

to ...condition... for ...durée [, délai]. do ...action... 

Condition

A condition is a relational expression that defines the goal to be achieved. Exempli gratia:

a >= 100

The action is repeated until the value of the global variable is 100.

Term

Duration is the time limit, expressed as the actual number of seconds during which processing is performed. It can be an integer or an actual number, but it is always alphabetic.
If you don't want limited time, you write the symbol & to represent infinity.

Term

This parameter is optional. It sets the timeout in milliseconds between two iterations of an action. By default, there is no time.

Action

An action is a block of instructions defined to attempt to achieve a goal, the block is executed in a repetitive manner, as in an iteration (but this is not one, we are in asynchronous mode).

You can also try to maximize value. In this case, when the time limit is reached, it ends with the nearest value of this target.

All this works asynchronously: If you define several goals in one program, the actions are triggered simultaneously, so it must work on independent variables.

It's really not competition, even if it looks like it. The generated JavaScript is based on the setInterval and setTimeout functions. This control structure is suitable for modeling and controlling a robot to control elements or parts and make them move towards the target, independently of each other.

Ex-extensive

Example of simple code:

int ai = 50
int bi = 5

to ai >= 100 for &
   ai = ai + bi
   int ai
/to 

Example single-line code:

int ci = 100

int addit()
   ci + bi
return ci

to ci >= 1000 for 0.9 do print addit()

If these two examples are placed in the same program, they will run at the same time, and their intermediate results will be displayed alternately.

If your code works locally with Node.js, you can also use the process and child_process libraries, which provide similar capabilities.

Here is JavaScript code from biblio scriptol.js that allows target orientation:

exports.goal = function(condi, dur, actio) { 
var iter = setInterval(function() {
if(condi()) {
clearInterval(iter);
clearTimeout(limiter);
return;
}
actio();
}, 0);
if(dur == "&") dur = 2147483647;
var limiter=setTimeout(function() { clearInterval(iter); }, dur);
}

This function is called with two functions as arguments, plus duration. For more information, see the code generated by the compiler.

Synchronous mode

For synchronous work, that is, in order for the fulfillment of goals to be carried out one after another, the syntax is as follows:

to ...condition... while ...durée...
  ...processus...
/to

On one line:

to ...condition... while ...durée... do ...action... 

The word "while" replaced the word "for."

Here is the JavaScript code for synchronous mode:

exports.goalSync=function(condi, dur, actio) { 
var stopFlag = false;
if(dur == "&") dur = 2147483647;
var limiter=setTimeout(function() { stopFlag = true; }, dur);
while(stopFlag == false) {
if(condi()) {
clearTimeout(limiter); stopFlag=true;
return;
}
actio();
}
}

Using more general than asynchronous mode, this control structure can be used in any processing.

Examples of SVG programs targeting .fr.