Help, may someone help with the "move" command? it can't be a bug

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)
[/details]
<br/>

......Why?

Do you have the right boots?

yep. the one with move command.

Your problem is here

        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.

1 Like

Many thanks. Yes I see. it is “1 step”.

Is there a problem with this code? The sprite won’t move when there is water.

loop:
enemy = self.findNearestEnemy()
item = self.findNearestItem()

# 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

To check type use:

if item.type is 'poison':

or

if item.type is not 'poison':

you can also use == and !=

Thanks. It works well and I have passed the level.