Hello guys, Is there any tutorial on how saving and load process are works? because i want to create a new JSON file and i don't know what are the functions on the DataManager should i allias or use to manage the Update and Getting a data from a JSON file. I tried to read some scripts of others like the Quest scripts and still can't understand what they do haha! Sorry I'm a newbie in scripting. Thanks in advance 🙂
Tutorial for a New JSON file?
Javascript/Plugin SupportWhat kind of file are you adding - something similar to the $data... files?
What I normally do is just look through DataManager, and wherever the $data... files are used, I will add something similar in my plugin.
Let's go through it ... we'll use a new variable called $dataMyData for the example (all of this is within your own plugin).
var $dataActors = null;
just initializing it to contain nothing. This probably doesn't need to be done, but for completeness, we'll do it:
var $dataMyData = null;
This is where it lists all the files that need to be loaded on launching the game, and what global variable (array) they're going to be put into. We don't want to redefine it (as that would remove all the default ones), we just want to add to it:
DataManager._databaseFiles.push({ name: '$dataMyData', src: 'MyData.json' });
If that's all you want to do - load it when the game is launched, that's all you need to add, apart from the rest of your plugin to actually use it. If you want to do more stuff, like setting things up after the data is loaded, you can do that in the DataManager.onLoad function:
var _DataManager_onLoad = DataManager.onLoad;
DataManager.onLoad = function(object) {
_DataManager_onLoad.call(this, object);
if (object === $dataMyData) {
// do other stuff here
}
};
However, if you want to create a new class, like $gameActors, $gameSystem, etc that get saved with the player's save file, that's a completely different process.
What I normally do is just look through DataManager, and wherever the $data... files are used, I will add something similar in my plugin.
Let's go through it ... we'll use a new variable called $dataMyData for the example (all of this is within your own plugin).
var $dataActors = null;
just initializing it to contain nothing. This probably doesn't need to be done, but for completeness, we'll do it:
var $dataMyData = null;
Code:
DataManager._databaseFiles = [
{ name: '$dataActors', src: 'Actors.json' },
...
This is where it lists all the files that need to be loaded on launching the game, and what global variable (array) they're going to be put into. We don't want to redefine it (as that would remove all the default ones), we just want to add to it:
DataManager._databaseFiles.push({ name: '$dataMyData', src: 'MyData.json' });
If that's all you want to do - load it when the game is launched, that's all you need to add, apart from the rest of your plugin to actually use it. If you want to do more stuff, like setting things up after the data is loaded, you can do that in the DataManager.onLoad function:
var _DataManager_onLoad = DataManager.onLoad;
DataManager.onLoad = function(object) {
_DataManager_onLoad.call(this, object);
if (object === $dataMyData) {
// do other stuff here
}
};
However, if you want to create a new class, like $gameActors, $gameSystem, etc that get saved with the player's save file, that's a completely different process.
Thanks 🙂 for the quick response.
Yes! something similar to the $data... files.
Now, I got how to load the JSON files. Thank you 🙂
That creating a new class like $game.. is too difficult to understand.
And extracting the contents to a particular class (ex: $gameMyclass) is to confusing hehehe.
Yes! something similar to the $data... files.
Now, I got how to load the JSON files. Thank you 🙂
That creating a new class like $game.. is too difficult to understand.
And extracting the contents to a particular class (ex: $gameMyclass) is to confusing hehehe.
It's not necessarily difficult - it's actually pretty easy. You just do it differently, that's all.
Original thread: https://forums.rpgmakerweb.com/threads/tutorial-for-a-new-json-file.71687/