How do i use arrays?

Get help using Construct 2

Post » Sat Jun 21, 2014 1:29 am

Really the trick for loop is cleaver. Nice to learn about tokencount and tokenat.
B
15
S
2
Posts: 5
Reputation: 984

Post » Mon May 15, 2017 3:53 pm

Hod do I load a JSON (or XML/CSV) file's data into an array? I inserted an array object and gave it dimensions of 21,1000,1 - my JSON file has 21 columns and 1001 rows - with 1 row header. Do I need a For Loop to read each object pair in JSON and set it to an x,y,z in the Array? Or can I just cut and paste the entire JSON string into the JSON load field? Or do I load it as a file? Manual doesn't really help. thanks in advance
B
4
Posts: 2
Reputation: 204

Post » Mon May 15, 2017 7:49 pm

@RealMagisterLudi

I use this for loading json files to arrays:

Add the AJAX object to your project.
Create yourArray object.
Add your.json file to your project files.

1) System| On (trigger): AJAX| Request your.json file (tag "your")

2) AJAX| On "your" completed: yourArray| Load from JSON string AJAXLastData

Make sure your json file is formatted like so for a 3D array:

{
"c2array":true,
"size":[2,3,4],
"data":[

[
[,,,],
[,,,],
[,,,]
],

[
[,,,],
[,,,],
[,,,]
]
]
}
Last edited by mekonbekon on Wed May 17, 2017 9:12 am, edited 1 time in total.
B
22
S
9
G
4
Posts: 480
Reputation: 4,342

Post » Wed May 17, 2017 3:32 am

Thanks - I'll try that tonight
B
4
Posts: 2
Reputation: 204

Post » Sat Oct 28, 2017 11:38 am

I have been trying to do this too, I have read every forum post I can find on the topic but can't get it to work. I have used exactly the process outlined here, but whatever I do, nothing shows up in my array. When I run debug, it shows all the values in the array as zero.
B
5
S
2
Posts: 6
Reputation: 437

Post » Sat Oct 28, 2017 11:43 am

@Eskrose, there are 4 pages in this post. Which comment are you referring to? What exactly are you trying to do?
Please also share your capx or a screenshot of your code.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
100
Posts: 1,429
Reputation: 53,925

Post » Sun Oct 29, 2017 4:02 am

Message: Eskrose can only post plain text URLS until they have 500 rep. 2 URLS modified. Why?
Wow, thanks for such a quick reply, wasn't expecting that on a months old post! I meant the process for importing a json to an array using ajax, as described by meconbecon just above.
CODE: https://www.dropbox.com/s/3nzb63xn3d1hk7e/partsofspeech%20events.PNG?dl=0
DEBUG REPORT: https://www.dropbox.com/s/jwzbx2s7jgma6vk/partsofspeech%20debug.PNG?dl=0
B
5
S
2
Posts: 6
Reputation: 437

Post » Sun Oct 29, 2017 4:32 am

@Eskrose
There may be errors in your .json file
Could you share the project?
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
100
Posts: 1,429
Reputation: 53,925

Post » Sun Oct 29, 2017 6:05 am

Message: Eskrose can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Yes, I thought the error might be in the json itself. Thanks.
https://www.dropbox.com/s/b43fn9r9o792z ... .capx?dl=0
B
5
S
2
Posts: 6
Reputation: 437

Post » Sun Oct 29, 2017 6:08 am

Your link is broken, try posting it without the "https://" part
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
100
Posts: 1,429
Reputation: 53,925

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: midward, RetroInsight and 46 guests