[Tutor] Umm.. I need help on changing Global Variables.
davea at davea.name
Sat Jan 31 23:34:49 CET 2015
On 01/29/2015 12:16 PM, Tallen Grey Smith wrote:
> So, I’m trying to make a very simple game that involves time management properly, but I’m having an issue.
> thats my code, and I want it to where if I type charge it’ll make my charge go up 10, my steps go down 1, my divs going down
1, and it to go to
Python (like any modern procedural language) does not have a goto
command. You're calling the other function, which means that eventually
the other function will return back to game(). That's probably a big
mistake, but it won't matter for the moment.
> my charge_1 function, which should do the same thing but with a tweaked dialog box
I don't see any dialog boxes in that code.
> But no matter how hard i try, once it gets to the charge_1, it always says
> that the variables that I changed where referenced in previous functions and it can’t pull them.
Don't paraphrase the effect. Show just what got displayed. I've never
seen an exception called "it can't pull them"
> How can I change this to get a variable that when changed in my If statement, would be useable in other functions?
Use of global variables is thoroughly discouraged. I'd suggest making a
Game class, and making all these "variables" attributes of an instance
of Game. Then you just pass that instance around between the various
functions, as a formal parameter.
More information about the Tutor