Hello hello, I swear I do try to do my own research before posting these questions, lol.
I thought making a multiple choice style quiz in Twine would be super easy, and I see it all the time in Twine games. I thought it was an Input element like
(checkbox:), but I quickly realized that’s not quite what I want. I’m looking to create a multiple choice quiz with four possible answers, and the player can only choose one, like how a normal online quiz works (note: these choices aren’t links to anything).
(checkbox:) almost works for this, if I do four in a row, but that allows the player to check every box, an option I don’t want. This “quiz” is just part of a brief story moment in my game and I don’t even need it to function fully (i.e. log the answers or show the correct result or anything, and even if I did need it to work properly, there are other tutorials I can follow for that).
So, to reiterate, I need help creating a question format that looks like multiple choice and that only allows the player to “fill in the bubble” on one option. I’ve tried finding a post on how to do this, to no avail. As a bonus, it would be cool if the choice “bubbles” actually looked like circles that go from hollow to full when selected, instead of the square boxes that the
(checkbox:) macro uses. But that’s not really necessary, just a bonus if there’s a simple solution to creating that look.
Any help would be as always appreciated, thanks!
Unfortunately there are two things that make implementing what you want difficult:
- Harlowe doesn’t include a
One possible way to could achieve a ‘single selection’ like outcome using Harlowe features is something like the following, which uses a Named Hook to contain the set of “choices” and the
(replace:) macro to replace that set with the selected “choice”.
(set: $fruit to "")
Select a fruit:
(set: $fruit to "Apple")
(set: $fruit to "Banana")
(set: $fruit to "Cherry")
eg. like accessing and updating Story Variable state.
Ahh dang, so that’s where everyone is getting their easy multiple choice stuff, the
(radio-button:) macro. That is unfortunate. Thanks for your response though, with some changes I think your example might possibly work for what I want… though I might just suck it up and use the
(checkbox:) macro anyway and hope the player doesn’t discover or care that they can choose every option, lol. It’s really about the ‘aesthetic’ of a multiple choice quiz rather than the functionality, so technically the “only choose one option” thing isn’t that important.
So, this is fun. I actually… got something “working” (ish) with the check boxes using this janky code. I’m not too experienced with Twine coding so I’m sure there’s a simpler/cleaner way of doing this, but I basically bound all the answers (A, B, C, and D) to variables and then used
(set:) to make it so no two boxes can be checked at once. Initially this didn’t work for whatever reason and it bugged the hell out of me, but I eventually figured out the code essentially wasn’t “updating” (I’m sure there’s a reason for this / better way to describe this) so I added a
(live:) with a very short timer so the code would always be refreshing. So, yeah, hella janky, but it sorta mostly works for my purposes!
(live: 0.01)[(if: $A is true)[(set: $B to false, $C to false, $D to false)]]
(live: 0.01)[(if: $B is true)[(set: $A to false, $C to false, $D to false)]]
(live: 0.01)[(if: $C is true)[(set: $A to false, $B to false, $D to false)]]
(live: 0.01)[(if: $D is true)[(set: $A to false, $B to false, $C to false)]]
''1.'' Which of the following is //not// another name for the Andromeda Galaxy? //(2 points)//
(checkbox: 2bind $A," Messier 31")
(checkbox: 2bind $B," M31")
(checkbox: 2bind $C," AD30")
(checkbox: 2bind $D," NGC 224")
EDIT: Well, seems I spoke too soon. The code works for the multiple choice questions, but I have a text input box further down in the same passage and for some reason the code seems to be screwing with that! When you click to type in the input box it gets clicked out of almost instantly, as if the
(live:) is affecting the input box as well and causing it to “refresh”. Mmmmmm
Hello, i wanted to know how can we make more than 1 correct answer type of mcq? I mean if two of the options are correct? How to make that
Yeah, Sugarcube has radio buttons, and I think also drop-down menus for selection.
One other thing you could do is forego checkboxes altogether and just present choices to the player - each choice goes to a passage that sets the variable required and moves on to the next question.
Harlowe does have checkboxes which set a variable to either true or false, and I would assume you can have multiples of them on the same page:
A command that creates a checkbox input, which sets the given bound variable to
false , depending on its state.
(checkbox: bind $gore, "Show violent scenes") creates a checkbox labeled “Show violent scenes” which is initially unchecked.
(checkbox: 2bind $perma, "Permadeath") creates a checkbox which is initially checked if $perma is
true , and continues to update itself whenever some other macros change $perma.
Yeah, Harlowe has dropdowns too, at least.
I considered doing it like you said, but this part of my story is more about imitating the aesthetic of a multiple choice quiz (it’s essentially a flashback to you taking a test in high school), and the checkboxes look better for that in my opinion. Plus I wanted the questions all on one passage, as if you were looking at a test. I’m pretty content with what I ended up with.