Feature Request: Trigger: On variable value change

  • 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. :)

  • +1

  • 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.

  • 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. :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Jase00 - :) Thanks for the vote!

    Sure thing! <img src="smileys/smiley20.gif" border="0" align="middle" />

    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.

    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!

  • just in case there's anyone still interested.

    On instance variable change plugin

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)