DarwinBotsManual
Open the app EspañolES

else

Opens the alternative body of a gene, which runs when the conditions of the cond came out false.

Facts

Word
else
Family
Flow
What it does
Opens the “otherwise” body: it runs only if the conditions of the gene were false. After a start with no cond, a stop or another else, it never runs.
Cost
Flow control; end is free
Runs
always

else is the gene's “otherwise”. In cond C start A else B stop, body A runs when the conditions C are true and B when they are false. They never both run in the same cycle.

' moves forward while it has more than 2000 energy; otherwise, it turns
cond
 *.nrg 2000 >
start
 20 .up store
else
 50 .aimdx store
stop

With 2500 energy the bot moves forward with .up; with 1500 it stays still and turns with .aimdx. Note one detail: in the first cycle it turns even if it has 2500, because .nrg is still 0 and the condition comes out false. The senses arrive only from the second cycle (see Execution and costs).

It is also valid right next to the conditions, without start: cond C else B stop runs B only when C is false, and there is no body for the true case.

An else that has no cond … start (or a cond) right before it never runs: after a start without cond, after a stop or after another else.

The else counts as a separate gene in .genes and .thisgene: in cond … start … else … stop there are two genes.