0 votes
by (330 points)
How do I require an answer to a radio button or checkbox question before allowing the player to continue the game? Is there some way to hide the link to the next passage (or just make it inactive) until the question has been answered? Also, and this is a minor matter that doesn't really relate to the game I'm building right now, but I'm curious: can you change the link depending on the answer given?

1 Answer

0 votes
by (68.6k points)
selected by
 
Best answer

You could use a <<link>> macro to ensure that the variable has a proper value before allowing the player to continue.  For example:

What's your favorite pie?
* <<radiobutton "_pie" "blueberry">> Blueberry?
* <<radiobutton "_pie" "cherry">> Cherry?
* <<radiobutton "_pie" "coconut cream">> Coconut cream?

<<link "Continue">>
	<<if def _pie>>
		<<set $pie to _pie>>
		<<goto [[Next Passage]]>>
	<</if>>
<</link>>

What exactly you test for in the <<if>> condition would depend on what exactly you're doing.  In the above example we ensure that the temporary variable _pie has a value before assigning that value to a story variable and sending the player to the next passage.

Here's a slightly more complicated example which adds an error message for the player:

What's your favorite pie?

* <<radiobutton "_pie" "blueberry">> Blueberry?
* <<radiobutton "_pie" "cherry">> Cherry?
* <<radiobutton "_pie" "coconut cream">> Coconut cream?

<<link "Continue">>
	<<if def _pie>>
		<<set $pie to _pie>>
		<<goto [[Next Passage]]>>
	<<else>>
		<<replace "#error-pie">>&nbsp;— Please select a pie.<</replace>>
	<</if>>
<</link>>@@#error-pie;@@

 

by (44.7k points)

Alternately, you could just add a "checked" parameter to one of the <<radiobutton>> macros, and then it will default to that value.

...