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

Get help using Construct 2

Post » Tue Oct 03, 2017 7:03 pm

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.
B
13
S
2
G
1
Posts: 50
Reputation: 1,233

Post » Wed Oct 04, 2017 3:27 am

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.
Check out my awesome game Doptrix
B
17
S
9
G
51
Posts: 839
Reputation: 28,487

Post » Wed Oct 04, 2017 8:48 pm

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!
B
13
S
2
G
1
Posts: 50
Reputation: 1,233


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests