how to cycle through my AJAX data list

0 favourites
  • 8 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • 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!!!!

  • 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, ",")

  • 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:

    """

  • Double quotes escaping in Construct is done by adding another double quotes. So the line to remove them will look like this :

    replace(TempName, """", "")[/code:gapwlya6]
  • Magistross

    Thanks, it works!!!

  • Double quotes escaping in Construct is done by adding another double quotes. So the line to remove them will look like this :

    replace(TempName, """", "")[/code:16qqoisr]
    

    Totally forgot about that thanks

  • lennaert

    hello, im almost finished but i have one problem

    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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)