how to cycle through my AJAX data list

Get help using Construct 2

Post » Tue Mar 24, 2015 11:34 am

Hello,

I have small script on server side that generates list of images that are in particular directory.
I get that list with AJAX request and mine data looks like this:

["immage1.jpg","img2.jpg","photo.jpg"] etc.

Now i trying to make my dummy sprite to load immage from my static URL + first immage name in that list, then to create second sprite to repeat action for 2nd immage and so on....
(trying to make photo album)

Now to get each name from that list one at the time?
or to input all into array and then to read it?

any ideas on how to proceed?


Thanx!!!!
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Tue Mar 24, 2015 11:46 am

Sure :)


Use, for (not for each, for)

local var TmpName

On Ajax request complete

Blank Sub Event request complete
action
set TmpName = replace(Ajax.LastData, "[", "") //remove opening bracket
set TmpName = replace(TempName, "]", "") //remove closing bracket
set TmpName = replace(TempName, '"', "") //remove double qoutes, note the use of single qoutes around the double qoute in the middle


Sub Event request complete
For "imageloop" 0 to tokencount(TmpName ",") //This counts the amount of commas, indicating each chunk with a file name
action
append text.txt tokenat(TmpName, loopindex, ",") // every loop it will fetch the next 'chunk' containing the file name. I append it to a text file here, but you can use it to any sort of action using : tokenat(TmpName, loopindex, ",")
Who dares wins
B
50
S
10
G
10
Posts: 1,728
Reputation: 12,895

Post » Tue Mar 24, 2015 2:42 pm

lennaert wrote:set TmpName = replace(TempName, '"', "") //remove double qoutes, note the use of single qoutes around the double qoute in the middle


Hi. im stuck here... C2 wont accept single quote... :(
i'w tryed this also:
"""
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Tue Mar 24, 2015 2:48 pm

Double quotes escaping in Construct is done by adding another double quotes. So the line to remove them will look like this :
Code: Select all
replace(TempName, """", "")
B
55
S
22
G
22
Posts: 881
Reputation: 16,595

Post » Tue Mar 24, 2015 3:00 pm

@Magistross
Thanks, it works!!! :)
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Tue Mar 24, 2015 4:13 pm

Magistross wrote:Double quotes escaping in Construct is done by adding another double quotes. So the line to remove them will look like this :
Code: Select all
replace(TempName, """", "")



Totally forgot about that :P thanks
Who dares wins
B
50
S
10
G
10
Posts: 1,728
Reputation: 12,895

Post » Tue Mar 24, 2015 4:16 pm

@lennaert
hello, im almost finished but i have one problem
Image
this gets me allways last immage to all created sprites... :(
how to load each image on a new sprite? (i mean same sprite but different UID)

thanx!
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Tue Mar 24, 2015 4:19 pm

That wont work ...

You need unique objects ... not instance .... updating a frame will result in all instances of that object having its frame updated.

Look into R0j0hounds Paster plugin, and create paster objects with those urls ;)
Who dares wins
B
50
S
10
G
10
Posts: 1,728
Reputation: 12,895


Return to How do I....?

Who is online

Users browsing this forum: javi1230, ninepixels and 6 guests