python - How can I change a Bool variable in one function from another? -


i'm having issues regarding bools. i'm creating a game after getting ex35 in learn python hard way.

in game there 2 functions i'm having trouble (roomone, , getfood), 1 function brings , given option pick brick of food - later use throw @ switch disable electric field around you.

i want user able throw food if has food on person... - way program set - not matter if user has food - can throw either way. i've tried return foodbrick = true or (==) in food function. has not worked out.

how can fix game can turn off switch when foodbrick on person?

your immediate problem because setting foodbrick = true, no matter user types in getfood() subroutine.

you've done bunch of work, i'll suggest @ code , see if can identify doing repeatedly, , see if can make common things subroutine.

past that, think should consider making player object (member of class) or dictionary, can add attributes player in different subroutines, , have them visible throughout. like:

player['hasfood'] = true 

or

player.has_food = true 

depending on how implement it.


Comments

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

formula - R: how to pass in a reference to the variable in glm or lm? -