Howdy, Stranger!

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

Sugarcube options menu

edited March 2015 in Help! with 2.0
I'm a little confused about the SugarCube options menu variables.

What I want to do is create a toggle that:

1. Starts at the green "on"
2. When clicked to off, stops all music from playing
3. Sets a $music variable to 0 to prevent the game from starting up music in future (my music is gated behind <<if $music is 1>>)
4. When clicked on again, sets the $music variable back to 1

Currently I have this:

<<optiontoggle "musicoff" "Turn music off">>
Enabling this option turns off music and prevents it from playing.
<<stopsound "sound/music.ogg">>
<<stopsound "sound/intromusic.ogg">>
<<set $music to 0>>
Unfortunately, it:

1. Defaults to off (which is a little confusing since you're turning a music option "on" to turn music off. The explanatory text has been written for how the current toggle is, not how I want it to be)
2. Does not set $music back to 1 if it is clicked again, making the option choice permanent


  • The following is based on the <<optiontoggle>> and <<saveoptions>> documentation

    There are a number of issues with your example.

    1. A Toggle option's state (if they are yes or no) is not stored in a $variable, instead it is stored as a boolean (true for On and false for Off) in the options collection, so the state of your <<optiontoggle "musicoff" "Turn music off">> is stored in options.musicoff. You can use a <<set>> macro in your StoryInit passage to set its initial state like so:

    :: StoryInit
    <<set options.musicoff to true>>
    2. Your toggle option is asking a negative question but expecting a positive answer which can be confusing, it would instead be better to show a "Play Music" option initially set to true so that the Off state would stop the music. Something like the following.

    :: StoryInit
    <<set to true>>

    :: MenuOptions
    <<optiontoggle "music" "Play Music">>
    Use this option to start and stop the music
    <<if not>>
    <<stopsound "sound/music.ogg">>
    <<stopsound "sound/intromusic.ogg">>

    :: Some Passage
    // Code to start playing the music....
  • Thanks for the help. :)
Sign In or Register to comment.