The “Custom Database” is an extended database that is stored with your save file. It stores any additional objects created during the game, and any changes to the “Game Database” which contains the default data when a game is initialized.
The purpose of this custom database is to provide a way to modify the database on the fly without affecting any other instance of the game as the data files are supposed to be read-only.
This script handles all save/load issues that you might encounter with custom data, so any changes you make to the database persist across the same save file, but do not affect other games.
Script: download here
The database files are, by default, stored in the Data folder in your project. In the scripts, they are global variables prefixed with the word “data_”, such as “$data_actors” or “$data_skills”. Most of them with the exception of System and MapInfos are arrays, indexed by object ID.
Each array can be treated as a table, such as the Actors table or the Weapons table.
This script builds on the default design and supports the following operations
- Read – get objects from the database
- Create – add new objects to the database
- Update – update existing objects in the database
Deleting objects is not supported.
You will be working with the CustomData module provided in the script most of the time. You are encouraged to use the methods provided in case the internal workings of the script change.
The database holds RPG objects, not Game objects. If you are unsure what attributes are available, you can refer to them in the Help Manual.
Nothing new is provided here. Simply access the data arrays as usual. The important thing to note here is that you should only access the database through the data files.
$data_actors # get actor 1 $data_skills # get skill 32 $data_weapons # get weapon 94
You can create new RPG objects and add them to the database. The CustomData module provides a set of “add” methods for each table. Each “add” method takes your object and assigns an ID to it, returning the ID to you. It is up to you what to do with the ID.
The process for creating a new object is as follows:
- Instantiate a new RPG object
- Set the attributes
- Add it to the database
Example: create a weapon called “Moon Blade” with wtype_id 1, icon 147, and +20 atk bonus. Add it to the database, and then add one to your party.
w = RPG::Weapon.new w.name = "Moon Blade" w.icon_index = 147 w.wtype_id = 1 w.params = [0, 0, 20, 0, 0, 0, 0, 0] id = CustomData.add_weapon(w) $game_party.gain_item($data_weapons[id], 1)
If successful, you should see the new weapon in your inventory when the script is called.
You can update existing RPG objects in the database. The CustomData module provides a set of “update” methods for each table. Each “update” method takes your object and updates the appropriate record in the database using the object ID as the key.
The process for updating an object is as follows:
- Get a reference to your object
- Make changes to your object as needed
- Tell the database to update it
Example: Given that the “Moon Blade” from above was assigned ID 61, we would like to upgrade it by changing its name to “Moon Blade +1”, increase its atk power by 50, and giving it a new icon 389.
w = $data_weapons w.name = "Moon Blade +1" w.params += 50 w.icon_index = 389 CustomData.update_weapon(w)
If successful, the moon blade from before should now have the updated data
The Custom Database provides support for the following objects