Discord
Login
Community
DARK THEME

Suggestion for script

@gilles storage.export storage.clear storage.import Most importantly I think we need the second one. Please add it if not already there.

huh?

Another approach is for there to be two functions: storage.as_object and storage.from_object. This way, the programmer could use storage.from_object(object end) to clear the storage. The MicroScript API code could be changed at play.js:538:

    return service = {
      api: {
        set: (name, value) => {
          value = this.storableObject(value);
          if ((name != null) && (value != null)) {
            storage[name] = value;
            write_storage = true;
          }
          return value;
        },
        get: (name) => {
          if (name != null) {
            if (storage[name] != null) {
              return storage[name];
            } else {
              return 0;
            }
          } else {
            return 0;
          }
        }
      },
      // new code -----------------------
      as_object: () => {
        return {...storage};
      }
      from_object: (value) => {
        value = this.storableObject(value);
        if ((typeof value == "object") && (value != null)) {
          storage = value;
          write_storage = true;
        }
        return value;
      }
      // end new code -------------------
      check: () => {
        if (write_storage) {
          write_storage = false;
          try {
            return ls.setItem(`ms${namespace}`, JSON.stringify(storage));
          } catch (error1) {
            err = error1;
          }
        }
      }
    };

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community