0

I'm creating a text-based game that requires you to search two places to move forward in the game, but it also has two dummy options to lead you astray. These are not important. The problem is that once the method is called again after heading down one of the 'if' options, and one of the variables is set to true, it sets it back to false at the very top.

def marketplace():
    searchArmorer=False
    searchBlacksmith=False
    while (searchArmorer==False and searchBlacksmith==False):
        print("Search the:")
        search=input("\n A. The blacksmith \n B. Crocodile Shop \n C. Armorer \n D. Exotic Cheese shop \n")
            if search=="A":
            searchBlacksmith=True
            print("You find some dusty looking copper swords in the corner that the blacksmith says you can borrow. If you haven't got it already, now all you need is some armor. \n")
            marketplace()
        elif search=="B":
            croc=input("You open the door to have a crocodile leap out at you! Will you attempt to fight it, or run away? \n A. Fight \n B. Flee \n")
            #croc fight
            if croc=="A":
                print("You have died. Crocodiles are dangerous.")
                break
            elif croc=="B":
                print("You escape back to the village square. \n")
                marketplace()
            #end of croc fight
        elif search=="C":
            searchArmorer=True
            print("You ask if the armorer has any cheap armor, but he says the cheapest he has is leather. It's not your first choice, but beggars can't be choosers. \n")
            marketplace()
        elif search=="D":
            print("You see nothing that could help you on your quest. \n")
        marketplace()
Juan Leni
  • 6,982
  • 5
  • 55
  • 87
  • 3
    Don't recall `marketplace()`. Instead, use `continue`. You aren't taking advantage of your loop. – zondo Mar 01 '16 at 19:05

1 Answers1

1

"While" loop will execute again and again until the condition is false, so you don't need to call the function again from within the loop.

Delete or comment out all calls to marketplace(), and it will work fine.

Also you don't need to use continue either if you are using an if - elif, because it will execute only one of the sentences.

Tadhg McDonald-Jensen
  • 20,699
  • 5
  • 35
  • 59
Pedro
  • 21
  • 4
  • I have to call it twice, once down the armorer path, and once down the blacksmith path. Once it's restarted however, it resets both because I have to initiate the variables. I'm looking for a work-around. – user3362503 Mar 02 '16 at 18:46