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

<<fadein 2s 4s>>
<<link "__Fruits__">>
	<<set _showFruit to true, _showNuts to false, _showVegetables to false, _lastLookedAt to "fruit">>
<<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>>
	<<set _showFruit to false, _showNuts to false, _showVegetables to true, _lastLookedAt to "vegetables">>
<<link "__Nuts__">>
	<<set _showFruit to false, _showVegetables to false, _showNuts to true, _lastLookedAt to "nuts">>
<<link "__Check Out__">>
	<<set _showFruit to false, _showVegetables to false, _showNuts to false>>

	<<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>>
			<<append "#list">><<print "You are done shopping">><br><</append>>
			<<append "#list">>[[another passage|another passage]]<br><</append>>


1 Answer

+1 vote
by (68.6k 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"