Feature Request: Trigger: On variable value change

Discussion and feedback on Construct 2

Post » Sat Apr 13, 2013 4:13 pm

I'm sure there a work-around for what I have in mind, but is it possible to add a trigger that checks for the moment the value of a variable changes?

For instance, in my stealth game, I may have my enemy chasing me. I have a variable that states "Is enemy chasing player?" - True.
But there are times before and after where both are False. I want to test the moment the pursuit is lost.

The reason in my example is because before pursuit, the chase condition is false, but I don't want the follow-up actions to take place BEFORE the chase has even started. I need a test that says THE MOMENT WHEN the value changes and pursuit has been lost.

Does this seem like a viable option to add? Thanks. :)Rhindon2013-04-13 17:19:09
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
112
S
20
G
8
Posts: 741
Reputation: 13,636

Post » Sat Apr 13, 2013 7:00 pm

+1
B
45
S
19
G
10
Posts: 562
Reputation: 9,543

Post » Sat Apr 13, 2013 7:14 pm

We probably won't add this. The performance overhead of running a trigger is fairly small, but variables are used and changed so much in projects I'm sure a feature like this would drag down performance. And the workaround is simple: either use a static local variable, e.g.

[Static local number OldValue = 0]
+ Myvalue != OldValue
-> Set OldValue to MyValue
-> Do something else

Or instead of setting the variable directly, call a function, which does additional work as well as setting the variable.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sat Apr 13, 2013 7:22 pm

@Jase00 - :) Thanks for the vote!
@Ashley - I suppose I can see that (barely, as I don't have the programming expertise like you do...but I understand).
The work-around, though, I think will fit what I have in mind perfectly. I know of the !=...er, whatever you call that instruction (I can't remember), but I'm not used to using it. Thank you. :)
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
112
S
20
G
8
Posts: 741
Reputation: 13,636

Post » Sat Apr 13, 2013 7:32 pm

[QUOTE=Rhindon] @Jase00 - :) Thanks for the vote![/QUOTE]
Sure thing!

[QUOTE=Ashley] We probably won't add this. The performance overhead of running a trigger is fairly small, but variables are used and changed so much in projects I'm sure a feature like this would drag down performance. And the workaround is simple: either use a static local variable, e.g.

[Static local number OldValue = 0]
+ Myvalue != OldValue
-> Set OldValue to MyValue
-> Do something else

Or instead of setting the variable directly, call a function, which does additional work as well as setting the variable.[/QUOTE]
Ah I see, I thought it would boost performance in some places but yeah it would bog down the performance since variables change all the time. The more you know!
B
45
S
19
G
10
Posts: 562
Reputation: 9,543

Post » Tue Dec 10, 2013 8:28 pm

just in case there's anyone still interested.

On instance variable change plugin
B
3
Posts: 8
Reputation: 241


Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 15 guests