0 Favourites

How do I add a variable to a Instance only once?

  • Hi!

    I'm having a big problem here, mabey someone can help me:

    I want to add a number to an instance variable but only once, so here's what I mean.

    For example: Player is overlapping "Tree" -> subtract 50 from the Player's Instance Variable called "InView"

    and when he is not under a "Tree" he will lose the Bonus of -50 "InView"

    So what I'm trying to do is, giving the Player a Bonus of -50 on "InView" which will make him more difficult to find by the enemies. So "InView" stays for the visibility of the player.

    Now my Problem is, that as long as the Player is overlapping the "Tree" construct2 is subtracting -50 constantly in place of just once every time he walks over.

    I tried it with "Trigger once" but that only works for one time, so when the Player moves out of the "Tree" and after a while walks back in, he won't get -50 from "InView" again.

    And I tried something with the Behavior Timer but i can't figure out how it really works.

    Can somebody help me with this?

    Thanks

  • Why not use an 'on collision' event instead?

  • 'Trigger Once' is the way to go... regardless of your values you don't want to keep executing the same code over and over while the player is just standing there behind the tree you only want to set it once.

    Use a boolean and make the player's 'state' to 'isHiding' and you can check that variable.

  • Ok, well that's a simple and nice tip. This should work fine for me.

    @codah: the collision doesn't worked properly. The Player is not getting back the -50 if he's walking out of the Object:"Tree" again. anyway I'm going to try it with the boolean.

    Thank you guys!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Oh right. Sometimes I store the previous value of a variable and compare the current value against the previous value (with a trigger once). That works as well because it keeps triggering as the value changes back and forth. Many ways to do it, but sounds like you've got it sorted.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
220 14,876
Tom's avatar
Tom Construct Team Founder
Unread hot topic
99 10,126
karshinkoff's avatar
karshinkoff
Unread hot topic
0 Favourites
[Plugin] instance bank2
85 18,366
rexrainbow's avatar
rexrainbow