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


From Creatures Wiki
(Redirected from Doif)
Jump to navigation Jump to search

DOIF is a CAOS command controlling flow. If a DOIF or ELIF condition is not true (that is, something else is happening), the flow skips ahead to the next condition in the 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

It is generally more efficient to use ELIF rather than several DOIF-ENDI pairs after each other, as the engine usually runs 5 commands per TICK (unless INST is used).


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