# Put flags where you want to build traps.
# When you're not building traps, pick up coins!
while True:
flag = hero.findFlag()
if flag:
# How do we get flagX and flagY from the flag's pos?
# (Look below at how to get x and y from items.)
flag = hero.findFlag("green")
hero.buildXY("fire-trap", flagX, flagY)
hero.pickUpFlag(flag)
else:
item = hero.findNearestItem()
if item:
itemPos = item.pos
itemX = itemPos.x
itemY = itemPos.y
hero.moveXY(itemX, itemY)
Immediately after your conditional if flag: statement; you have defined the variable, flag, a second time. This second assignment is unnecessary and should be removed. Also, look at the way you have defined itemX and itemY . Do you think it might be a good idea to do this for flagX and flagY as well?
I think the level has a flaw. If you are sufficiently fast you have no need to build anything and to win without fighting. When possible I don’t use flag except in rare occasions. So I rewrote the level in coffee-script and in midway to finish it I saw the screen:
There are other levels where you can achieve success with just a line or two of code. There are other levels where flags can be used where they are not intended and it makes for an easy way to complete the level. Yes, it allows the completion of the level, but the point of the lesson is missed. One only cheats oneself if done this way.
@Luke10. Necroposting is ok as long as the post is relevant to the current thread. Necroposting is actually better than bunch of topics with the same thing.