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

Difference between revisions of "DOIF"

From Creatures Wiki
Jump to: navigation, search
m (Added category)
Line 36: Line 36:
[[Category:C1 CAOS Commands]]
[[Category:C2 CAOS Commands]]
[[Category:C3 CAOS Commands]]
[[Category:C3 CAOS Commands]]

Revision as of 15:51, 7 June 2018

DOIF is a CAOS command controlling flow.


Syntax: DOIF cond (condition) ..

DOIF is part of a set of commands used for conditional execution of code. It marks the start of a code block to execute if cond is true. It must be followed by another conditional execution marker: ELIF, ELSE or ENDI.

Some valid patterns for DOIF.. code are:

  • DOIF .. ENDI
  • DOIF .. ELSE .. ENDI
  • DOIF .. ELIF .. (ELIF ..) ENDI
  • DOIF .. ELIF .. (ELIF ..) ELSE .. ENDI

where .. indicates a code block for execution under conditions.

DOIF blocks can also be "nested". C1 discussion of nested DOIF C3/DS discussion of nested DOIF


Here is a simple way of using DOIF and its confederates. If the current pose is 0, change it to 1; if it is 3, change it to 2; in any other case, change it to 5.

* change an agent's pose depending on how it looks now.
  POSE 1
  POSE 2
  POSE 5

DOIF is an important part of the CAOS language and many examples for other commands and functions use it. For instance, see the ROT13 script on CHAR, the implementation of SINS, and the third example in ATTR.

See also