How to Save a Game Using NWJS?

1 favourites
  • 9 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hello, I'm redoing my game on Steam because of the way it saves, I was using the game's save state and on Steam I sent the entire Appdata folder to the Cloud, this works, but the obvious thing happened, if I perform updates, old players will continue on the version they played the first time.

    So I'm remaking my game the right way, using Local Storage and Arrays, it's saving smoothly. However, I can't find the json file that my Local Storage saves anywhere.

    I found some people saying to use the NWJS object and create a folder to save it, but I didn't find any information or an exact tutorial on how to create, save the json and then load it in the same way that Local Storage does.

    Does anyone who uses NWJS to export games to Windows know how I can save my games in a JSON and load them? And of course, I can work on it, for example after loading send it to my array.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • construct.net/en/make-games/manuals/construct-3/plugin-reference/nw-js

    See the section in the manual regarding using file paths correctly on the NW.js page.

    It recommends writing to NWjs.UserFolder & "myfile.txt", however I would additionally recommend putting it in a directory unique to your game, as well as saving the file as .json if you'll be saving data in json format. Alternatively, use an obfuscated/unique/encrypted format you are familiar with.

    You want to use the NW.js Write text file action, with your array.asJSON as the content to write. Or whatever else type/format of data you're saving. Dictionary.asJSON works well as well, and is more similar to LocalStorage in terms of keys and values. Save to your dictionary as you normally would have to LocalStorage, with the additional step of writing the dictionary to disk as a file through NW.js when desired.

    To load, you can use the ReadFile() expression (into your load dictionary or load array action). You can get information about the file location with the NW.js action List files along with the UserFolder, ListCount, and ListAt() expressions to confirm and validate the existence of save files.

  • First, you need to add NWJS object to the project.

    NWJS Write Text File action to save.

    Array Load from NWJS.ReadFile("path") to load.

    And of course these will only work in the exported game.

  • construct.net/en/make-games/manuals/construct-3/plugin-reference/nw-js

    See the section in the manual regarding using file paths correctly on the NW.js page.

    It recommends writing to NWjs.UserFolder & "myfile.txt", however I would additionally recommend putting it in a directory unique to your game, as well as saving the file as .json if you'll be saving data in json format. Alternatively, use an obfuscated/unique/encrypted format you are familiar with.

    You want to use the NW.js Write text file action, with your array.asJSON as the content to write. Or whatever else type/format of data you're saving. Dictionary.asJSON works well as well, and is more similar to LocalStorage in terms of keys and values. Save to your dictionary as you normally would have to LocalStorage, with the additional step of writing the dictionary to disk as a file through NW.js when desired.

    To load, you can use the ReadFile() expression (into your load dictionary or load array action). You can get information about the file location with the NW.js action List files along with the UserFolder, ListCount, and ListAt() expressions to confirm and validate the existence of save files.

    Thank you!

  • First, you need to add NWJS object to the project.

    NWJS Write Text File action to save.

    Array Load from NWJS.ReadFile("path") to load.

    And of course these will only work in the exported game.

    I believe what I should do then is create an array and a json within the construct, use Ajax to import the json into the array, and then use NJWS to write the array into the json, right?

  • I believe what I should do then is create an array and a json within the construct, use Ajax to import the json into the array

    If you need to pre-load some data into the array, then yes - create an array file in the project and load it with AJAX. You don't need NWjs for this part.

    and then use NJWS to write the array into the json, right?

    If you need to save the contents of the (changed) array in runtime, you can either save it to local storage or write to a disk file with NWjs.

  • > I believe what I should do then is create an array and a json within the construct, use Ajax to import the json into the array

    If you need to pre-load some data into the array, then yes - create an array file in the project and load it with AJAX. You don't need NWjs for this part.

    > and then use NJWS to write the array into the json, right?

    If you need to save the contents of the (changed) array in runtime, you can either save it to local storage or write to a disk file with NWjs.

    I was using Local Storage, but I can't find the location where it is saved, this is my main problem actually, I need to be able to find the saved json. I will try to use NJWS to save it in a json that I know where it is.

  • LS location on Windows should be this:

    C:\Users\USERNAME\AppData\Local\game_name\User Data\Default\IndexedDB

  • LS location on Windows should be this:

    C:\Users\USERNAME\AppData\Local\game_name\User Data\Default\IndexedDB

    Apologies for the delay, I found a light location of a few kb where the Local Storage is saved, the path is also in Appdata, it's called chrome (and some numbers), Thanks for the help!

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