Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Radiobuttons and If's

I've been using radiobuttons quite frequently, and they're great to establish variables. But I came across a question. It's not a structural problem to my game, just a whim, but I got curious. So here goes: is it possible to have a radiobutton establish a variable and unlock a hidden content of the same passage it's in?

I'll explain better.
I have this in my passage, for example,
* Beer  <<radiobutton "$meal" "beer">>
* Mead  <<radiobutton "$meal" "mead">>
* Ale  <<radiobutton "$meal" "ale">>

<<linkreplace ">>">><<goto "Next">><</linkreplace>>

Now my question, my intention was that the <<linkreplace>> only appeared once the player had made a choice. Now I imagined that could have something to do with a refreshing of the passage itself but I don't know how to incorporate that with the radiobutton macro.
Is this possible? Thanks :)

(and sugarcube 2.18/twine 2)


  • edited July 2017
    Assuming that this situation is not a one-off and you have several passages containing the same setup, try something like the following.

    <label><<radiobutton "$meal" "beer">> Beer</label>
    <label><<radiobutton "$meal" "mead">> Mead</label>
    <label><<radiobutton "$meal" "ale">> Ale</label>
    <span id="reveal">[[>>|Next]]</span>
    TIP: Wrap the <<radiobutton>>, or <<checkbox>>, and its label within the <label> tag. It makes the included text also activate the radiobutton, or checkbox, when clicked on.

    JavaScript (Twine 2: goes in Story JavaScript; Twine 1: goes in script-tagged passage)
    postrender['radiobutton-reveal'] = function (content) {
    	var reveal = content.querySelector('#reveal');
    	if (reveal) {
    			.on('change.reveal', function () {
    				if (this.checked) {

    • Using <<goto>> should be a last resort. You certain don't need it here.
    • Using <<linkreplace>> as you are is bizarre. Unless the link is supposed to directly output something around or in replacement of its link test when clicked, you should be using <<link>> instead.
  • Thanks @TheMadExile it works exactly as I wanted. Thanks for the tip on the <label> thing too, I didn't know it. As for the <<linkreplace>> I am indeed replacing the link with something else. I just posted part of the passage, in fact, when clicked, depending on a previous variable, there's another chunk of text that appears, that's why. But thank you for the note. :)
Sign In or Register to comment.