Help with Continuous Alchemy


#1

Hi, I need help with level 10 of the Sarven Desert. The system says that there are no errors in the code, but my character just doesn’t go and get the water.

# Race munchkins to the water distilled by Omarn Brewstone!
# The continue statement is powerful for managing complicated logic.
# When the program uses the continue statement, the rest of the loop is skipped.
# However, unlike with "break", the loop repeats instead of stopping.
# Use "continue" to verify the conditions of the ambush.
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!")
       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":
        continue
    # If it is not, the potion must be a bottle of water, so walk to it and return to the starting position!
    else:
        self.moveXY(item.pos.x, item.pos.y)
        self.moveXY(32, 47)
        continue
    continue

Any help would be appreciated.


#2

When you used self.moveXY(item.pos.x, item.pos.y) you didn’t indent it so that it would be inside the else:. Did you do this on purpose?


#3

It is aligned with the else: in game. Accidentally made a typo when posting this thread.


#4

Ok, thanks for the info. But can you edit it?


#5

Fixed.

I still need help with the level though, I’ve been trying to figure it out for a while and no luck.


#6

yo escribi este codigo y me funciono en la segunda vuelta hay q usar la bandera por q le hero se traba y no coge el agua

while True:
enemy = hero.findNearestEnemy()
item = hero.findNearestItem()
flag = hero.findFlag()

# Si no hay enemigo, continúa fuera del bucle.
if not enemy:
    continue

if flag:
    if flag.color is "black":
        hero.moveXY(flag.pos.x, flag.pos.y)
        hero.pickUpFlag(flag)
# Si hay un enemigo, pero no hay artículo, pide una poción y continúa fuera del bucle.
if not item:
    hero.say("¡Dame agua!")
    continue

# Usa una sentencia-if para comprobar el tipo del artículo. Si es de tipo "poison" (veneno), continúa fuera del bucle.
if item.type == "poison":
    continue
# Si no lo es, la poción debe ser una botella de agua, camina hasta ella y vuelve a la posición inicial!
# so moveXY to the potion, then back to the start!
if item.type != "poison":
    hero.moveXY(item.pos.x, item.pos.y)
    hero.moveXY(33, 42)