How do I can understand this?

Get help using Construct 2

Post » Sun Jul 16, 2017 7:20 pm

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.

Image

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?
B
4
Posts: 19
Reputation: 232

Post » Sun Jul 16, 2017 9:34 pm

  • 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.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sun Jul 16, 2017 10:39 pm

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=)
B
4
Posts: 19
Reputation: 232


Return to How do I....?

Who is online

Users browsing this forum: Cubeeo and 22 guests