Trying to make a customization menu

Twine Version: 2.3.9
Story Format: SugarCube 2.31.1

My goal is to have a passage that acts as a customization menu for the proceeding story. In this passage, the player will be able to fiddle with a whole bunch of settings such as what characters are involved in the story and who they want to play as. I am very novice at programming, and my little experience with sugarcube is making this quite the learning process.

What I want is a bunch of settings the player can click on to activate the corresponding $variables, of course without taking them to a different passage. I only know how to make links to other passages, and when I scanned through the documentation I couldn’t find anything that I could get to work or understand.

For Example:

Choose your character:

  • character 1
  • character 2

Choose the scenario:

  • scenario 1
  • scenario 2

Try the <<link>> macro:

<<link "character 1">><<set $character to 1>><</link>>

That won’t go anywhere, but it will display whatever text and run whatever code is inside the <<link>>.

To prevent any confusion and provide a consistent interface, it’s strongly recommended that links should only be used for passage navigation.

In this case I’d recommend using the <<radiobutton>> macro instead. For example:

''Choose your character:''
<label><<radiobutton "$char" "char 1" checked>>Character 1</label>
<label><<radiobutton "$char" "char 2">>Character 2</label>

''Choose the scenario:''
<label><<radiobutton "$scene" "scene 1" checked>>Scenario 1</label>
<label><<radiobutton "$scene" "scene 2">>Character 2</label>

That will give people a clickable “radio button” option (which only allows one of each radio button group to be selected) which will set the value of the variable name that’s in quotes in the first parameter to the value in the second parameter if that radio button is checked. The “checked” parameter in the first option of each radio button group gives it a default option, in order to make sure that at least one option is picked.

Wrapping the macro in a <label> element like that makes sure that the label is clickable as well, though you might want to add the following code to your Stylesheet section to make that fact more obvious by changing the cursor appropriately when it hovers over the label’s text:

label {
	cursor: pointer;
}

After that you could use the <<link>> macro to send you to the appropriate passage based on those variables. For example, if the passage name was simply “scenario name - character name” you could do this:

<<link "Begin">>
	<<goto `$scene + " - " + $char`>>
<</link>>

The “backquotes” (the accent mark found on the ~ key on the upper-left of most keyboards) around the parameter within the <<goto>> macro causes that code to be evaluated and passed as a single parameter value.

Thus if, for example, the radio buttons were set to the first option in both cases, then if the user clicked the “Begin” link, that code would try to send them to the “scene 1 - char 1” passage.

There are lots of other ways to do that, but that’s one of the simplest in most cases.

Enjoy! :grinning: