Set instance variable based on another instances' variable?

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hey guys, I'm still pretty new to Construct so go easy on me. I'm wondering if it's possible to set an instance variable based on another instances' variable. For example, I have a game based on a grid of sprite blocks. At a regular interval, I would like each block be able to set its animation frame to the same frame as the instance of the block below it.

    Each block has a variable for its ColumnNumber and RowNumber. From this, I have set a variable for its name. (Which is ColumnNumber & "." & RowNumber). So far, each block can also determine the name of the block adjacent to it by adding or subtracting 1 from either the row or column. (So block 3.1 knows that the block below it is called 3.2). Finally, each block is also setting a variable that corresponds with the CurrentFrame of that instance.

    How can I set it up so that at, set interval, each block can reference another block by its name variable, and use the CurrentFrame variable of the referenced block to set its own NextFrame variable (Which it will use next interval to change to that animation frame)?

    I hope that makes sense!! Essentially what I am trying to is to get the animation frames to change to create the illusion of upward motion.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Your essential problem is that you are referencing objects of the same object type, so "block.Variable" may reference one or the other.

    To simplify things, I would go with something like this.

    One function is called to select the frame number of the other block. This function is called using "Function.Call", and so sets a return value.

    Only thing that isn't done in this example is the verification of existence of another block below the current one.

  • THANK YOU!! Somehow I managed to miss the ability to add functions from the objects menu and I've been tearing my hair out over this seemingly ridiculous oversight! Your logic is indeed the best way to tackle this problem, thanks again.

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