Python Forum
Winning/Losing Message Error in Text based Game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Winning/Losing Message Error in Text based Game
initialize game loop
while True:
    if current_room['name'] == 'Chamber of Secrets':
        if inventory == ['heart', 'nose', 'empathy', 'eyeballs', 'soul', 'hair']:
            print('\nYou have reached the Chamber of Secrets and helped Harry Potter to defeat Lord Voldemort!')
            print("You have encountered Lord Voldemort without all six potion ingredients!")
            print('Game Over!')
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"]
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"}
jefsummers likes this post

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error message pybits 1 320 May-29-2021, 10:26 AM
Last Post: snippsat
  Environment seems to keep losing references spacedog 2 411 Apr-23-2021, 07:36 PM
Last Post: spacedog
  A text-based game [SOLVED] Gameri1 6 775 Apr-20-2021, 02:26 PM
Last Post: buran
  f-string error message not understood Skaperen 4 566 Mar-16-2021, 07:59 PM
Last Post: Skaperen
  OOP vs functional - - elaborate turn based RPG game (Derek Banas Udemy course again) Drone4four 6 877 Mar-14-2021, 08:38 AM
Last Post: ndc85430
  Overwhelmed with error message using pandas drop() EmmaRaponi 1 451 Feb-18-2021, 07:31 PM
Last Post: buran
  losing memory antioch 1 408 Jan-20-2021, 05:29 AM
Last Post: antioch
  how to make a hotkey for text adventure game myn2018 2 468 Jan-06-2021, 10:39 PM
Last Post: myn2018
  cx_Oracle.DatabaseError: Error while trying to retrieve text from error ORA-01804 rajeshparadker 0 2,572 Nov-12-2020, 07:34 PM
Last Post: rajeshparadker
  Split gps files based on time (text splitting) dervast 0 385 Nov-09-2020, 09:19 AM
Last Post: dervast

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020