Here is a question I have about function scope in Python.
If I have a table data, called ‘Global’, and I want to get the value in row 1, column ‘total_amount’
I would access that as such:
total_amount = int(op(‘global’)[1, “total_amount”])
Now, if I want the value of that to be a variable, that I can access inside the “offToOn” function, (in a chop Execute DAT for instance), this is how I have been doing it:
[code]total_amount = int(op(‘global’)[1, “total_amount”])
def offToOn(channel, sampleIndex, val, prev):
global total_amount
print(total_amount)[/code]
This will print the total amount (i.e. the amount in the table). However, if, in the same function I add
total_amount = 5
That number does not get added to the table. Why is? It seems like once I declare the global total_amount, it should reference the (op(‘global’)[1, “total_amount”]) path instead of just its value. Am I wrong here? And, if I do set, in the offToOn function, the value of “global total_amount” to 5, I am assuming that next time the function is called, the value of “total=_amount” will be reset to whatever the table value is, right?
After typing that out I am realizing it should just be Python storage FTW.