0 votes
by (130 points)

Can someone explain why this (show:) macros on this code example never activate; no matter whether var is or

isn't 1., the text "You clicked" is never rendered - yet My reading of the code is it should always be.

(if: $var is 1)[1 (show: ?one) ]
(else:) [2 (show: ?two)]

|one)[You clicked one]
|two)[You clicked two]


The code here is much simpler than the code in my story; where I have a complex set of (if:) which provided mutlple routes to the same hook; which is why I came up with this construction. 

I can change the the if hook contents to  ' (link: "continue")[(show ?one)] '  but that adds another link for the player to click which doesn't actually represent a choice; and I'm trying to remove those as a design decision.


1 Answer

+2 votes
by (144k points)
edited by

WARNING: For simplicity sake the following information is conceptional correct even though it isn't 100% technically correct.

The TwineScript within a Passage is generally processed and executed statement by statement from top to bottom.

In your example the (if:) and (else:) macro statements are processed before the two hidden named hooks statements are, this means that at the time either of the (show:) macros are executed the two hidden named hooks don't exist yet which is why one of them isn't made visible.

If you move the two hidden named hooks so that they are before/above the (if:) macro then the relevant (show:) macro will work.

|one)[You clicked one]
|two)[You clicked two]

(if: $var is 1)[1 (show: ?one) ]
(else:) [2 (show: ?two)]

The reason placing the (show:) macro within the associated hook of a (link:) macro works is because the content of that associated hook isn't processed or executed until after the user selects the link, and that selection can't occur until all of the Passage as been processed so the hidden named hooks with exist.

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.