How do I Get AJAX result into array

Get help using Construct 2

Post » Tue Mar 25, 2014 2:58 pm

Hi all,

I will make it short.

I have a AJAX action and get a result like: 1, 43, 492, lalala, example, 1455
Or atleast, thats what i can do. I can make the , a | or whatever thats not the problem.

All i need to know is how to get all these different results into seperate results and not in 1 sentence.
So: 1, 43, 492
Should become:
Level = 1
Experience = 43
Coins = 492

Let me know if my example is clear and any one has a solution!

Thanks in advance!
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Tue Mar 25, 2014 3:00 pm

Unfortunately Arrays in c2 are not associative.

Hence I use the HashPlugin from Rexrainbow.
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

Post » Tue Mar 25, 2014 3:43 pm

I used tokens, and it's fairly easy from there. You need a way to sort them on incoming though, so 3-4 values like that is easy: set 'level' to tokenat(ajax.lastdata,0,"|") for example.

If you have bigger strings coming in, you will need to perhaps use some loops (token count times + loop index), or token-in-token (such as: level'1|experience'43 etc., with | as one token and ' as the other).

Or, if you have all of that in an array, send the array data asJSON through ajax, then load it into an array with ajax last data. This way is harder to set up for a game in general, but easier to manage in large-scale games.

Hope that helps!
B
28
S
8
G
5
Posts: 429
Reputation: 7,007


Return to How do I....?

Who is online

Users browsing this forum: darkrealos, plinkie, Rhindon and 19 guests