Difference between revisions of "Sub"
From Wiki
(→Example 1) |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | {{command header|Flow Control}} | |
+ | {{body|sub {sub name} |The ''sub'' command starts a smaller macro within the macro. You transfer to the [[sub]] by using [[gosub]] elsewhere in the macro. Use [[return]] to go back to where the [[gosub]] was previously.}} | ||
+ | |||
+ | {{note|You must not jump out of a sub! Use return to properly terminate a sub routine. To prevent a stack overflow, EUO only supports 1000 consecutive GoSubs without returning. Remember this when using recursion! When the GoSub stack is about to get 1001 levels, the very first level in the bottom of the stack is deleted to make room.}} | ||
+ | |||
+ | |||
+ | ==== Example ==== | ||
+ | <pre> | ||
+ | mainloop: | ||
+ | gosub speakgame hi | ||
+ | wait 1s | ||
+ | goto mainloop | ||
+ | |||
+ | sub speakgame | ||
+ | exevent macro 1 0 %1 | ||
+ | return | ||
+ | </pre> | ||
+ | |||
+ | == Related Commands == | ||
+ | {| style="background:gainsboro; color:black; border: 2px #aaa solid;" | ||
+ | | Width=250px align=center | [[Gosub]] || Width=250px align=center | [[Return]] | ||
+ | |} | ||
+ | {{footer}} |
Latest revision as of 10:39, 3 August 2007
Synopsis
sub {sub name}
Description
The sub command starts a smaller macro within the macro. You transfer to the sub by using gosub elsewhere in the macro. Use return to go back to where the gosub was previously.
Note: | You must not jump out of a sub! Use return to properly terminate a sub routine. To prevent a stack overflow, EUO only supports 1000 consecutive GoSubs without returning. Remember this when using recursion! When the GoSub stack is about to get 1001 levels, the very first level in the bottom of the stack is deleted to make room. |
Example
mainloop: gosub speakgame hi wait 1s goto mainloop sub speakgame exevent macro 1 0 %1 return
Related Commands
Gosub | Return |
See also
Main Page | Documentation |