You are reading a single comment by @Jonathan and its replies. Click here to read the full conversation.
  • I'm trying to program the settings for an app. All bigger numerical values show up and are selectable without any problems. However the last setting can be selected between Always/Alarms/Never. It shows up nicely in the menu but when I try to select an Item I get a horribly garbled error message in the console and nothig is saved to JSON. However the value in the variable is correctly set. The "Weekend Start Hour" menu works as it is supposed to however the "Follow DND" gives the error.

    If I remove writeSettings() from line 31 the menu works as expected but of course it then doesn't save anything when switching apps.

    This is the code in question:

    
     ( function(back) {
      var FILE = "annoy.json";
      var dndChoices = ["Always", "Alarm", "Never"];
      var settings = Object.assign({
        // Default values
        wes: 13,
        dnd: 0},
        require("Storage").readJSON(FILE, true) || {});
      function WriteSettings(){
        require("Storage").writeJSON(FILE, settings);
      }
      E.showMenu({
        "" : {"title" : "Annoy"},
        "Weekend Start Hour": {
          value: 7|settings.wes,
          min: 0, max: 23,
          onchange: v => {
            settings.wes = v;
            writeSettings();
          },
          format: v => v+"h",
        },
        "Follow DND": {
          value: 0|settings.dnd,
          min: 0, max: 2,
          format: v => dndChoices[v],
          onchange: v => {
            settings.dnd = v;
            console.log(v, settings.dnd);
            writeSettings();
          },
        },
      });
    })(load);
    

    And the error:

    >
    |___|                 _
             |_| espruino.com
    1 1
    Uncaught ReferenceError: "writeSings();
                           a.value);r.scroll=l.scroller.scry<a.y-4|­|(b=k(c.y),(0>f||0<=b)&&d from line 1 col 17
    d.handled| 
    
About

Avatar for Jonathan @Jonathan started