How do I get values from .json array in a loop?

1 favourites
  • 6 posts
From the Asset Store
"Epic Clash of Destiny" Dramatic Battle Music Loop Asset
  • I am trying to set the string 'State' of every 'Tile' to each corresponding Value in the Path ".tileStates", but it seems to set every 'State' to the last Value in the Path. What do I do wrong? (I am new to JSON and Loops, so might be a stupid question)

    The final product looks like this;

    But should look like this;

    Tagged:

  • Can you show the rest of the code as well? I mean the part that cycles the entire grid to insert the respective values from the JSON file?

  • From what I can see, you're not making the pick of a given object instance to assign it the color. Basically in the for loop of each assignment you assign the same color to all blocks each time.

    The last color in your JSON is white, so at the end of the loop you will have all your blocks white.

    If you add a brakepoint to your loop, and in debug mode, proceed tick by tick manually, you'll see what happens during the loop.

    I recommend creating the block and assigning it the color in the same event, or else make the correct block pick when you assign it the color.

  • OM#%¤%G I am stupid. I just realised I made it way more complicated, than I had to. I ended up with this simple line of code. Thank you Biscotto for "spelling it out" for me. Good day to you sir.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Happy to have helped you!

    Be careful when using the IID of an instance. If for some reason you destroy one, and then create another in the usual location, your colors will no longer be ordered as they are in the JSON file. ;)

    Happy programming!

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