0 votes
by (520 points)

Hi, all!

OK, this is a SugarCube question,but I think it would be the same with Harlowe with the (live:) macro.

Bon, coucou.

<<set $pie to "XXX">>
<br>What's your favorite pie?

<br><<radiobutton "$pie" "blueberry">> Blueberry ?
<br><<radiobutton "$pie" "cherry">> Cherry?
<br><<radiobutton "$pie" "coconut cream">> Coconut cream?

<<repeat 1s>>
	<<if $pie != "XXX">>
		<br><br><<print $pie>>
		<<stop>>
	<</if>>
<</repeat>>

<br><br>Finished

Apparently, everything works as advertised: when I click one of the three radiobuttons, at the next 1 second cycle the value of $pie is printed.

But, BUT: "Finished" is printed immediately, and I don't want to see it before the user has made a choice. Even worse: this makes this code unusable as this passage is intended to be included in another one.

Can we stop Twine's execution while waiting for user input ? And I don't want to stop it with "[[Whatever|Wherever]]". I want to do that in the middle of a passage or in an included passage.

 

Thanks in advance.

 

4 Answers

0 votes
by (159k points)

NOTE: A potentially better solution would involve using Javascript to monitor the change state of the radio button elements and then updating the page using functionality similar to the <<replace>> macro, as this would result in there being very little delay between the Reader selecting a radio-button and the indicated text appearing.

When a Passage is processed before being displayed the whole of it's contents (excluding the bodies of interactive/timer macros) executed to generate the resulting HTML. This is why the Finished text is being instantly displayed, because it's not part of the <<repeat>> macro's body.

The following solution uses Custom Styling to generate a HTML div element with the ID of outcome and a <<replace>> macro to update the contents of that div once the condition in the <<repeat>> macro is true.

Bon, coucou.

<<set $pie to "XXX">>
<br>What's your favorite pie?

<br><<radiobutton "$pie" "blueberry">> Blueberry ?
<br><<radiobutton "$pie" "cherry">> Cherry?
<br><<radiobutton "$pie" "coconut cream">> Coconut cream?

@@#outcome;
@@\
<<repeat 1s>>\
	<<if $pie != "XXX">>\
		<<replace "#outcome">>$pie<br><br>Finished<</replace>>\
		<<stop>>\
	<</if>>\
<</repeat>>

 

0 votes
by (520 points)
edited by
Very good, greyelfr; thanks. But what are the backslahes for, and how can I prevent them from being displayed when the game is played ?

And I have (perhaps) an even better question : is a "[[whatever|wherever]]" equivalent to a <<break>> or a <<stop>>? Can I use it to properly get out of a loop executing in the current passage?
by (159k points)

Read the Line Continuations markup documentation, they don't/won't appear in the visual output.

by (159k points)
edited by

notes:
a. When either replying to someone's answer or asking a follow up question about an answer, you should use either the dark Comment button or the "thought bubble with three dots" button to open a text field to enter that replay/question. The green Answer button is for supplying an answer to a question.

b. Except when I state otherwise in my comments, I test all my examples before writing up an answer/comment to a question, this doesn't mean that an error can't creep in during the cut-n-pasting of the code examples.

I retested the above example and it doesn't show any backslashes, either before or after a radio-button is selected. So I suggest the problem is in your version of the code:
a. Did you cut-and-paste the code as is into your passage?
b. Did you add any white-space (like a space character) on the same line after the backslashes?
c. Did you reformat the contents on the <<repeat>> macro's body?

Can I use it to properly get out of a loop executing in the current passage?

The <<repeat>> macro's documentation clearly lists the two methods that can be used to terminate it's execution, and neither the <<break>> macro (used with the <<for>> macro) nor the markup-based link are either of them.

You can include a markup-based link within the <<replace>> macro's body is you wish to display one after the Reader has selected a radio-button..

0 votes
by (520 points)
edited by
( Deleted by me ).
0 votes
by (520 points)

Well, they did appear. But what about my other question ? Does exiting a passage inside a loop stop the executing loop? Having said that, it would be logical and solve my problem.

...