How do I populate a 2d array from json?

0 favourites
  • 3 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • Hi, Happy New Year.

    I am new to Construct 3 and am using it to build a puzzle game. The format of the game is a 3x3 grid of buttons which each have a pattern of spots on them. I need to get the board layout into a 2d array from a json file.

    So the json looks like this.

    {"1":{"layout": [[0,1],[1,3,4,7],[2],[2,3,6],[4,8],[1,3,5,8],[6],[4,5,7],[3,8]],...},

    "2":{"layout": [[0,3,4],[1,5,7],[1,2],[3],[3,4],[2,5,6,7],[2,3,6],[0,7],[4,8]],...},


    In the json, the layout takes the format of a nested list of 9 elements, one for each button. The nested values (of which there is a maximum of 4 in each element) denote the pattern on each button.

    Say that board number 1 is selected from the directory and the value is assigned to a variable called 'boardNum'. How do I assign the layout to a 9x4 array? E.g. layoutArray = boardnum.layout

    One thing I suspect is not ideal is having the nested list in square brackets. I created the json directory in Python and made the layout as a Python list. I can easily change this format if required.

    Thanks in advance for any help you can provide.



  • Check out the official template, it shows how to parse and and extract data from JSON.

    I also have an example which shows full path to every value in the JSON:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you very much!

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