Scene save state, load state

20 October 2017 19:10
Ive been looking into the api and I am unable to find a method of saving the current scene state and being able to load it afterwards. Ive looked within the scene class and storage class but have only found get_scenes(). Any guidance would be appreciated.
21 October 2017 04:20
You can't write files with javascript.. only way is to use storage module.

I use it to set the quality level and make it persistent so next time they come it remembers their settings.

browser cache or cookies not sure how they do it exactly, it's not persistent user can probably clear them but works for the most part.

This will read a JSON file that you can manually configure and then load it's settings. If you had a way to talk to the server you could send messages and get the server to update the JSON file.
m_assets.enqueue([{ id: "config", type: m_assets.AT_JSON, url: "js/myconfig.json"}], process_config, null);

if those don't work then I'm not sure what you want to do ;)
21 October 2017 04:25
exports.init = function() {

  quality = m_storage.get("quality");

  if (!quality) {
      quality = DEFAULT_QUALITY;
      m_storage.set("quality", quality);

    switch (quality) {
    case "LOW":
        var qual = m_cfg.P_LOW;
    case "MED":
        var qual = m_cfg.P_CUSTOM;
    case "HIGH":
        var qual = m_cfg.P_HIGH;
    case "ULTRA":
        var qual = m_cfg.P_ULTRA;

m_cfg.set("quality", qual);

if (quality == "LOW") {
m_cfg.set("enable_outlining", "true");

if (quality == "MED") {
m_cfg.set("allow_hidpi", "false");
m_cfg.set("antialiasing" , "true");
//m_cfg.set("precision" , "false");
//m_cfg.set("smaa", "false");
m_cfg.set("ssao" , "false");
m_cfg.set("bloom" , "false");
m_cfg.set("god_rays" , "false");


      canvas_container_id: "main_canvas_container",
      callback: init_cb,
      physics_enabled: true,
      show_fps: true,
      alpha: false,
      autoresize: true,

21 October 2017 04:26
function lowQset() {

m_storage.set("quality", "LOW");

setTimeout(function() {
}, 100);


function highQCset() {

  m_storage.set("quality", "MED");

  setTimeout(function() {
  }, 100);

function highQset() {

  m_storage.set("quality", "HIGH");

  setTimeout(function() {
  }, 100);

function ultraQset() {

  m_storage.set("quality", "ULTRA");

  setTimeout(function() {
  }, 100);
22 October 2017 03:45
Thanks I figured this far. I suppose I would have to set every location, every material every transform and rotation for every object individually and reload them all to save a scene state and reload it at will.. Maybe a function that builds an array of every object and its property to save into storage for loading afterwards is something they have already been looking into. Would be a vital feature especially for games and a massive stress relief then doing it manually. Thanks again.
23 October 2017 09:59
I see, You wouldn't do all that locally with JS in the browser cache or cookies. B4W guys won't be making that since you need server side. Javascript won't let you write from browser to file system, someone clears cache or cookies and it's all gone, not recoverable..

If you are talking on your local machine you could run it with electron or nwjs. Are you making a stand alone desktop App or an app for internet?

If you are looking to do sub 250ms saving location and translation on app for internet then you want a server to manage that:

I use node.js on a server connected to database. The server keeps track of all that stuff so when user saves or logs out save to DB. You can easily have a save button in the browser which signals to the server to save the info also or just save it all in real time.

I've used, firebase, mongo, mySQL and most recently postgres.
check out, they host node.js and have have postgres for free for development..

You can point your node app at firebase or mongodb (mongo is less friendly with the free stuff) or just point the javascript in the browser there directly.

First one I tried was Firebase, super friendly. Works from anywhere, save at 1 second intervals save x,y,z to dB, think I went down to sub 1 sec intervals saving but makes more sense to move to server if you need real time.

firebase & mongo = nosql
mysql and postgres = sql
23 October 2017 10:14
Thanks again for the info, i am using php for the server side. I had previously suggested a b4w server side nodejs module to allow networking in the logic editor. As I recall they were looking into it already so it is very likely updating object properties for saving scene/game states will come along with that.
Please register or log in to leave a reply.