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

RETN

From Creatures Wiki
Jump to navigation Jump to search

RETN is a CAOS command that ends the definition of a subroutine.

Usage[edit]

Syntax: RETN

Ends the definition of a subroutine began by a SUBR command. Do not use RETN from another block of code (when calling the subroutine with GSUB, for instance, or from within a LOOP).

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]