1
DNA - General / If - Elseif - Else
« on: August 30, 2008, 09:19:20 PM »
It is definitely possible, and has in fact been done before.
Example from Nanite Detonators 2.3:
(The code may LOOK complicated, but each line in the first block of code corresponds to one line in the second block of code, and the lines which set shoot and shootval should set things apart nicely too.)
Note: elif is the same concept as elseif
The readable code prior to being compiled by PyBot:
DarwinBots code:
The last dropbool line is kind of like an "endif" sitting there by itself. The other places where blocks ended, the dropbools and such were placed at the beginning of the next line. (So did this one, but someone might have said "Where'd '*.numties 0 =' come from?" if I had pasted the entire line )
Example from Nanite Detonators 2.3:
(The code may LOOK complicated, but each line in the first block of code corresponds to one line in the second block of code, and the lines which set shoot and shootval should set things apart nicely too.)
Note: elif is the same concept as elseif
The readable code prior to being compiled by PyBot:
Code: [Select]
if (nrg>500):
if ((eyef>0) and ((in1!=ID1) or ((memval!=genes) and (memloc==&genes))) and (robage>2) and (refage>2) and (shootval==0)):
aimshoot = aim - angle(refxpos, refypos)
if ((timer andbits 3)==0):
shoot = -1
shootval = 10
elif ((timer andbits 3)==1):
shoot = -6
shootval = -10
elif ((timer andbits 3)==2):
shoot = &mkslime
shootval = -31999
else:
shoot = &shootval
shootval = 31999
DarwinBots code:
Code: [Select]
*.nrg 500 >
dupbool dupbool *.eyef 0 > *.in1 9136 != *.memval *.genes != *.memloc .genes = and or and *.robage 2 > and *.refage 2 > and *.shootval 0 = and and
*.aim *.refxpos *.refypos angle sub .aimshoot store
dupbool dupbool *.timer 3 & 0 = and
-1 .shoot store
10 .shootval store
not and not dupbool not dupbool *.timer 3 & 1 = and
-6 .shoot store
-10 .shootval store
not and dupbool *.timer 3 & 2 = and
.mkslime .shoot store
-31999 .shootval store
not and not or not
.shootval .shoot store
31999 .shootval store
dropbool
dropbool dropbool
dropbool
The last dropbool line is kind of like an "endif" sitting there by itself. The other places where blocks ended, the dropbools and such were placed at the beginning of the next line. (So did this one, but someone might have said "Where'd '*.numties 0 =' come from?" if I had pasted the entire line )