Property Value Changing in Code

How would I use property value in python? I tried stuff like:



timer = cont.owner["timer"]


if always.positive:
     timer = 2


And it doesn’t work.

Thanks

use a event to trigger

#Get X
X = own[‘blah’]

X do something

#return X
own[‘blah’] = X

You were close. You changed a variable named ‘timer’ instead of the property ‘timer’. Also, I’m not sure why you set this condition because it makes no difference. This should work:

own = cont.owner
own['timer'] = 2

Edit: Unless you meant something different?

That was exactly what I needed. Thanks guys

No problem :slight_smile:

I think it would help if I clarified for you how assignment works in Python.

When you write “A = 1; B = A”, you assign the variable A to point to an integer object of value 1. Then you assign the variable B not to point to A itself, but to whatever A points to. So B and A are now both pointing to the same integer object. Then suppose you add “B = 5” to the script. Now you’ve set B to point to a brand new integer object, that happens to have a value of 5. However, A still points to the original integer object- the one that has a value of 1.

Now here’s where it gets tricky. Suppose you write “A = [1,2,3]; B = A”. Now A and B are pointing to the same list object that holds the values [1,2,3].
If you then wrote “B = [1,7,10]”, B now points to a brand new list, and A still points to same old list.
However, if instead of writing the above command, you wrote “B[0] = 11”, then B does not point to a new list. It still points to the old list, but you’ve changed one of the values in the list. Since A and B still point to the same list, you’ve also changed the value of A. So A and B both point to one list that contains [11,2,3]