Please specify version and format if asking for help, or apply optional tags above:
Twine Version:2.3.9
Story Format: Sugarcube 2.31.1
I would like to include a “mute audio” button in the UI bar. I’m using `this code from HiEv’s archive and have added it to my story JavaScript.
function masterMuteHandler() {
SimpleAudio.mute(settings["masterMute"]);
}
Setting.addToggle("masterMute", {
label : "Master Mute.",
desc : "Mute control for all audio.",
onInit : masterMuteHandler,
onChange : masterMuteHandler
}); // default value not defined, so false is used
My problem is getting the button to do anything.
I’ve tried several things. This is my most recent code:
That results in an error that “setting” is not defined. (I’ve seen other example code that uses setting.SettingName inside a Twine <> statement after calling Setting.addToggle in the JavaScript, which is why I’m trying it this way.)
Any help would be greatly appreciated. Thank you!
(I’ll obviously want to change the button text too, but that’s not really the trouble right now.)
For added clarity to what the others have said, the Setting object is for setting up the “Settings” dialog window, while the settings object is used for accessing the values of the various settings. The capitalization and pluralization have to match exactly for them to work properly. See the SugarCube documentation on the Setting API and the settings object for details.
Also, if you want to toggle the button icon too, you can do this: