How do I make and then access a nested array in C2?

0 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I would like to have in Construct 2 something that looks like this in javascript:

    var testArray = [["John","Megan","Luke"],["diamond","chess"], ["so", "then", "how"]];

    Then i would like to be able to access the indexed values.

    How do i do that? I tried creating an array and then passing another array as its value but it does not work.

    Eventually i would like the solution to be compatible with JSON and local storage.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Can't you use 2D array?

    In your example it will look like this:

    [

    ["John","Megan","Luke"],["diamond","chess",""], ["so", "then", "how"]];

    You can also store strings instead of child arrays (with values separated by comma or some other symbol).

    You'll just need to parse them using tokenat()

    ["John,Megan,Luke","diamond,chess", "so,then,how"];

    Or you can store JSON-strings of child arrays in your parent array. Of course, you'll have to "Load from JSON" before accessing them.

    And finally, you can create several instances of the child array, and in the parent array store child array's UIDs. (or some other unique identifier of child array instances). However, saving and restoring all them from local storage will not be an easy task.

  • Thanks for giving me instructions to experiment with. Congratulations on your gaming success! Your game looks pleasantly sophisticated. Keep up the good work for more to come!

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