tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
185 stars 42 forks source link

Setting menu disappears on reload #54

Closed Purzelkater closed 4 years ago

Purzelkater commented 4 years ago

The following code I have added to my start passage:

<<script>>
    var settingFontSize = function () {
        var emSize = (settings.fontSize/100).toString();
        document.getElementById("passages").style.fontSize = emSize+"em";
    };
    Setting.addHeader("");
    Setting.addRange("fontSize", {
        label    : "Font size",
        min      : 100,
        max      : 200,
        step     : 5,
        default  : 100,
        onInit   : settingFontSize,
        onChange : settingFontSize
    }); 
    Setting.addToggle("playSound", {
        label    : "Play music?",
        default  : false
    });
    Setting.save();
<</script>>

Starting a new game the setting dialog works like expected. But after reloading the game (reload the window on browser or close and open the html file) or after resetting the values (with the default reset button on setting dialog) the setting button disappears from the menu.

ChapelR commented 4 years ago

That is expected behavior. If your start passage doesn't run, neither does that code. It should be in story JavaScript. If you absolutely insist on having it in a passage, use StoryInit.

Purzelkater commented 4 years ago

That's it! Thank you. I hadn't thought of that the Setting setup would be temporary on the Start passage.