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
#1
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.
Reply
#2
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.
Reply
#3
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
jefsummers likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error message about iid from RandomizedSearchCV Visiting 2 1,006 Aug-17-2023, 07:53 PM
Last Post: Visiting
  Color a table cell based on specific text Creepy 11 1,959 Jul-27-2023, 02:48 PM
Last Post: deanhystad
  Another Error message. the_jl_zone 2 974 Mar-06-2023, 10:23 PM
Last Post: the_jl_zone
  Sending Whatsapp Message in the text file ebincharles869 9 3,513 Jun-21-2022, 04:26 PM
Last Post: snippsat
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 1,509 Apr-04-2022, 09:29 PM
Last Post: Larz60+
  Extracting Specific Lines from text file based on content. jokerfmj 8 2,952 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,990 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  understanding error message krlosbatist 1 1,904 Oct-24-2021, 08:34 PM
Last Post: Gribouillis
  Extract text based on postion and pattern guddu_12 2 1,625 Sep-27-2021, 08:32 PM
Last Post: guddu_12
  Error message pybits 1 39,972 May-29-2021, 10:26 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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