How do I arrays over 9?

Get help using Construct 2

Post » Tue Apr 18, 2017 2:47 pm

I want to be able to read 22 words out of a text file to set as variables to use in a card game.

I have a set up that allows me to take a string that I have saved out to a text file (of 22 words) and separate them.

is there a way to have a similar set up with and array and AJAX but store more than 9 things?

Thanks,
All advice appreciated.
B
5
S
1
Posts: 65
Reputation: 507

Post » Tue Apr 18, 2017 4:31 pm

You can store array items in a json file (just rename with *.json instead of *.txt) in the following format:

{
"c2array":true,
"size":[5,6,1],
"data":
[
[[0],[1],[0],[-1],[-1], [0.5]],
[[1],[0],[1],[0],[-1], [0.5]],
[[0],[3],[1],[3],[-1], [0.5]],
[[1],[3],[0],[3],[-1], [0.5]],
[[2],[3],[2],[3],[-1], [0.5]],
]
}

You can make the data items what ever you want, of course.

You can make the array as big as you like and even turn it into a 3D array by adding extra items within the inner square brackets, just make sure to adjust the size values at the top.

Import the file into the files folder for your project on the "Project" tab.

Add an array object to your game (e.g. yourArrayObject)
Add the AJAX object.

System|On start of layout: AJAX| Request (your json).json (tag "your tag")
AJAX | On "your tag" completed: yourArrayObject|Load from JSON string AJAX.LastData

This will grab your json array and add it to the array object - I don't think you have to stipulate the size of your array object - it should automatically fill up from the json - but it probably doesn't hurt to set the dimensions the same.

Hope that makes sense! :)
B
16
S
7
G
3
Posts: 395
Reputation: 3,693

Post » Wed Apr 19, 2017 11:17 am

mekonbekon wrote:You can store array items in a json file (just rename with *.json instead of *.txt) in the following format:

{
"c2array":true,
"size":[5,6,1],
"data":
[
[[0],[1],[0],[-1],[-1], [0.5]],
[[1],[0],[1],[0],[-1], [0.5]],
[[0],[3],[1],[3],[-1], [0.5]],
[[1],[3],[0],[3],[-1], [0.5]],
[[2],[3],[2],[3],[-1], [0.5]],
]
}

You can make the data items what ever you want, of course.

You can make the array as big as you like and even turn it into a 3D array by adding extra items within the inner square brackets, just make sure to adjust the size values at the top.

Import the file into the files folder for your project on the "Project" tab.

Add an array object to your game (e.g. yourArrayObject)
Add the AJAX object.

System|On start of layout: AJAX| Request (your json).json (tag "your tag")
AJAX | On "your tag" completed: yourArrayObject|Load from JSON string AJAX.LastData

This will grab your json array and add it to the array object - I don't think you have to stipulate the size of your array object - it should automatically fill up from the json - but it probably doesn't hurt to set the dimensions the same.

Hope that makes sense! :)


Thanks, this is great advice for anyone looking to use Arrays to do things like level editors and RNG based card games. Thanks a lot. (although i didn't need to use this as i realised i didn't need an array to do what i wanted and could just load in the things I wanted and use them as they are using AJAX.)
B
5
S
1
Posts: 65
Reputation: 507


Return to How do I....?

Who is online

Users browsing this forum: stevenode, Yahoo [Bot] and 11 guests