Goto: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 2: | Line 2: | ||
/goto <label> | /goto <label> | ||
'''Note:''' Using a goto incorrectly could lead to an infinite loop. You can break out of a currently running script by pressing Control+Break. | '''Note:''' Using a goto incorrectly could lead to an infinite loop. You can break out of a currently running script by pressing Control+Break. | ||
You can also use a variable as a goto name, eg. | |||
:%jumppoint | |||
If %jumppoint were set to 5, /goto 5 would jump to that point in the script. | |||
==Example== | ==Example== | ||
/number { | /number { | ||
if ($1 == 1) goto one | [[if]] ($1 == 1) goto one | ||
elseif ($1 == 2) goto two | [[elseif]] ($1 == 2) goto two | ||
else goto unknown | [[else]] goto unknown | ||
:one | :one | ||
echo One | [[echo]] One | ||
halt | [[halt]] | ||
:two | :two | ||
echo Two | echo Two | ||
Line 18: | Line 22: | ||
} | } | ||
In the above alias, if the first parameter were 1, it would jump to label ''one'', otherwise if it were 2 it would jump to label ''two''. If it is none of those, it will jump to the ''unknown'' label. | In the above alias, if the first parameter were 1, it would jump to label ''one'', otherwise if it were 2 it would jump to label ''two''. If it is none of those, it will jump to the ''unknown'' label. | ||
/randpoint { | |||
[[var]] %jump1 = 1, %jump2 = 2 | |||
goto [[$r]](1,2) | |||
:%jump1 | |||
echo Picked jump 1! | |||
halt | |||
:%jump2 | |||
echo Picked jump 2! | |||
halt | |||
} | |||
The above alias is an example of using a variable as a point name. It will pick either point 1 or 2. | |||
[[Category:Commands]] | [[Category:Commands]] |
Latest revision as of 23:48, 6 April 2008
The /goto command allows you to jump from one point in a script to another point.
/goto <label>
Note: Using a goto incorrectly could lead to an infinite loop. You can break out of a currently running script by pressing Control+Break.
You can also use a variable as a goto name, eg.
:%jumppoint
If %jumppoint were set to 5, /goto 5 would jump to that point in the script.
Example
/number { if ($1 == 1) goto one elseif ($1 == 2) goto two else goto unknown :one echo One halt :two echo Two halt :unknown echo Unknown number! halt }
In the above alias, if the first parameter were 1, it would jump to label one, otherwise if it were 2 it would jump to label two. If it is none of those, it will jump to the unknown label.
/randpoint { var %jump1 = 1, %jump2 = 2 goto $r(1,2) :%jump1 echo Picked jump 1! halt :%jump2 echo Picked jump 2! halt }
The above alias is an example of using a variable as a point name. It will pick either point 1 or 2.