my code:
while True:
flag = self.findFlag("green")
if flag.type == "Green":
self.pickUpFlag(flag)
else:
enemy = hero.findNearestEnemy()
item = self.findNearestItem()
if item:
self.moveXY(item.pos.x, item.pos.y)
if enemy:
hero.attack(enemy)
on line three it says that .type is null
What if there isn’t a flag? ‘flag.type’ would be null then.
1 Like
Is this your brother’s code? If so, don’t forget to change self to hero.
if flag.type == "green": # this may be an error, it will be null if you didn't place down any flags
if flag and flag.type =="green": # this will not result an error, and you dont capitalize the 'g'
You need only
if flag:
because this
finds only the green flag.
that woks 2 (20 chars so#……¥#……¥……#@)#(&¥296083643864*#……¥*#…………8^**@&)(!@+!)@!@)^*&#%%^($#& )
actually i made it but now hero is turning in to self and self does the same thing as hero
like this?
while True:
flag = hero.findFlag("green")
if flag and flag.type == "green"":
self.pickUpFlag(flag)
else:
enemy = hero.findNearestEnemy()
item = self.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
if enemy:
hero.attack(enemy)
if flag: #===> just do if flag because you already did 'flag = hero.findFlags("green")'
i made a new code because he would attack and then get distracted with the items then take damage then go back to attacking so orges get giant because of the mushrooms and well i would die so i made a other code but he wont get any flag or do anything but it says everything is fine with it
code:
while True:
flag = hero.findFlag("green")
flag = self.findFlag("black")
if flag and flag.type == "green":
hero.pickUpFlag("green")
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
else:
continue
elif flag and flag.type == "black":
hero.pickUpFlag("black")
item = self.findNearestItem()
if item:
self.moveXY(item.pos.x, item.pos.y)
green flag means attack but it does nothing not even pick the flag up black is get item but well it has the same problem
I suggest you not to play the level, its mega hard, i beat it with over 3500 health and barely had any health left
I found the problem
flag = hero.findFlags('green')
flag = hero.findFlags('black') # you're using flag for both color flags,
# the hero wont know which color you're using
# because you can't place down 2 color flags at the same time
# Instead, use the code below:
flagG = hero.findFlags('green')
flagB = hero.findFlags('black')
if flagG:
# Do stuff then pick it up
if flagB:
# Do stuff then Pick it up
well i had to change loads of code and now green flag works but not black
code:
while True:
flagG = hero.findFlag('green')
flagB = hero.findFlag('black')
if flagG:
hero.pickUpFlag(flagG)
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
else:
continue
elif flagG:
hero.pickUpFlag(flagB)
while True:
item = self.findNearestItem()
if item:
self.moveXY(item.pos.x, item.pos.y)
1 Like
Um, do what? 
I think you have a slight typo here.
well now after the first wave my hero stops
code:
while True:
flagG = hero.findFlag('green')
flagB = hero.findFlag('black')
if flagG:
hero.pickUpFlag(flagG)
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
else:
continue
elif flagB:
hero.pickUpFlag(flagB)
while True:
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
black means collect items
1 Like
What glasses are you using? I’m thinking that your ‘while true’ loops are part of the problem. If you have Twilight equipped, you are finding every enemy on the map, so are getting stuck. I used Enchated…gave me infinite range, but not through walls. Your first inner loop is going to look for enemies forever. Actually, you apparently don’t have Infinity do you? Instead of what I first thought, it appears that you are clearing all line of site enemies and items and then it stops. Doesn’t he need to go around the corner a ways to see the next group of enemies?
Maybe using ‘while true’ is not the best solution? I used a very different strategy, one not using flags, so this is only an educated guess. Perhaps iterating through an array of visible enemies might work better?..it’s a thought 
1 Like
Also, keep the move methods in mind. Think of moveXY as a fire and forget method…once it fires, no further code will fire until the destination is reached. With the ‘move’ method, you take a step, execute any following code, then continue on the next loop, continuing the move from where you left off (so to speak).