It’s the problem I encountered in map3, case “Continuous-Alchemy”.
First of all I’ve managed to clear the stage with the following code:
The code which works
loop:
enemy = self.findNearest(self.findEnemies())
item = self.findNearest(self.findItems())
if not item:
self.say("Give me a drink!")
item = self.findNearest(self.findItems())
continue
if item.type != "poison":
item = self.findNearest(self.findItems())
self.moveXY(44, 35)
self.moveXY(34, 47)
However once replacing the "moveXY" to "move", code won't work. Instead the character start looping(waddling) around his/her initial position.
[details=The code that fails (self.move(item.pos))]
```
loop:
enemy = self.findNearest(self.findEnemies())
item = self.findNearest(self.findItems())
if not item:
self.say("Give me a drink!")
item = self.findNearest(self.findItems())
continue
if item.type != "poison":
item = self.findNearest(self.findItems())
self.move(item.pos)
self.moveXY(34, 47)
move() goes one step and then yields and then the next time the loop comes around it moves another step. moveXY() moves the whole way there and then moves onto the next task.
What is happening is you are taking 1 step towards the potion and then move back to (34, 47) every time you loop.
# If there is no enemy, continue out of the loop.
if not enemy:
continue
# If there is an enemy, but no item, ask for a potion and continue out of the loop.
if not item:
self.say("Give me a drink please.")
continue
# Use an if-statement to check the item's type. If the type is "poison", continue out of the loop.
if item.type:
"poison"
# If it is not, the potion must be a bottle of water, so walk to it and return to the starting position!
if not "poison":
self.moveXY(44, 36)
self.moveXY(34, 48)
continue