Pick a variable name based on loopindex?

0 favourites
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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?

  • Zebbi you could use loop like this too

    https://www.scirra.com/tutorials/9423/i ... -variables

  • You can't "build' variable names. You can use an Array or Dictionary to do what you want.

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

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

  • 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

  • Yes, extensively then that should be very easy for you

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

  • Can container up Arrays with Sprites. Works awesome, feels like there is only 1 array around when coding.

  • 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 Same thing, really though.

  • Can you post a CAPX example? It's still not clear what you are doing/wanting.

  • Can you post a CAPX example? It's still not clear what you are doing/wanting.

    https://www.dropbox.com/s/r0erae2dpy2sh ... .capx?dl=0 I was suggested to try and use local variables instead of an array, so it's temporarily set up for that with the other ton of variables switched out, if this fails, I'll wire it up to an array instead. I also need to figure out how to pick a different instance for each loop from the families references in the actions for the debug objects.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You're going to have to tell me what I'm looking at here. There's a lot there.

  • You're going to have to tell me what I'm looking at here. There's a lot there.

    I've improved it, or so I think: https://www.dropbox.com/s/r0erae2dpy2sh ... .capx?dl=0 If you check the Trace1 group, I've got local variables that adjust according to the direction the player is aiming, and each loop for the 5 different tracers resets and reuses it. I've picked each of the debug objects (the star, end, normal (hit) and line families) based on the loop index. It seems to work okay except one tracer in wanging off to the top, maybe it's cause of the 0-index or something?

  • You're going to have to tell me what I'm looking at here. There's a lot there.

    One more edit, it was the scope I've fixed, I just reordered the tracer via a subevent: https://www.dropbox.com/s/r0erae2dpy2sh ... .capx?dl=0

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