Jump to navigation Jump to search
GSUB is a CAOS command that jumps to a subroutine.
Syntax: GSUB label(string)
Jumps to a subroutine which is defined elsewhere in the code (usually at the end of the normal code flow) with a SUBR command and the same label. The code following the GSUB command will continue executing after the end of the subroutine.
Subroutines are very often used in more complex agents, since they make the code much easier to deal with and more human-readable. The Robot Toy is relatively simple - it's a toy, not a plant or an animal - but it still has three subroutines just to deal with walking!
subr walk sndc "rob1" frat 1 **ov10 indicates which way the toy is facing doif ov10 lt 0 gsub walk_left else gsub walk_right endi velo va99 -8 retn *walking left subr walk_left anim [0 1 2 3 4 5 6 7 8 9 10 0] setv va99 -5 retn *walking right subr walk_right anim [12 13 14 15 16 17 18 19 20 21 22 12] setv va99 5 retn