GSUB

GSUB is a CAOS command that jumps to a subroutine.

Usage
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.

Example
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 doif ov10 lt 0 gsub walk_left else gsub walk_right endi velo va99 -8 retn subr walk_left anim [0 1 2 3 4 5 6 7 8 9 10 0] setv va99 -5 retn subr walk_right anim [12 13 14 15 16 17 18 19 20 21 22 12] setv va99 5 retn
 * ov10 indicates which way the toy is facing
 * walking left
 * walking right