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

Difference between revisions of "DOIF"

From Creatures Wiki
Jump to navigation Jump to search
(+example (not so good...))
m
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
'''DOIF''' is a [[CAOS]] command controlling flow.
+
'''DOIF''' is a [[CAOS]] command controlling [[Flow (CAOS)|flow]].
  
 
==Usage==
 
==Usage==
Line 12: Line 12:
 
*''DOIF .. ELIF .. (ELIF ..) ELSE .. ENDI''
 
*''DOIF .. ELIF .. (ELIF ..) ELSE .. ENDI''
 
where .. indicates a code block for execution under conditions.
 
where .. indicates a code block for execution under conditions.
 +
 +
DOIF blocks can also be "[https://en.wikipedia.org/wiki/Nesting_(computing) nested]". [https://web.archive.org/web/20201026002851/https://discoveralbia.com/2015/06/solving-c1-caos-with-nested-doif-statements.html C1 discussion of nested DOIF] [https://creaturescaves.com/dev.php?section=Advice&view=3521 C3/DS discussion of nested DOIF]
  
 
==Examples==
 
==Examples==
Line 34: Line 36:
 
*[[ENDI]]
 
*[[ENDI]]
  
 +
[[Category:C1 CAOS Commands]]
 +
[[Category:C2 CAOS Commands]]
 
[[Category:C3 CAOS Commands]]
 
[[Category:C3 CAOS Commands]]

Revision as of 20:23, 22 July 2022

DOIF is a CAOS command controlling flow.

Usage

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

Examples

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.
DOIF POSE eq 0
  POSE 1
ELIF POSE eq 3
  POSE 2
ELSE
  POSE 5
ENDI

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