[Home]0050

HomePage | RecentChanges | Preferences

gosub iLabel

Description

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

Parameters

iLabel
The label the subroutine is at.

Example

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

...

@FadeWait
  wait 0
  if 0
    !is_fading
  jf @FadeWait
  return

Comments

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.


CategoryStructuralOpcodes

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