Welcome to the Creatures Wiki! Log in and join the community.

SUBR

From Creatures Wiki
Revision as of 23:41, 15 March 2018 by Pilla (talk | contribs) (recategorize)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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[edit]

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[edit]

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

See Also[edit]