Howdy, Stranger!

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

How to make a pause and mute button in MenuOptions?

I've been trying to use the MenuOptions passage of my story to make a pause and mute button for the music, but it's not going very well. I can get both of them to turn the sound off, but I can't figure out how to turn the sound on. I tried looking at the example file for MenuOptions, but I didn't really get what I'm supposed to do to make the EnsureOptionsExist widget work. This is the code I am currently using.
:MenuOptions
<<ensureOptionsExist>>\

<<optiontoggle "pause" "Pause">>
Pause the music?
<<onchange>>
<<pausesound $music>>
<</optiontoggle>>

<<optiontoggle "mute" "Mute">>
Mute all sound?
<<onchange>>
<<stopsound $music>>
<<set $sound = "muted">>
<</optiontoggle>>

:Widget
<<widget "ensureOptionsExist">><<if Object.keys(options) eq 0>><<setOptionsToDefault>><</if>><</widget>>

<<widget "setOptionsToDefault">>
<<set options.pause = false>>
<<playsound $music>>
<<set options.mute = false>>
<<set $sound = "audible">>
<<saveoptions>>
<</widget>>

Comments

  • You're only pausing/stopping your audio within the &lt;&lt;onchange&gt;&gt; sections, when what you actually want to be doing is toggling the audio states.  For example:

    :: MenuOptions
    <<ensureOptionsExist>>\
    !Sound Options
    <<optiontoggle "pause" "Pause">>
    Pause the music?
    <<onchange>>
    <<if options.pause>>
    <<pausesound $music>>
    <<else>>
    <<playsound $music>>
    <</if>>
    <</optiontoggle>>
    <<optiontoggle "mute" "Mute">>
    Mute all sound?
    <<onchange>>
    <<if options.mute>>
    <<stopallsound>>
    <<set $sound = "muted">>
    <<else>>
    <<set $sound = "audible">>
    <<playsound $music>>
    <<playsound $ambient>>
    <</if>>
    <</optiontoggle>>
    [EDIT] Fixed a few misspellings.
  • That doesn't seem to be working. Now the music just won't pause no matter what I do. Is there something I should be changing in the widget passage?
  • The problem is that I misspelled options as option in the example I gave.  Change that and it should work.

    Note, however, that the example doesn't cover interactions between pause and mute.  Frankly, I don't see why you need both.  You'd probably be better off simply using a single "Enable audio/sound" option.

    As to changing the widget.  I'd probably suggest not putting non-option setting in &lt;&lt;setOptionsToDefault&gt;&gt;, since it only gets called when the options don't exist.  You'd be better off putting the other settings in StoryInit.

    I'll attach an example of what I mean.
  • Okay. Thank you for the help! It works now, and I've just pared it down to a mute button!
Sign In or Register to comment.