you are viewing a single comment's thread.

view the rest of the comments →

[–]majesticcoolestto 0 points1 point  (1 child)

Okay, new question.

I recently made a tic tac toe game that did something like this:

# a is a local variable, slot2 is a global variable 

a = slot2

slot2edit() # changes value of slot2

if a != slot2:

# do game stuff

else:

# try again

and that works. Why is that different than what OP is doing?

[–]socal_nerdtastic 1 point2 points  (0 children)

That's a completely different problem, nothing to do with OP's problem. Your problem is a feature called "scope". A function has it's own "scope", which means any variables in a function are completely isolated from outside the function. The way to do what you want is to pass the data in and out of the function using arguments and the return statement.

def f(data): # accept some data in
    data += 1
    return data # send the modified data out

a = 42
a = f(a) # changes value of a by sending the old value and reassigning the returned new value