Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

Arrays, for loops and multiple passages

$
0
0
First of all, this is in sugarcube.
I have a question:
Assuming I have an array,
$myArray to [0, 1, 2, 3, 4, 5]
, and I want to display this as follows:
<<for $i to 0; $i < $myArray.length; $i++>>
<<print $myArray[$i]>>
[[Pick this element|nextPassage][$foo to $myArray[$i]]]
<</for>>

Now, if you'll try this, you'll learn that this code does not work. The reason for this is that the variable $i contains the value of $myArray.length, since the for loop was concluded. That is to say, even though the following is printed:
0
Pick this element
1
Pick this element
...
5
Pick this element
No matter which element you pick, the value of $foo will always be 5.

Is there a workaround for this?

Viewing all articles
Browse latest Browse all 1844

Trending Articles