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

Auto-generating Links

$
0
0
Hi,

Absolute beginner with any of this and unable to find a solutions to the following problem.
I am working with Sugarcube 2 and have run into a bit of a hurdle I can't find a solution to. I have set up my links in a way to carry variables:
<<link [[Smell]]>>
    <<set $target = "flower">>
<</link>>

In the 'Smell'-Passage a switch statement is then checking on how to proceed with this particular input.

Since I have a lot of these kind of links, I was hoping I could automatically generate these links:
<<set $redflower to {
"name": "Red flower",
"actions": ["look", "smell", "take"],
}>>

<<set $blueflower to {
"name": "Blue flower",
"actions": ["look", "smell", "take"],
}>>

<<set $allflowers = [$redflower, $blueflower]>>

<<for _i to 0; _i lt $allflowers.length; _i++>>
    <<print $allflowers[_i]>>: 
    <<for _j to 0; _j lt $allflowers[_i].actions.length; _j++>>
        <<switch $allflowers[_i].actions[_j]>>

        <<case "look">>
        <<link [[Look]]>>
            <<set $target = $allflower[_i].name>>
        <</link>>

etc...

        <</switch>>
    <</for>>
<</for>>


This creates the basic link-structure just fine, but obviously <<link [[Look]]>><<set $target = $allflower[_i].name>><</link>> does not work ouside of the for-clause, so I get an error as soon as any of the links is clicked. Is there any way I can replace it to make this work, or do I have to fill in every link manually?

Viewing all articles
Browse latest Browse all 1844

Trending Articles