I am programming a game as per ex35 and I am quite enjoying myself! However I tried making a hidden room with a loop that will only allow you to enter with a word trigger… but it just doesn’t seem to work. Been scratching my head over it for the last few days, and it ignores the three elifs that have the hiddenroom variable inside of it. but will deal with the other if statements. IT’s like they don’t exist!
Anyone else can help? The particular issues are between line 57 and 68. Well that entire function really.
I am unsure if you want to have the person input “north hiddenroom” or just “hiddenroom”. However, the problem maybe that user input is a string ‘hiddenroom’ is not a boolean which Choice is trying to test for. Hope that makes sense. Cheers tc
the ‘or’ statement requires you to be specific therefore you need to add the comparison again for each of the if elements
if choice == “East” or choice == “east”:
elif choice == “West” or choice ==“west”:
elif choice == “North” or choice ==“north” and not hiddenroom:
am I making sense ?
great forum, my first post, thanks for giving me a reason
just had a google and python supports the CASE like statement which you could use to shorten your if statements.
elif choice == “East” or choice ==“east”:
your could use .upper() function
if choice.upper() == “EAST”:
not sure if you’ve solved this, re check your code, I’m not good at debugging yet so I add print statements to check program execution, todo this I added print(“roomB”) to the code to prove which if statement was being executed, if you run the program and type ‘west’ this should prove to you the program does not get there, try it
if choice == "North" or "north":
elif choice == "West" or "west":
You can keep the hiddenroom boolean to break the while loop. Maybe make a variable that has the word you want. (variable “string”) trigger_word = “slap” (Or something like that, lol)
elif choice == trigger_word:
print("There might be a way out of here!")
hiddenroom = True // so it breaks the loop
hiddenroom = True
return hiddenroom # so that it breaks the while loop