Feb-07-2018, 09:32 PM
(Feb-07-2018, 08:39 PM)Harveyyy Wrote:def q2a(): q2a=input("You walk to the chest. You find that the chest is empty, but the skeleton has a sword and an axe but you can only hold one.\nDo you want to take the sword(1)?, or the axe(2)") if q2a == "1": sword = True print("Sword was taken") q2b() if q2a == "2": axe = True print("Axe was taken") q2b()
In this function, you create two new variables, sword and axe, which happen to have the same name as variables in the global scope. This is called "shadowing". https://en.wikipedia.org/wiki/Variable_shadowing
You can fix that in one of two ways:
1) Restructure your program to avoid using globals. This is the better option, but would involve rewriting everything.
2) Add the line
global sword, axe
to the top of the function, to hint to python that you're referring to those variables in a different scope.