How do I can understand this?

0 favourites
  • 3 posts
  • pretty stupid question probably, but please help me to figure it out.

    here is an image about how to get random text from txt file via ajax.

    i actualy understand most of it except "loopindex-1".

    i realise that in this line (3) we put a new text from last ajax date which is separeted by new line, but i cant undestand second part of the code (loopindex-1). according to the manual there should be like a number of token, but here we get it randomly as i see.

    so how does it work, this loopindex-1?

    • The For condition repeats as many times as there are tokens.
    • An Array's Push back on X axis action basically "inserts" a new row of items into the Array.
    • tokenat(ajax.lastdata,loopindex-1,newline) is what is inserted into that new row. Where "ajax.lastdata" = The data string from which the token is extracted "loopindex-1" = The index of the token. This needs to be there to determine which of all the tokens should be used. An index of 0 would use the first token, an index of "tokencount(ajax.lastdata,newline)-1" would return the last token. The expression "loopindex" basically represents a dynamic variable that starts at 1 ("For 1...") and increases by 1, for every loop iteration. It has to be "loopindex-1 because the index for "tokenat(...)" starts at 1, while the "For" condition starts at 0. "newline" = the separator that determines which string separates the tokens.

    I hope this is not too confusing.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • oh, that was a bit confusing a few minutes i was thinking about ur words. gladly i finaly got it, my thoughts about random were wrong, random is in the 4th line not 3th as i said. loopindex just a place in array (0,1,2...), but my "for" starts from 1, so when FOR=1 i have a place in array under 0, when for=2 array has 1, thats why i have to subtract 1, therefore loopindex-1.

    probably my explanation of my understanding is a bit wrong, but for me my question is answered, thank you so much=)

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