permanently storing data in javascript defined variables

Hey guys,

Id like to know how to replicate what the global build in rpg maker variables have - where you can store data inside them, and they dont reset once you save and quit your game.
Ive tried window, and $gameSystem, but they just get undefined again once you exit the game.

Is permanently storing data in javascript defined variables possible to do, and if so how would you do it?
You need to include your variables into the save and load functions of the engine.

That by the way is the reason why we say that changing plugins makes savefiles incompatible - because plugins that add their data to save and load change how the savefiles are constructed.
And you need to do the same to save your data.
@Andar Could you give me a working example on how that would look perhaps? I have no idea how to include variables to the save and load functions of the engine. Or perhaps theres a tutorial somewhere?
For an example, check out my notepad plugin (link in signature). Ctrl-f to find the section that works with "DataManager".

You need to do 4 things to add something to a save file:

  1. Define your variable on game startup (typically set to null)
  2. Create your variable for new games
  3. Add your variable to the save contents
  4. Extract your variable from the save contents
Is permanently storing data in javascript defined variables possible to do, and if so how would you do it?
yes 2 easy way.
1er: the Web Storage API
https://developer.mozilla.org/fr/docs/Web/API/Web_Storage_API
Also take a look to how compress the local storage, because memory a limited with this api.
http://pieroxy.net/blog/pages/lz-string/demo.html
You will also need compresse in json before
https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/JSON/stringify

2er: the Json and node
is the best way and easy wah , but more work.
You need build a engine to write and load in nwjs you game system.
https://github.com/nwjs/nw.js/wiki/save-persistent-data-in-app
https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/JSON/stringify
@Aloe Guvner @Jonforum You both have given me lots of materials to look through, ill go study it all first, and if I dont figure it out ill post again. Thanks alot!
Just some context, Jon and I answered the question in 2 different ways.

I was talking about 'hooking in' to the way that RPG Maker already works with the save files, and his answer is more about ways to save data in general using JavaScript (not specific to RPG Maker).
@Aloe Guvner Thanks, ill keep that in mind!

Original thread: https://forums.rpgmakerweb.com/threads/permanently-storing-data-in-javascript-defined-variables.95156/