SugarCube 2.0: Settings API
Often, it can be useful to have global values that exist as part of the Settings dialog where players can change them at different times. For this, we can use the <a href="http://www.motoslave.net/sugarcube/2/docs/api-setting.html">//Settings//</a> API.
To start creating a collection of Settings, we can first use the {{{Setting.addHeader()}}} function to set a header and a description.
<<script>>
Setting.addHeader("Content Settings", "Settings controlling what content is made available in the game.");
<</script>>
[[Setting Settings]]To build some settings, we can use either {{{Setting.addToggle()}}} or {{{Setting.addList()}}}. For single options, use a "toggle" or for muliple options, "list." (Note: {{{Setting.save()}}} must be called to "save" the values before they will appear in the //settings// object to access.)
<<script>>
Setting.addToggle("showtext", {
label : "Show some text?",
default : false
});
Setting.addList("options", {
label : "Choose an option",
list : ["Option 1", "Option 2", "Option 3", "Option Another"],
default : "Option 1"
});
Setting.save();
<</script>>
The value of showtext is <<print settings.showtext >>
The value of options is <<print settings.options >>