DarwinBotsManual
Open the app EspañolES

dupbool

Duplicates the value on top of the boolean stack. Good for saving a condition and using it again, for example to nest conditions in the body.

Facts

Word
dupbool
Family
Logic
Boolean stack
pops 1, pushes 2
What it does
Copies the top of the boolean stack. With an empty stack it does nothing, unlike dup.
Cost
Logic
Runs
inside a gene: in the condition (cond) and in the body (start or else)

dupbool pushes a copy of the value on top of the boolean stack. With an empty stack it does nothing.

Its use is nesting conditions inside the body: you save a copy of the outer condition, combine it with an inner one using and, and when done a dropbool gives you back the outer one intact for the next. The bot This'n'That 1.01 (Peksa), from the Bestiary, does this to balance energy (.nrg) and body (.body):

' This'n'That 1.01 (Peksa): balances energy and body
cond
start
  *.nrg *.body !%= dupbool
  *.nrg *.body > and
  *.nrg *.body sub 100 ceil .strbody store dropbool
  *.body *.nrg > and
  *.body *.nrg sub 100 ceil .fdbody store
stop

The outer condition is “energy and body differ by more than 10%” (!%=). The boolean stack goes through:

AfterBoolean stack (top on the right)
!%= dupbooldiffer, differ
> anddiffer, (differ and energy to spare)
dropbooldiffer
> and(differ and body to spare)

That way, if there is energy to spare it moves it to the body (.strbody) and if there is body to spare it moves it to energy (.fdbody), 100 at a time at most (ceil keeps the smaller). A bot that starts with 3000 energy and 1000 body stops at 1300 and 1170.