0 votes
by (120 points)

Hello everyone,

I am new to SugarCube and i've been struggling with the following problem. 

I have a array (myArray) that contains several elements. I try to set a variable through the link setter before moving to next passage as follows:

<<set $myArray to [{prop:"A"}, {prop:"B"}, {prop:"C"}]>> 

<<for _i to 0; _i lt $myArray.length; _i++>>
	Get [[nextPassage][$myVariable to $myArray[_i]]]

The problem is that $myArray[_i] is not affected to myVariable. The $myVariable is undefined when i want to use print it in nextPassage. (Error: <<print>>: bad evaluation: Cannot read property 'prop' of undefined)

Can you please tell me how i could implement this functionnality without having to write manually one by one the content of myArray ? 



1 Answer

0 votes
by (64.2k points)

You need to use the <<capture>> macro.

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.