Set instance variable based on another instances' variable?

Get help using Construct 2

Post » Mon Feb 24, 2014 11:07 am

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.
B
3
Posts: 2
Reputation: 179

Post » Mon Feb 24, 2014 12:52 pm

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.
B
17
S
8
G
4
Posts: 461
Reputation: 6,157

Post » Tue Feb 25, 2014 1:46 am

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.
B
3
Posts: 2
Reputation: 179


Return to How do I....?

Who is online

Users browsing this forum: jorgmaquoi and 19 guests