Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2.3.5
Story Format: SugarCube 2.3.1
I’m likely too new to this to ask the right question or to find it in searches, so I’ll just ask.
My goal is to set a simple variable for $gunSidearm, having players choose between “Your trusty .45 pistol” and “Your worn 9mm SMG” without jumping to an entirely new “page” in the game.
I simply want to select the $gunSidearm from a short list/array and then confirm it with the end line “You ensure you have plenty of ammunition and clear the chamber for your $gunSidearm.”
I realize this is probably 101 level stuff, but I’m totally lost and am praying to find a kind soul to help a poor confused designer who’s new to Twine.
You ensure you have plenty of ammunition and clear the chamber for your \
<<listbox "$gunSidearm">>
<<option "trusty .45 pistol">>
<<option "worn 9mm SMG">>
<</listbox>>
Edit: some people also like to use cycling links for this sort of thing…
I’m looking for something without any sort of drop down menu, but just a list of options such as the following:
Your worn 9mm SMG
Your trusty .45 pistol
Then you’ll get a confirmation on the same page with a <<print $gunSidearm>> after the selection. I know I’ve seen it done before in a Twine game, but I can’t for the life of me figure out how.
Then, in your passage, you’d put something like this:
<span id="confbtn">Choose your weapon:
<<for _i = 0; _i < setup.guns.length; _i++>>
<label><<radiobutton "$gunSidearm" setup.guns[_i] `$gunSidearm == setup.guns[_i] ? "checked" : ""`>> Your <<= setup.guns[_i]>></label>
<</for>>
<<button "Confirm weapon choice">>
<<if def $gunSidearm>>
<<set $("input[type=radio]").attr("disabled", true)>>
<<replace "#confirmed">>\
You ensure you have plenty of ammunition and clear the chamber for your $gunSidearm.
[[Next]]
<</replace>>
<<remove "#confbtn">>
<<else>>
<<replace "#confirmed">>\
Select a weapon above first.
<</replace>>
<</if>>
<</button>>
</span><span id="confirmed"></span>
That will disable the radiobuttons when they click the “Confirm weapon choice” button, hide the earlier text, show the text you requested, and display a link for the “Next” passage.
If you don’t want it to remove the earlier text, just get rid of the “<<remove "#confbtn">>” line.
You could also set $gunSidearm to one of the gun names, like “<<set $gunSidearm = "trusty .45 pistol">>”, in StoryInit if you want to set that as the default gun.
<span id="options">\
Choose your weapon:
* <<link "Your worn 9mm SMG">><<set $gunSidearm to "worn 9mm SMG">><<replace "#options">><<print "You ensure you have plenty of ammunition and clear the chamber for your "+$gunSidearm+".">><</replace>><</link>>
* <<link "Your trusty .45 pistol">><<set $gunSidearm to "trusty .45 pistol">><<replace "#options">><<print "You ensure you have plenty of ammunition and clear the chamber for your "+$gunSidearm+".">><</replace>><</link>>
</span>