Sub
CommandFlow control
sub {name}...return [value]Also searchable as: Sub · subroutine · function · procedure
sub starts a sub: a named group of lines that gosub runs, ending with
return. Parameters passed by gosub are in %1, %2, … and their number is in
%0.
gosub say hello worldhalt
sub say display ok %0 words: %1 %2returnWhere to put subs
Section titled “Where to put subs”When the normal flow of the script reaches a sub line, it does not run the sub: it jumps over it, to the
line after the sub’s first return. A sub with an early return, such as one inside an if, is
therefore not skipped completely: the script lands in the middle of it. Two ways to avoid that:
- Put the subs after the main part of the script, after its
haltor its finalgoto, where the flow never reaches them. This is the usual layout. - Or wrap the body in a block right after the
subline. The script then skips the whole block:
sub check{ if %x = 0 return 0 return 1}
set %x 0gosub checkdisplay ok #Result ; 0haltDetails
Section titled “Details”- Names are not case-sensitive. When two subs have the same name,
gosubuses the last one in the script. - Leave a sub with
return, never withgoto.
See also
Based on the EasyUO wiki, edited for EasyUO Reforged. This text is available under the GNU Free Documentation License 1.2.