What is the right way to append data to an array from json?

Get help using Construct 2

Post » Tue Oct 06, 2015 3:02 pm

Hi,

currently i have an array which loads data from json. Apparently an event is triggerd which loads another json string (with additianal content, same array structure), but instead of replacing the whole content of the array i want to append the content at the "end" so the existing array will be extended.

the only way i can imagine to do this right now is to load the new content into a second array and then loop to through the second array appending its content to the first on.

i just would like to ask if there is a better way to do this?

kind regards
Patrick
B
19
S
7
G
1
Posts: 222
Reputation: 2,546

Post » Tue Oct 06, 2015 3:28 pm

If you don't want to code a json parser (/interpreter), this is probably the fastest solution. Just make sure instead of using stuff like push, better resize the array at start of the merge and then just set at - I think this should be more memory-efficient (not sure tho).

Other idea would be getting a json-expression out of the exisiting array and merge the two json strings correctly together and after that set the array from the single expression, but I doubt thats any faster, so no reason to do that.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Tue Oct 06, 2015 4:04 pm

Thanks @mindfaQ :)

here is my current attempt, currently not working, there must be something i am missing. the output of the appended data is always 0

Image

but i will find the solution :D
B
19
S
7
G
1
Posts: 222
Reputation: 2,546

Post » Tue Oct 06, 2015 4:08 pm

ah instead of the width ive extended the height :D

Solved :)
B
19
S
7
G
1
Posts: 222
Reputation: 2,546

Post » Tue Oct 06, 2015 5:03 pm

Image
would be a bit simpler ^^
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Wed Oct 07, 2015 9:35 am

WOW that looks efficient! thank you so much :D, i will implement it :)
B
19
S
7
G
1
Posts: 222
Reputation: 2,546


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 11 guests