Everys
From Original War Support Wiki
Tutorials -> Everys
Before this
Please read: Time in Original War
Basics
Everys are basically timers which allow to execute blocks of code after specified time. Every X ticks an every will execute its code but only as long as it's enabled. It gets disabled automatically every time its code is executed so it won't run again unless you enable it!
every 1 do begin enable; // We want to enable it unconditionally so that it runs unless it gets disabled somewhere // Some code here end;
The above code will run after 1 tick and then every 1 tick since we re-enable it every time it runs. Worth noting is a fact that re-enabling can be delayed with any wait() command issued before enable.
You can use var to declare local variables. begin/end can be omitted if there are no variable declarations and body of the block is one command long.
Triggered everys
Triggered everys are slightly different from the basic ones. They run only if their trigger statement evaluates true.
every 0$1 trigger x = 1 do begin // Some code here end;
In the example above the statement (x = 1) gets evaluated every one second (0$1) until it's true and as long as the every isn't disabled. When it evaluates to true, everything happens as if it was a normal every.
Marked everys
All everys start enabled. Sometimes you would like to have some available but not yet enabled - without using the trigger - to save CPU cycles.
The thing you need is to be able to enable/disable them remotely. SAIL has a solution.
To be able to identify an every, you have to mark it:
every 0$1 marked 1 do begin // Some code here end;
In this example we have an every identified by 1. We can use this integer to control the every remotely:
disable(1);
or
enable(1);
Delaying everys
You can delay an every using this syntax:
every <TIME1> + <TIME2> do
Such an every will be run the first time after <TIME1> + <TIME2> seconds but subsequently only every <TIME1> seconds. So if we have an every like this:
every 0$3 + 0$20 do
it will run the first time after 23 seconds but after that every 3 seconds.