r/pythonhelp • • Jun 28 '23

Another text based game question. Hopefully my last one.

/r/learnpython/comments/14ks8ye/another_text_based_game_question_hopefully_my/
0 Upvotes

3 comments sorted by

•

u/AutoModerator Jun 28 '23

Note:

  • This sub went private for a few days recently in solidarity with other subs who are hoping to get Reddit to reconsider some changes that they have proposed. These changes will affect the Reddit API and many third-party apps that access Reddit. If you are not already aware of the proposed changes, please read up on the topic and the ongoing protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/TheComputerGuy420 Jun 29 '23

When writing games you would usually use the concept of flags so you could write something like

Guard_bribed = False

if not Guard_bribed:
    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

else:
    continue

1

u/Attack_On_Tiddys Jun 29 '23 edited Jun 30 '23

Edited: Thank you so much! I ended up learning how to do what you suggested with true/false and ended up fixing my issue!