Link based upon random + variable result?

Twine Version: Sugarcube 2.36.1

Total beginner to Twine and any coding so ELI5, please. I am writing an IF RPG-like game.

I am trying to give the player the option of solving the challenge using their $fire or $water statistic. These are set earlier in the story. Based on what the player chooses, a random number 1 through 6 is added to the $fire or $water stat. The result either takes them to the Good “OpenCalm” passage or the Bad “OpenNervous” passage for both variables.

What am I doing wrong? Please and thank you!

<<link "Take a quick jog to burn some energy. (Fire)">>
	<<set _roll to random (1,6) + $fire>>
    <<if _roll < 5>>\
	[[You're still wound up and can't seem to calm your nerves.|OpenNervous]]
    <<else>>\
	 [[You still your nerves.|OpenCalm]]
	<</if>><</link>>
<<link "[[Meditate for a moment to center yourself. (Water)">>
	<<set _roll to random (1,6) + $water>>
	<<if _roll < 5>>\
  	[[You're still wound up and can't seem to calm your nerves.|OpenNervous]]
	<<else>>\
  	[[You still your nerves.|OpenCalm]]
	<</if>>
<</link>>

Hi!

You’re trying to put a link …
[[You're still wound up and can't seem to calm your nerves.|OpenNervous]]
…inside a link
<<link "Take a quick jog to burn some energy. (Fire)">><</link>>, which is why it doesn’t work (the “inside” links are not displayed).

There’s a couple of ways to achieve the result you want: You can use <<goto>> inside your link to redirect the player to target passage:

<<link "Take a quick jog to burn some energy. (Fire)">>
	<<set _roll to random (1,6) + $fire>>
    <<if _roll < 5>>\
	<<goto "OpenNervous">>
    <<else>>\
	<<goto "OpenCalm">>
	<</if>>
<</link>>

Or you can add the roll before the link and display one of two links that look identical, but lead to different passages:

<<set _roll to random (1,6) + $fire>>
<<if _roll < 5>>\
[[Take a quick jog to burn some energy. (Fire) | OpenNervous]]
<<else>>\
[[Take a quick jog to burn some energy. (Fire) | OpenCalm]]
<</if>>\

(In both cases, you’ll have to put the additional message (“You’re still wound up and can’t seem to calm your nerves.”/“You still your nerves” somewhere else, like in the the target passage).

3 Likes

I knew it was something simple. Thank you so much! The first solution is what I used with <<link>> and it worked exactly as intended.

1 Like