I would like some actions to run every time a certain global variable is modified in my code, but I can't find the way to do that it in the editor. Does a condition like
"On Variable value change"
exist in Construct 2?
I can imagine creating another global variable, checking if the first variable is different from the second, then copying the first variable's value to the second at the end of my event sheet, but it seems quite complex for such an easy thing.
Instead of doing it like this, can't you just make a function that you call every time you change it in the code. For instant if you need something to happen depending on its value:
Set Global_var = 1
Function.call("Global var changed")
Function "Global Var Changed"
---> If Global_var = 1 <Do something>
---> If Global_var = 2 <Do something>
Then you don't have to constantly check it, because you know you only call the function if a change takes place.
You can do that with functions as nimos100 described. Or even a bit different - I would split that into two functions "setMyGlobal" (where you change value of your global) and "someActions". Second one should be invoked by the first one, and all logic other than setting a global variable value I would put to this second function. I find it more organized/semantic, but it obviously depends on what actions you need to do .
But if you need to invoke it in the "observer" way, then each observer should have it's own trigger. So the trick with variables solves the issue then.
Develop games in your browser. Powerful, performant & highly capable.
Your solution works perfectly and is easier than mine. Thanks a lot!
I conclude that the condition "on value changed" simply doesn't exist, but as you stated, calling a function when modifying the value is probably more efficient.
Thanks for giving further informations. In this case I'll use nimos' solution (which is already implemented and working) but will definitely keep yours in mind for the next time.