0 Favourites

How do I can understand this?

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

  • Construct 3

    Buy Construct 3

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

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

  • 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)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
Understanding subscription
96 4,814
ruskul's avatar
ruskul
Unread hot topic
99 10,153
karshinkoff's avatar
karshinkoff
Unread hot topic
56 4,736
MPPlantOfficial's avatar
MPPlantOfficial