Python Forum

Full Version: Winning/Losing Message Error in Text based Game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
initialize game loop
while True:
    if current_room['name'] == 'Chamber of Secrets':
        if inventory == ['heart', 'nose', 'empathy', 'eyeballs', 'soul', 'hair']:
            print('\nCongratulations!')
            print('\nYou have reached the Chamber of Secrets and helped Harry Potter to defeat Lord Voldemort!')
            break
        else:
            print("You have encountered Lord Voldemort without all six potion ingredients!")
            print('Game Over!')
            break
This is my winning and losing statements for a text based adventure I'm currently writing. The player has to move room-to-room gathering each inventory item before encountering the villain in his room. Even when I have all 6 items when I reach the villain's room, I'm still getting the loosing message. Not sure where I've messed up in my code. Any help is appreciated.
you need to show more code, at least show where inventory is being set
coding something like this without the use of functions (or classes) is difficult at best.
also, you will always exit this loop because you have a break at the end of each if statement.
Lists are not sets. They have an ordering. You are doing an equality test with a list, but that means the order has to be correct as well.

>>> ["a", "b"] == ["b", "a"]
False
If you don't care about the order, make your inventory a set. You can still add and remove items, but order is no longer important.

>>> {"a", "b"} == {"b", "a"}
True