I am trying to create a script that sets a local variable, references it from a function, and can return the manipulated value back to the main scope (or whatever it's called; I'm new to Python)
I have simplified my code to show the utmost basics of what I am trying to accomplish, which is to import a local from the module into a function block, I think.
I have gotten this to work by using globals
, but that isn't the best solution . . .
chambersinreactor = 0;
cardsdiscarded = 0;
def find_chamber_discard():
"""Find chambers and discard in row (reads each player slot)"""
chambersinreactor = 0; # Resets the variable, not what I want
cardsdiscarded = 0; # Resets the variable, not what I want
chambersinreactor += 1
cardsdiscarded += 1
return # Don't know what to put here
find_chamber_discard()
print chambersinreactor # prints as 0, should be 1
print cardsdiscarded # prints as 0, should be 1
chambersinreactor
and ` cardsdiscarded` ARE global variables. They're defined outside of the local scope. – Joel Cornett May 11 '12 at 3:41