SUBR

SUBR is a CAOS command that begins the definition of a subroutine. As of Creatures 1, it also had the same effects as STOP, so all subroutines should be placed at the end of a timer script.

Usage
Syntax: SUBR label(string)

Begins the definition of a subroutine. The subroutine will end at a RETN command.

The label is case-sensitive and should begin with a letter. It will be used with GSUB to go to the defined subroutine during code execution.

In C1, all SUBR labels should be 4 characters long.

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