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

0 favourites
  • 5 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • 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?


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

  • Try Construct 3

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

    Try 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)