Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Save/Load Character variables.

Another strange story...

Is there a way to save the Character variables, like atributes, gold, from one story to other?

i.e: If i have 2 or more stories in diferent html files, can i set the name in first story and load somehow in the rest of stories?

Any ideas?

Comments

  • The SugarCube story format supports saving the story state (History / Variables) to a file on the Readers harddisk, and it can be configure what gets saved. That file could then be loaded into a different story as long as it knew what to do with the data in the save file.
  • I have read it and i made this:
    [Story Javascript]
    macros.add("SaveCharacter", {
    		handler : function () {
    			SaveSystem.save(8, "Character", $Player[0]);
    		}
    });
    [Story]
    <<click "Save">><<SaveCharacter>><</click>>
    

    But appears an error: Cannot execute macro...

    As the idea is to autosave the character on hard disk without asking about slot, this will be correct? Create one slot more, save, remove slot.
    macros.add("AutoSaveCharacter", {
    		handler : function () {
    			config.saves.slots=SaveSystem.length()+1
    			SaveSystem.save(SaveSystem.length(), "Character", $Player[0]);
    			SaveSystem.exportSave()
    			config.saves.slots=SaveSystem.length()-1
    		}
    });
    

    And im worried about SaveSystem.exportSave() becouse the documentation explains that "Saves the story to disk." not a part of it and SaveSystem.save(slot [, title [, metadata]])->metadata "The data to be stored in the save object's metadata property." but not the only value. I think if i try to load in other story, would be an error because the story is not the same.

  • SugarCube's save system is for saving the entire story state history (as it exists at the time of the save), not parts of it. It creates fully functional saves. It is not intended for dumping the odd $variable to disk.

    Depending on what you actually want to do, it may be possible to use the save system to achieve it. If you want to save some state which would be used as the seed of another story, then it is possible to pare down a save to the barest essentials for later loading by another story to use as its seed. If, on the other hand, you want to save some state which can be moved freely back and forth between stories, then you'll want to look for another method.

    PS: The macros are incorrect on multiple levels. Beyond the purely functional issues, neither is going to do what you want, so I won't bother going into details now about why they're incorrect. However, if you'd like, I could do so.
  • edited August 2015
    The idea is to save the carácter atributes at the end of a story for use in de begining of the next story. I have read the macroslib.js of sugarcube but for now i cant understand how save works.
  • Klain wrote: »
    The idea is to save the carácter atributes at the end of a story for use in de begining of the next story. I have read the macroslib.js of sugarcube but for now i cant understand how save works.

    Couldn't you just link them back to a menu screen at the end of the game? That way their variables stay the same, but you play through passages again.
  • edited August 2015
    The stories will be on separated html files and if im right, the save file compare the passages to know if is the same story and load.
  • Ok, I'm sure this will be more a fix than a solution but somehow it works .
    macros.add("SagaSave",{
      version: {major:1, minor:0, patch:0},
      handler : function() {
    	// Store
    	localStorage.setItem("Saga", this.args[0]);
    	}
    });
    
    macros.add("SagaLoad",{
      version: {major:1, minor:0, patch:0},
      handler : function() {
    	// Retrieve
    	state.active.variables["Name"]=localStorage.getItem("Saga");
    	}
    });
    

    In a first try, I've use <<SagaSave $Name>> in a story and in other <<SagaLoad>><<print $Name>> and it works.

    With some investigation and work i thing it can be used as a real solution.

    Thanks all!!
Sign In or Register to comment.