How do I "constrain" a variable value to another?

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi, I don't know the exact word to use since I in Gamesalad it's called "constrain", but I can't find the equivalent in Construct 2.

    Basically, a variable will contain within it the same value as the one it's targetting at all times.

    I need this because there is a self.attribute in enemies that keeps track of the X, Y of their target, and a third attribute that helps switch between targets. So basically, if the target value is 0, all enemies will keep track of the X,Y of the player, if the target value is 1, then it will keep track of the X,Y value of a different target, and so on.

    Right now I'm using "every X seconds" and alternatively, every tick, but I would prefer something that just "constrains" the values?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Every tick -> set value

    That's how you do it in C2.

    Alternatively, just use a blank condition (which is exactly the same thing as "every tick" just without having any visibly written condition)

    ~Sol

  • Your program is doing a lot of things every tick so don't be too scared to use it. I did the same thing because it sounds like it would be a costly condition to use, but just think about the things you use this method for because often there is a way around it. For instance a Life Bar could checked 60 times a second or you could just change it when the player is damaged. Other things like the player facing the mouse cursor won't be able to avoid being looked at every tick.

  • Ok, thank you, for some reason, every tick didn't work for attributes within an object, since there where 30 objects to check, but going the "every x" route worked. It might have been that I had something wrong, but I will just go with this.

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