HomePage | RecentChanges | Preferences

gosub iLabel


Jumps to the specified label, but returns to the next opcode when the return opcode is encountered.


The label the subroutine is at.


fade 500, 0 ; Fade out.
gosub @FadeWait ; Wait until done with fading.
fade 500, 1 ; Fade in again.
gosub @FadeWait


  wait 0
  if 0
  jf @FadeWait


Subroutines can be compared to functions or procedures in other programming languages.

gosub is great way to keep your code small and easy to read, by putting blocks of code that you use multiple times in subs. Sometimes putting code that 'belongs together' (but is only used once) in a sub can also help to keep your code easy to read.

Unfortunately, gosub does not accept arguments the way create_thread does. If you want to pass arguments, you can still use local variables to do so, but you will have to manually set them every time before calling the subroutine.

You can gosub six levels deep, at max.


HomePage | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited October 16, 2004 2:27 pm by CyQ (diff)
SourceForge.net Logo