DO
- LOOP
FUNCTION
RECEIVER
Calls a function trigger multiple times.( !?FU trigger)
NEW DO RECEIVER SYNTAX.
See below
!!DO#1/#2/#3/#4:XXXX; | Calls a function trigger multiple
times: #1 is number of function, #2 is start value #3 stop value #4 is increment |
OPTIONS
P$/$/$... up to 15#s. |
Run function many times: P Note: the
:P parameter must be placed in the !!DO calling (even if no values are to
be transfered to the loop) for the loop to work correctly. |
Comments:
The x16 variable (used in functions called with
the DO Receiver),
stores the current cycle number of the function. For example, if the function is
being repeated 12 times (from 1 to 12), the first time through, x16 will equal
1, the second time 2 and so on. If you change the x16 variable, you can actually
"speed up" or "slow down" a function loop, or even exit from it completely by
setting x16 equal to the end value (or higher) that was specified in the DO
receiver.
Now if you change x16 in the function you can speed up, slow down,
repeat or end the cycle. Moreover, all parameters are only set when you first enter the function. Within
the function, you may change them.
Example1:
!!DO1/2/10/2:P5;
...
!?FU1;
!!IF:M^Var x1=%X1 and x16=%X16^;
!!VRx1:+1; !!VRx16:+1;
It must show:
Var x1=5 and x16=2
Var x1=6 and x16=5
Var x1=7 and x16=8
Example2: Loop backwards, jumping 4 elements / loop (speeding up) , starting with 47
!!DO2/1/66/1:P47/11; [send value 47 to the function's variable x1]
!?FU2;
!!VRv5:Sx1+1-x16; [do the loop backwards]
!!IF:M^the present value of x16 is %X16 and v5 is %V5^;
!!VRx16:+7; [set jump value to 8]
Instead of 66
loops you get only 9 loops, with these values:
x16: 1 9 17 25 33 41 49 57 65
v5: 47 39 31 23 15 7 -1 -9 -17
Other sugestions: The same can be done forwards. Also, the !!VRx16:+7; can be replaced (i.e.) with R7: "!!VRx16:R7";, calculating a next random jump value up to 7, every jump, or (i.e.) with Rx2: "!!VRx16:Rx2", calculating a random number up to x2, in this case x2 being 11 (!!DO2/1/66/1:P47/11;).
However, you have got to take care when asigning x16 a value, directly or through another variable. If this value is not within the loop extremes (in this case 1 and 66: !!DO2/1/66/1:P47/11;) the cycle breakes, meaning you end the loop prematurely.
Questions and
answers:
Q:
How is x16 effected by nested DOs?
A: Each DO loop keeps its own x16 value.
Q: Let's
say I have the following code: (this would reflect, say, checking a 10x11 array
for something)
!!DO1/1/10/1:P;
!?FU1;
!!DO2/20/30/1:P;
point A
!?FU2;
point B
My question is, at point B, will x16 have a value between 1 and 10, or
between 20 and 30?
A: 20 and 30
Q: Also, at
point A, will x16 have the value from DO1, or DO2?
A: DO1,
because the line is inside FU1 function
A: (note) If you change the value of x16, that will change the loop. For example, if you set x16 to 999 (or even 50 in this case), that would end this loop as soon as it checks the x16 value (after it finishes one looping).
Q: I have a
main loop covering all heroes (DO1/0/155/1), but for each hero I need to check
through all creature slots (DO2/0/6/1). Would it work?
A: That should work fine with a standard nested DO loop structure
as far as I can tell.