How do I loop through one object in a family of arrays?

Not favoritedFavorited Favorited 0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello community! I have a question regarding a family of arrays. Let me explain what I am trying to archieve: I have 3 arrays with different data but in the same format. I want to make a function that loops through one of the 3 arrays and reads data from there. To make the function flexible, I created a family for the 3 arrays with each of them having an instance variable called "ArrayName". I pass this information as an argument for the function and pick the array from within the family that matches this argument. This all seems to work fine until the for-loop starts.

    The entry condition for the loop are "for each X element" and "ArrayName" = passed name argument from function (even though the picking of the right arrays was done before). Now when it enters the loop, it seems to proceed through *all* of the arrays producing the wrong amount of Xs and therefore the function itself repeats kind of "empty procedures" for the Xs that dont match the criteria.

    Is this intended or am I doing it wrong? Do you have other suggestions on how to fix this issue? Thank you for your help, Fabuc

  • Can you post a screen shot of your events? It's really hard to tell what you're doing wrong without seeing what you're actually doing.

  • The entry condition for the loop are "for each X element" and "ArrayName" = passed name argument from function

    ArrayName check should be the first condition!

    Did you set the ArrayName value correctly for each array? You can check this in the Debug Mode.

    Since every array object has only one instance, you don't really need the instance variable. You can just pick by array UID:

  • Thank you for your replies. I found a solution for the issue: If the array is picked before the "for each X" loop begins, the loop will run through all the arrays in the family. What I do now is as follows:

    - I pick the array with the associated instance variable to pick the right one from the family

    - Instead of looping with "for each X", I use "repeat ArrayWidth times"

    - First step after entering the loop is picking the array again

    - The events that follow will only apply to the picked array as originally intended

    This may help you if you have the same issue. From what I've learnt the picking algorithms vary depening what you do in you function and if you use "for each" loops.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • From what I've learnt the picking algorithms vary depening what you do in you function and if you use "for each" loops.

    I don't think that's true. As I wrote in my previous comment - picking the array instance should be the first condition!

    Pick, then loop through the array. It doesn't matter if you use "for each X" or a system "for" loop. And you don't need to pick the array again inside the loop.

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