I don't know how much do you know about programming, but I'll try to explain it as simple as possible.
It's all about scope. Think of scope as a box with all the things you can use. When in the main scope, that one where you define characters, screens and other variables, you can access everything you declared.
A function have its own scope. So inside the main scope, you can work and access all the variables and functions declared, but inside the function, you can only access variables declared inside the function itself
(actually, if it's a true global variable, you can access but not modify it inside the function - but you don't actually need to know this). It's like a box in a box. When in the second box, you can only work with what's inside the second box.
There's a way of saying to Python "hey, I wanna work with that variable outside of my scope", so you can alter the global value of the variable inside the function.
Code: Select all
default bob = True
def make_bob_false():
# If you don't do this, you will create a whole new variable called bob inside the function scope, and you throw it away when the function returns.
# This way, you're telling Python that you want to alter the value of the already created bob.
global bob
bob = False
EDIT:
You could also do this...
This way, you're working with a different bob inside the function, but in the end, the value returned is assigned to the original bob in the main scope.
Code: Select all
default bob = True
def make_bob_false(bob_inside_scope):
# do something with bob_inside_scope
if bob_inside_scope != False:
bob_inside_scope = False
return bob_inside_scope
bob = make_bob_false(bob)