Trouble storing which link clicked with variable choices

Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2.3.9
Story Format: Sugarcube

Hi, I’m currently trying to create a page of links based on generated game object entries. The result is a series of links displaying planet names, which when you click on them leads to that planet’s entry.

Currently, most of that is working fine but the issue I’m having is telling it to go to the right entry. Essentially, I’m setting $planetlook, which tells the planet detail display passage which link was clicked. However, because _setnumber has been modified by the time the link has clicked, it’ll always go to the last planet in the list.

I know there’s probably a fairly simple way to store the right value somewhere, it’s just stumping me what it is. Here’s the current scripting:

<<for _i to 0; _i lt $system.planet_no; _i++>>
	<<set _setnumber to _i + 1>>
	<<set _planetnumber to "planet" + _setnumber>>

	<<link "$system[_planetnumber].name" "planetdetails">>
        <<set $planetlook to _setnumber>>
        <</link>>
<</for>>

The <<capture>> macro

<<for _i to 0; _i lt $system.planet_no; _i++>>
    <<set _setnumber to _i + 1>>
    <<set _planetnumber to "planet" + _setnumber>>

    <<capture _setnumber>>
        <<link "$system[_planetnumber].name" "planetdetails">>
            <<set $planetlook to _setnumber>>
        <</link>>
    <</capture>>
<</for>>

Hope this helps.

2 Likes

Works perfectly, thank you!

1 Like