Custom loop, how to retrieve value?

For developers using the Construct 2 Javascript SDK

Post » Sun Jun 23, 2013 11:44 am

Hi, I'm trying to get a loop condition working.

I have a loop condition:

for (var ii = 0; ii < array.length; ii++) {
console.log(array[ii]);
}


Everything works as expected, now I would like to a have an expression that retrieve array[ii].

How can I achieve this with the sdk?
I searched and there is no mention of this, I tried to add a variable that gets updated each cycle and then ret.set_string(variable); but it gets just the last value.

Thanks

EDIT: change to ii otherwise parsed as italics0plus12013-06-23 11:45:28
B
30
S
9
G
6
Posts: 525
Reputation: 8,329

Post » Sun Jun 23, 2013 1:17 pm

Do you mean like the Dictionary object's 'For each key'? (It just iterates an object's properties rather than an array, but the code would be very similar, and has an expression to get the current key.) Check the source code to see how Dictionary does it.
Scirra Founder
B
402
S
238
G
89
Posts: 24,631
Reputation: 196,029

Post » Sun Jun 23, 2013 2:20 pm

@Ashley oh right forgot about that one, thanks, will check it out..
B
30
S
9
G
6
Posts: 525
Reputation: 8,329


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests