Page 1 of 1

Action on variable change

PostPosted: Wed Jul 20, 2016 2:56 am
by plbrunet
Hi everyone.

Is there a way to execute a script every time a variable changes? Like an action script but for variables?

Thank you.

Re: Action on variable change

PostPosted: Wed Jul 20, 2016 7:46 am
by Christian Hinxlage
Hi Pierre-Luc,

Please find a small project attached.
Something like that?

Regards

Christian

Re: Action on variable change

PostPosted: Wed Jul 20, 2016 9:18 pm
by plbrunet
Hi Christian,

That's interesting. I would have to play with the delay to see if it can handle faster changes.
I suppose there is not a more direct way of going about it.

Thank you.

Re: Action on variable change

PostPosted: Fri Jul 22, 2016 11:56 am
by Dennis Kuypers
Hi,

there are a couple of tricks you can do. For integers you can build a construct of

Nodes: Variable->Delay->Script

In the script you check if variable does not equal delay. Then it will trigger once per change. If the variable is constantly chaning and never rests on one value then your script will only trigger once, tough. Alternatively you can use a Delta node and check if the Delta != 0.

For text variables you can have a shadow variable that is updated by your script, so for example:
Code: Select all
(a node checks for:) if myvar != _myvar
{
' somthing has changed
' do stuff...
' and set shadow variable
_myvar = myvar
}


Dennis

Re: Action on variable change

PostPosted: Fri Jul 29, 2016 4:32 pm
by plbrunet
Great,

A colleague of mine also pointed out the trick of putting a variable into a label and using Action Script node to trigger script on label changes.

Thank you guys for those options.