You are not setting the value back to the actual parameter and are just referencing your local variables. You have to remember that you are not actually getting a reference the custom property when setting your variable to self.view.custom, you are just copying it’s value into a new variable. To get the functionality you desire, do something like the following:
x = self.view.custom.x #Get the value currently in the property
y = x['y'] #or x.y but I like json notation
y += 1 #Increment your counter
self.view.custom.x.y = y #set the actual property to the new value
system.perspective.print(self.view.custom.x.y)
What’s troubling me is that assigning y via the x copy will increment self.view.custom.x.y, but not the x copy. As if there’s a redirection on the copy, or the copy is read-only ?
In your example you were never incrementing self.view.custom.x.y at all. You had written:
custom = self.view.custom
Which is creating a copy of the custom property object.
You then had
x = custom.x
which is now a new separate variable, independent of “custom”
When you did
x.y = x.y + 1
you now successfully incremented object y of object x. Since “custom” is still a completely separate variable, the object custom.x.y is still the original value.
In general never assign the entirety of the custom properties to a single variable inside a script since that can get confusing fast. Try to assign each custom property object to it’s own variable:
x = self.view.custom.x
then perform any operation on the object and it’s children
x.y = x.y + 1
Then update the custom property by setting the value to your object
I agree I’ll avoid it now that I know the pitfalls. It’s still a strange behavior to me, and I can’t explain to myself how the copy affects the real property but not itself.
It’s basically just a bug.
There’s a lot of smoke and mirrors happening so that these things pretend to be native Python data structures. When you rebind them, that (currently causes this weird behavior.