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
Preliminary Steps
- Open RPG Maker VX and open the Script Editor (F11).
- Delete every pieces of code there. Absolutely everything.
- Create a new entry and name it ‘My New Script’ or a similar title.
- 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)
y=0
for i in 1..8
y+=24
str = database[i].name + " ... " + database[i].price.to_s
my_sprite.bitmap.draw_text(0, y, 240, 20, str, 2)
end
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