Gosub
gosub runs the sub with the given name. When the sub reaches
return, the script goes on with the line after the gosub.
Parameters
Section titled “Parameters”| Parameter | Meaning |
|---|---|
sub name |
Name of the sub. Case does not matter. |
parameter |
Optional values passed to the sub. Inside it, %1, %2, … hold them and %0 holds how many there are. |
Details
Section titled “Details”- No sub with that name: nothing happens and the script goes on with the next line.
- Several subs with the same name: the last one in the script is used.
- Nesting: about 1000
gosubcalls can be open at once without returning. Beyond that the oldest one is dropped, so recursion that deep loses track of where to come back to. - Leave a sub with
return, never withgoto: everygosubthat does not return stays open.
A sub can return a value in #Result: return %value.
Examples
Section titled “Examples”gosub greet Jim Bobhalt
sub greet ; %0 = 2, %1 = Jim, %2 = Bob display ok Hello %1 and %2returnAny number of parameters, walked with %0:
gosub joinwords These are the parametersdisplay ok #Resulthalt
sub joinwords set %message for %n 1 %0 set %message %message , % . %n , #spcreturn %messageSee also
Based on the EasyUO wiki, edited for EasyUO Reforged. This text is available under the GNU Free Documentation License 1.2.