Save new custom data

Hello everybody!

I'm not sure if this is the correct place for my question, If not i´ll rewrite it again in the correct place. if this place is corect, Perfect!

I'm designing some scripts for a game. (I have some simple javascripts, when finish cleaning them I think that I will share them).

But in my attempts I found a wall that I don't understand how to solve it.

I suppose that in my script I make a new variable for the items. For example Item._purity. Ok, no problem. But in the game, when we defeat the monsters, the purity value will changing. Next, we will want save our progress.
How could I save this new value in the game?

An idea was to use the game variables... but next I thought for to create a dinamic json but... when the game is to make, I think my solution won't work. Or yes?
But, maybe... Exist other way to solve this problem. Or not?
Maybe its possible to save in the datasave? this would wonderful! but how?
I´m not sure about it.

One greeting to all.

P.d: sorry for my english and thanks for the help.
Just to let you know, if a thread is in the wrong place, Mods will move it. There is no need to rewrite it somewhere else.
if I remember correctly, the function is called DataManager.makeSaveContents or StorageManager.makeSaveContents. Search for it in rpg_managers and see how it is handled.
Yeah Poryg is correct, adding your custom data to the save file is probably the easiest way to do what you want.

I wrote a small snippet that you can study and adapt to your own system:
https://forums.rpgmakerweb.com/index.php?threads/js-snippets-thread.92501/#post-881460
Oh, thanks to all. I will study these functions and the Aloe's code fragment.
@Aloe Guvner would this work with rmmz as well? i tried it but its saying the object not defined which is weird cause the object not only gets defined but also updated. I figure im doing something wrong. i tried @Poryg 's (mad respect for your tutorials btw) tutorial as well but its... you know not very clear on certain things. for example makeSavefileInfo and actually defining new objects for it cause, trying to brute force my way though understanding is giving me a headache since im unsure about a lot of things reguarding this process.
@ougitou1 this is an old thread so make your own.
Aloe Guvner make it as a snippet so it doesn't work on it's own without your own code.
and RMMZ use a tiny bit of a different way, so you need to spit in the core files how
those are handles, so it's best to make your own thread with your problem, so others
can help you out 🙂
Here is a simple answer. Insert your data in Game_System.
It will be included in the save contents. No need to look at the function mentioned here.
This work in all RPG Makers, including RMXP to the latest RMMZ.
@TheoAllen ill attempt this. thank you.

Original thread: https://forums.rpgmakerweb.com/threads/save-new-custom-data.97746/