The problem breaks down to this. In my text based game, before you can enter the training grounds, you must give the hungry guard the bread from your inventory. As of now, that works. The inventory updates to show the bread is no longer in the inventory. Along with removing the bread from the inventory, it gets removed from the dictionary called rooms.
Everything works except for when you re-enter the training grounds later, It then asks you for the bread again, which no longer exists.
My question is how would I write a while, if, elif, etc statement like:
if "Bread" not in rooms["Kitchen"]["Item"]:
continue
or something like that, so that you can re enter the room without it asking for the bread at a later point. I've only been coding for a few weeks so I know my code is probably garbage but I'm using this project to learn. The issue I face is the code needs to not allow you in if you don't have the bread for the guard, allow you to give the guard the bread for access, and then act like a regular room after you have given the guard the bread, leave, and then return to that room later.
here is the section of code.
if current_room == "Training Grounds" and "Bread" not in Inventory:
print("A hungry guard blocks your path and shoves you back into the Great Hall.")
current_room = "Great Hall"
continue
if current_room == "Training Grounds" and "Bread" in Inventory:
player_move = input("Would you like to offer the guard bread in exchange for access to the Training Grounds? ")
if player_move == "yes".capitalize():
current_room = "Training Grounds"
print("The guard lets you enter the Training Grounds.")
Inventory.remove("Bread")
del rooms["Kitchen"]["Item"]
continue
elif player_move == "no".capitalize():
print('"Get the hell out of here!"')
print("The guard shoves you back into the Great Hall.")
current_room = "Great Hall"
continue
I'm assuming somewhere in here is where I need the line to check for that, and allow you to enter the room. Or maybe my approach is off entirely. Any help is greatly appreciated.
I tried all sorts of variations of that solution. Wording it different ways, even tried using things like first_time_in_room = True
however, I don't really know how those work entirely.