Ok wow.
So, you have to say:
global wumpus_room
BUT you can't declare it as global AND assign it at the same time.
Oh, and the kicker? You're after-the-fact declaring at as a global variable INSIDE the function you want to modify it in!
So:
I guess by "declaring" inside the function that it needs to be on the lookout for a outside-declared instance of wumpus_room that this makes it ok to alter. This does NOT AT ALL explain why I can see the initial value of the variable as defined outside of the function.
Is "global" only necessary to MODIFY a variable outside of the scope... but not read the value? Doesn't that make the concept of "scope" twisted?
EDIT: Here's the site I got from my google searching on the subject http://www.saltycrane.com/blog/2008/01/python-variable-scope-notes/
No comments:
Post a Comment