0 votes
by (710 points)

The following code usually works fine, but when I add an if statement into the Vegetables link, I get a whole bunch of errors. Is there any way to use if statements or evaluate conditions within a link?

You have arrived at the store. You start off by buying some fruit.
<<silently>>
<<set $fruits to ["apple","orange","pear"]>>
<<set $vegetables to ["carrot","cabbage","potato"]>>
<<set $nuts to ["walnut","hazlenut"]>>
<<set _showFruit to true>>
<<set _showVegetables to true>>
<<set _showNuts to true>>
<<set _lastLookedAt to "fruit">>
<</silently>>
@@#list;@@

<<fadein 2s 4s>>
<<link "__Fruits__">>
	<<set _showFruit to true, _showNuts to false, _showVegetables to false, _lastLookedAt to "fruit">>
<</link>>
<<link "__Vegetables__">>

	<<if _lastLookedAt == "fruit>>
	<<append "#list">><<print "You stop looking at fruits, and switch to vegetables">><br><</append>>
	<<elseif _lastLookedAt == "nuts">>
	<<append "#list">><<print "You stop looking at nuts, and switch to vegetables">><br><</append>>
	<</if>>
	
	<<set _showFruit to false, _showNuts to false, _showVegetables to true, _lastLookedAt to "vegetables">>
<</link>>
<<link "__Nuts__">>
	<<set _showFruit to false, _showVegetables to false, _showNuts to true, _lastLookedAt to "nuts">>
<</link>>
<<link "__Check Out__">>
	<<set _showFruit to false, _showVegetables to false, _showNuts to false>>
<</link>>
<</fadein>>

<<silently>>
	<<repeat 2s>>
		<<if _showFruit>>
			<<append "#list">><<print either($fruits)>><br><</append>>
		<<elseif _showVegetables>>
			<<append "#list">><<print either($vegetables)>><br><</append>>
		<<elseif _showNuts>>
			<<append "#list">><<print either($nuts)>><br><</append>>
		<<else>>
			<<append "#list">><<print "You are done shopping">><br><</append>>
			<<append "#list">>[[another passage|another passage]]<br><</append>>
			<<stop>>
		<</if>>
	<</repeat>>
<</silently>>

 

1 Answer

+1 vote
by (63.7k points)
selected by
 
Best answer

You have a missing double quote within the first <<if>> of the <<link "__Vegetables__">>:

<<if _lastLookedAt == "fruit>> ← Missing double quote: "fruit → "fruit"

 

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.
...