Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Continuous Alchemy Help Needed


So I can’t figure out what is wrong in my code. When the potion is thrown my character doesn’t move and the munchkin gets the water and slaughters the hero and Omarn.

# 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.
while True:
    enemy = hero.findNearestEnemy()
    item = hero.findNearestItem()
    # If there is no enemy, continue out of the loop.
    if not enemy:
    # If there is an enemy, but no item, ask for a potion and continue out of the loop.
    if not item:
        hero.say("Give me a drink!")
    # Use an if-statement to check the item's type. If the type is "poison", continue out of the loop.
    if item.type is poison:
        hero.moveXY(44, 36)
        hero.moveXY(34, 47)
    # If it is not, the potion must be a bottle of water, so walk to it and return to the starting position!


@Bryukh @nick

Any ideas guys


What is ‘poison’? Is it a variable? I think you forget quotes if you compare strings.


So whenever a type is referred like that, it must be in quotes? Thanks man


I’d say usually “yes”, but you have to understand the difference between unquoted names (variables) and strings, otherwise you will frequently run into this problem.

hero.say(item.type) # poison
hero.say(item.type == "poison") # True, item.type holds a string 
                                # with the value "poison"

whatType = "poison" # You can also store strings in variables
hero.say(item.type == whatType) # And then read the variable's value
                                # to use it in a comparison