05 Jan 13, 11:24PM
Little script for the next version:
[cubescript]// do-while loops for cubescript by Bukz
// Requires AC 1.2.0.0 or better.
// Syntax:
// do [
// // body of code here
// // can span multiple lines/statements
// ] while [ (expression) ]
do = [
targ1 = $arg1
targ2 = $arg2
targ3 = $arg3
if (strcmp $targ2 while) [
execute $targ1
tmpExpression = (concat [bool =] $targ3)
execute $tmpExpression
if (!= $bool 0) [
sleep 0 [ do $targ1 while $targ3 ]
]
]
][/cubescript]
Example:
[cubescript]testdo = [
i = 0
do [
+= i 1
echo $i
] while [ (< $i 10) ] // brackets are needed
]
// Then execute the /testdo command in-game to see the output.
// Remember a do-while loop executes at least once no matter what,
// and the expression is evaluated AFTER every iteration, therefore
// the /testdo command should output the numbers 1 through 10 on the
// console. Brackets "[]" are needed around the expression argument
// for the do-while loop to work properly.[/cubescript]
[cubescript]// do-while loops for cubescript by Bukz
// Requires AC 1.2.0.0 or better.
// Syntax:
// do [
// // body of code here
// // can span multiple lines/statements
// ] while [ (expression) ]
do = [
targ1 = $arg1
targ2 = $arg2
targ3 = $arg3
if (strcmp $targ2 while) [
execute $targ1
tmpExpression = (concat [bool =] $targ3)
execute $tmpExpression
if (!= $bool 0) [
sleep 0 [ do $targ1 while $targ3 ]
]
]
][/cubescript]
Example:
[cubescript]testdo = [
i = 0
do [
+= i 1
echo $i
] while [ (< $i 10) ] // brackets are needed
]
// Then execute the /testdo command in-game to see the output.
// Remember a do-while loop executes at least once no matter what,
// and the expression is evaluated AFTER every iteration, therefore
// the /testdo command should output the numbers 1 through 10 on the
// console. Brackets "[]" are needed around the expression argument
// for the do-while loop to work properly.[/cubescript]