Pick a variable name based on loopindex?

Get help using Construct 2

Post » Thu Jan 26, 2017 2:45 pm

So, if I have some variables that are named with different numbers (Height1, Height2, Height3, etc) how do I pick these with a loop index, for instance:

For each instance
Set variable Height'loopindex'

where the variables are each picked based on they're loopindex, because it now correlates to the same name?
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,282


Post » Thu Jan 26, 2017 3:01 pm

You can't "build' variable names. You can use an Array or Dictionary to do what you want.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704

Post » Thu Jan 26, 2017 6:23 pm

Okay, so let's say I've got these variables:

XPoint1
YPoint1
XPoint2
YPoint2
XPoint3
YPoint3
XPoint4
YPoint4
XPoint5
YPoint5

And I've got 5 behaviours that, currently, I have grouped into five different sets of events that, depending on the behavior, checks a system expression against it's relative number (behavior #1 checks for an overlapping point and stores it at XPoint1 and YPoint1, behavior #2 checks for an overlapping point and stores it at XPoint2 and YPoint2, etc). The five behaviors are familied. How do I efficiently, run a "for each "family"" call the relevant pair of variables that correspond to the behavior number in the family, or should I say, the loopnumber of the behavior?
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,282

Post » Thu Jan 26, 2017 6:41 pm

Have you used arrays before? I just want to know how much detail to provide.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704

Post » Thu Jan 26, 2017 6:46 pm

blackhornet wrote:Have you used arrays before? I just want to know how much detail to provide.

Yes, extensively, one of the few things I have somewhat of an understanding of :D
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,282

Post » Thu Jan 26, 2017 7:11 pm

Yes, extensively then that should be very easy for you
B
257
S
43
G
15
Posts: 1,992
Reputation: 41,535

Post » Thu Jan 26, 2017 7:17 pm

Actually as I started writing, I came up with more questions, since I don't know your details.
If each behaviour is in a Family and sets it's own specific variables, why aren't those variables on the family? Then there should be no need to index them.
If that doesn't work, then getting back the the array idea, if you just have the single base object, then you can create a 5x2 array and use a container to connect the array to each instance. If there is more than one base object (grouped by families again) then you'd have to create the array object, store it's UID, and pick that array, by UID, when needed. This is obviously the most cumbersome mechanism.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704

Post » Thu Jan 26, 2017 8:13 pm

Can container up Arrays with Sprites. Works awesome, feels like there is only 1 array around when coding.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jan 28, 2017 1:11 pm

blackhornet wrote:Actually as I started writing, I came up with more questions, since I don't know your details.
If each behaviour is in a Family and sets it's own specific variables, why aren't those variables on the family? Then there should be no need to index them.
If that doesn't work, then getting back the the array idea, if you just have the single base object, then you can create a 5x2 array and use a container to connect the array to each instance. If there is more than one base object (grouped by families again) then you'd have to create the array object, store it's UID, and pick that array, by UID, when needed. This is obviously the most cumbersome mechanism.

Excellent, now I don't have a massive experience with loops, so bear with me, do I call each of the behaviors with a "for each" and if so, I can't use loopindex, so what's the proper way of calling these different instances of the behavior?

Just wanted to clarify, I think I've got my wording of behavior a bit wrong, I meant object/plugin :oops: Same thing, really though.
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,282

Next

Return to How do I....?

Who is online

Users browsing this forum: Julot135 and 25 guests