RGSS: Database

RGSS2 has a bunch of modules prefixed with ‘RPG::’ and they play a crucial role. They contain all the basic data structures of RMVX that are used for the database.

As an example, let’s pick the data class for Items. We obtain it via the RPG module: RPG::Items.

If you look carefully inside the RGSS2 Manual, you will notice that RPG::Items is derived from RPG::Usable and RPG::BaseItem. Take some time to study the manual because it’s the only way to create successful RGSS code.


Preliminary Steps

  1. Open RPG Maker VX and open the Script Editor (F11).
  2. Delete every pieces of code there. Absolutely everything.
  3. Create a new entry and name it ‘My New Script’ or a similar title.
  4. Copy and paste the following piece of code in the editor.
my_item = RPG::Item.new()
my_item.name = "Nintendo Switch : "
my_item.price = "$299.99"

str = my_item.name + my_item.price

my_sprite = Sprite.new()
my_sprite.bitmap = Bitmap.new(544, 416)
my_sprite.bitmap.draw_text(0, 0, 544, 416, str, 1)

loop { Graphics.update }

Of course it’s not really practical at this point, but I’m certain you’re getting the picture.

Load database from rvdata

In fact, we can do something better. We can use the built-in function load_data(filename) to load database entries directly from Items.rvdata2 in the project folder. Well, ‘rvdata2’ files are actually data collected from the database such as Skills, Items, Actors, etc.

So, the next snippet will show how load_data(filename) can be used. P.S. The filename path is relative to the .exe file of the project folder.

database = load_data("Data/Items.rvdata2")
my_sprite = Sprite.new()
my_sprite.bitmap = Bitmap.new(544, 416)


for i in 1..8
str = database[i].name + " ... " + database[i].price.to_s
my_sprite.bitmap.draw_text(0, y, 240, 20, str, 2)

loop { Graphics.update }

As you can see, we listed the 8 first elements stored in Items.rvdata2, displaying each item name and pricing.

There are many other similar data structures, feel free to explore them in the official documentation (press F1 while RPG Maker is open).






Leave a Reply

Your email address will not be published. Required fields are marked *