PDA

View Full Version : onValueChanged()



Blackfoot
August 13th, 2018, 15:50
The onValueChanged() function is called when a value is changed... getValue() returns the new value of the variable... is there a way to determine what the previous value of the variable was before it was changed?

Bidmaron
August 13th, 2018, 17:54
When I need value recovery, I save it in a script local variable initialized in onInit and updated once the change is committed in onValueChanged (or revert to pervious cached value if necessary but be sure and set a flag to prevent event recursion if you restore previous value)

Blackfoot
August 13th, 2018, 19:06
I can try that.. so the answer to my query is.. once you've arrived at the 'onValueChanged()' function.. the original value is 'gone'?

Moon Wizard
August 13th, 2018, 20:12
Yes, that's correct. The "onValueChanged" event is fired after the value is changed.

As Bidmaron suggested, when I need to remember the "current" value, I store in a local script variable that gets initialized in "onInit", and updated in "onValueChanged".

Regards,
JPG

Bidmaron
August 13th, 2018, 21:26
Wow. Had forgotten about the tic tac toe sequence.