Tutorial: RPG Maker RGSS – Database

RPG Maker (RGSS)

Tutorial: RPG Maker RGSS – Database

First glance at the 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.

CREATE A RPG::ITEM OBJECT

Let’s make a small test and set data manually:

1-) Open RPG Maker VX and open the Script Editor (F11).
2-) Delete every pieces of code there. Absolutely everything.
3-) Insert a new entry and name it something like ‘My New Script’
4-) Enter 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 do
Graphics.update
end

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

LOAD DATABASE FROM A RVDATA FILE

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.

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

y=0

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

loop do
Graphics.update
end

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 *