I want to know how to use save and load directly in JS!

From the Asset Store
Template for a generic save / load system, fully documented in comments and video
  • "save"

    "load"

    Fired when the savegame system saves or loads the state of the game. The saveData property of the event object is extra JSON data to save in the "save" event, and the corresponding last saved data in the "load" event. This allows custom data stored in scripts to be integrated with the savegame system. Note this is serialized to JSON so things like object references and complex types cannot be saved directly.

    This is the introduction of the document, but I still don't understand. Can you give me a detailed example?

  • There's currently no way to save or load a savegame directly from script. However when it's used in events, those events fire. In the "save" event, you can add extra data to be saved or loaded with the savegame in the saveData property of the event.

  • There's currently no way to save or load a savegame directly from script. However when it's used in events, those events fire. In the "save" event, you can add extra data to be saved or loaded with the savegame in the saveData property of the event.

    I still don't understand. Can you give me a code example?

    For example, what should I do to store the variable a = 100 a additionally?

    Is that so. Runtime. saveDate (a)?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here's an example:

    let myVariable = 123;
    
    runOnStartup(async runtime =>
    {
    	runtime.addEventListener("save", OnSave);
    	runtime.addEventListener("load", OnLoad);
    }
    
    OnSave(e)
    {
    	// Save myVariable by adding it to saveData
    	e.saveData.myVariable = myVariable;
    }
    
    OnLoad(e)
    {
    	// Load myVariable by reading it from saveData
    	myVariable = e.saveData.myVariable;
    }
  • Thank you

  • Here's an example:

    > let myVariable = 123;
    
    runOnStartup(async runtime =>
    {
    	runtime.addEventListener("save", OnSave);
    	runtime.addEventListener("load", OnLoad);
    }
    
    OnSave(e)
    {
    	// Save myVariable by adding it to saveData
    	e.saveData.myVariable = myVariable;
    }
    
    OnLoad(e)

    {

    // Load myVariable by reading it from saveData

    myVariable = e.saveData.myVariable;

    }

  • Sorry, my code was wrong, you have to assign the whole saveData object yourself like this:

    function OnSave(e)
    {
    	// Save myVariable by adding it to saveData
    	e.saveData = {
    		"myVariable": myVariable
    	};
    }
  • GREAR it is work !

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)