<script type="text/javascript">
function selectText(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
}
}
</script>
<a href="#" onclick="selectText('selectable')">Select All</a><br/>
Save the contents to "Program Flow Control.txt"
<div id="selectable">
=CMD =COMMAND once =DESC Start a block of instructions that are executed once only for the lifetime of the tower the script is associated with. =ENDDESC =EX once trace("42") #Only prints once endonce =ENDEX =ENDCMD =CMD =COMMAND endonce =DESC Ends a block defined by once. =ENDDESC =EX once trace("42") #Only prints once endonce =ENDEX =ENDCMD =CMD =COMMAND if (bool) =DESC bool ARG1: The value to evaluate<p/> Evaluate the first element on the stack. If True, then execute statements that follow, up to the endif or else statement. If False, execution skips to the first statement following the endif or else statement. Any nonzero value is considered True, a value of zero is False. =ENDDESC =EX if (<-var eq (1)) #Do Something endif =ENDEX =ENDCMD =CMD =COMMAND else =DESC When the if statement evaluates to False, then the statements following the else, up to the endif, are executed instead. =ENDDESC =EX if (<-var eq (1)) #Do something else #Do something else endif =ENDEX =ENDCMD =CMD =COMMAND endif =DESC Delimits the scope of an if-else-statement. Instructions between the if and endif statement are conditionally executed, depending on the results of the if evaluation. =ENDDESC =EX if (<-var eq (1)) #Do something else #Do something else endif =ENDEX =ENDCMD =CMD =COMMAND do =DESC The statements following the do, up to the loop statement, are executed repeatedly. Each iteration (loop), the initial value (Index) is incremented by one at the bottom of the loop and compared to Limit. When Index=Limit, execution will proceed at the first statement following Loop. Loops can be nested, but no more than 3 deep. See also: I, J and K<p/> NOTE: Limit comes first, then the initial value (index). This means that the first number should usually be bigger than the second number. =ENDDESC =EX do(5 0) trace(I) loop =ENDEX =ENDCMD =CMD =COMMAND loop =DESC Terminates the 'do' instruction. Control flow will return to the 'do' instruction until the Index is equal to the Limit. =ENDDESC =EX do(5 0) trace(I) loop =ENDEX =ENDCMD =CMD =COMMAND I number =DESC Current loop Index. Pushes the value of the current loop onto the stack. Only use within loops =ENDDESC =EX do(5 0) trace(I) loop =ENDEX =ENDCMD =CMD =COMMAND J number =DESC First outer loop index. When loops are nested, this pushes the value of the first (or only) outer loop onto the stack. =ENDDESC =EX do(2 1) do(4 3) I mul(J) trace loop loop =ENDEX =ENDCMD =CMD =COMMAND K number =DESC Outer loop index. When loops are nested, this pushes the value of the outermost loop onto the stack. =ENDDESC =EX do(2 1) do(4 3) do(6 5) trace(I J K mul mul) loop loop loop =ENDEX =ENDCMD =CMD =COMMAND while =DESC Beginning of a while loop. The statements between a 'while' and a 'repeat' should ultimately push a value to the stack that will determine if the loop executes the body of the 'repeat' block. =ENDDESC =EX 5 ->y while <-y gt(0) #is y greater than zero? repeat #repeat this section of code trace(<-y) <-y sub(1) ->y #subtract 1 from y so we don't end in infinite loop endwhile =ENDEX =ENDCMD =CMD =COMMAND repeat (bool) =DESC Pops an item from the stack. If true, execute the following statements. If false, jump to the statement following 'endwhile'. =ENDDESC =EX 5 ->y while <-y gt(0) #is y greater than zero? repeat #repeat this section of code trace(<-y) <-y sub(1) ->y #subtract 1 from y so we don't end in infinite loop endwhile =ENDEX =ENDCMD =CMD =COMMAND endwhile =DESC Returns execution to the 'while' statement. Note that endwhile is only executed, if 'repeat' evaluated to true. =ENDDESC =EX 5 ->y while <-y gt(0) #is y greater than zero? repeat #repeat this section of code trace(<-y) <-y sub(1) ->y #subtract 1 from y so we don't end in infinite loop endwhile =ENDEX =ENDCMD =CMD =COMMAND break =DESC Immediately exits the body of a 'while/repeat/endwhile' block or a 'do/loop' block. =ENDDESC =EX do(5 0) if (I mod(2) eq0) #divide inner loop with modulo 2 and test if zero break endif trace(I) loop =ENDEX =ENDCMD =CMD =COMMAND return =DESC Stops execution of a function call and returns immediately. If called from some place other than a function, it will stop the script execution and 'return' immediately. Useful for aborting function execution or script execution when necessary. =ENDDESC =EX trace("42") @MyFunc :MyFunc trace("1") return trace("2") =ENDEX =ENDCMD =CMD =COMMAND delay (number) =DESC The number of game loops to wait before allowing execution to pass to the next command. Timers used via SetTimer(0-3) continue to run and expire even while the script is delayed. =ENDDESC =EX #Stop runtime of the script for 30 game ticks, equivalent of 1 second. delay(30) trace(GetUpdateCount) =ENDEX =ENDCMD
</div>