• Register

What makes this particular game special? First of all the battle system. The standard battle system from RPG Maker VX ACE is pretty basic and has been around for a while. Actually ideas about novel combat system was what started development of the game. During the course of the game you will encounter various creature that you can capture and then summon during combat. Before going into battle it is crucial to evaluate the composition of enemy troops select the creatures you will summon and position them at strategic points. Each creature has its own unique role and abilities making a plethora of potential combinations for your small army. Secondary it is various deadly traps. Believe me they will keep you at the edge of your sit. Some of them will require speed and mastery of control, while others will challenge your intellect and common sense. The traps were created specifically for this game

  • View media
  • View media
  • View media
  • View media
  • View media
  • View media
Post article RSS Articles

Relations in RPG Maker VX ACE

Client Side Coding Tutorial

Hello guys and girls. My name is Iren_Rin, I am the author of “Trapped Summoner”. This article is about RPG Maker VX ACE and Ruby code. Perhaps you wouldn’t be very interesting if you work with another engine or language. But code examples are pretty simple so the article would be useful for you. In the article I will answer the question “Why does RPG Maker store relations as integers?”.

If you have examined RPG Maker source code you already know how its database is constructed. It is arrays of Ruby objects who are serialized with Marshal.dump and stored in separate files in Data directory. These arrays are restored with Marshal.load on each game load. Game saving process acts the same way, game data is serialized and stored in save file and is restored by the same way on save loading.

How does serialization work? In very simple words Marshal.dump stores an object class name and its instance variables. Marshal.dump also stores the same data for each instance variable of the object. The serialization goes recursively, in depth. Recovering goes in opposite order. Marshal.load takes the stored object class, initializes new object and assigns all stored instance variables. The key words here - NEW object.

Why am I talking about it? Because it is the direct reason why RPG Maker stores relations as integers. Let’s write some code.

We make Skill class with two instance variables to store skill name and damage:

class Skill
  attr_accessor :name, :damage

We initialize new spell and store it in skills array. It is our analog of RPG Maker’s $data_skills array. I am going to add nil element as the first element of the array for “realism”:

skill = Skill.new 
skill.name = 'Fireball'
skill.damage = 100

$data_skills = [nil, skill]

We make a Player class with array of skills

class Player
  attr_accessor :skills 

  def initialize 
    @skills = []

Let’s initialize a new player and add the spell to his @skills array.

player = Player.new
player.skills << $data_skills[1]
player.skills.include? $data_skills[1] #=>true

It is looks pretty good so far. Let’s serialize $data_skills and player and restore them back.

stored_player = Marshal.dump(player)
stored_skills   = Marshal.dump($data_skills)

restored_player = Marshal.load(stored_player)
$data_skills  = Marshal.load(stored_skills)

And now the problem:

restored_player.skills.include? $data_skills[1] #=> false
restored_player.skills[0] == $data_skills[1] #=> false
restored_player.skills[0].name #=> Fireball
restored_player.skills[0].damage #=> 100

It is unexpected result on the first glance. Despite the fact player’s spell has the same parameters as the spell from database array they are not equal. The answer is pretty simple. But let’s understand how Ruby checks equality. You can redefine “==” method for any object but by default ruby checks equality of #object_id. That means that object a is equal to object b if a.object_id is equal to b.object_id. When we did Marshal.load Ruby made new objects for us. We stored the same spell object (in $data_skills and in player.skills), but on restoring Marsha.load restores two new objects with different object_id. That’s why they are not equal. But equality is half of the devil. Suppose we want to change damage of the spell from 100 to 200.

$data_skills[1].damage = 200
restored_player.skills[0].damage #=> 100

We changed only instance in $data_skills array and left player’s spell untouched because objects are different. So what we can do with it? The same what RPG Maker do! We shouldn’t store an objects as relation, we should store its index in appropriate database array. There would be only one “alive” instance - the one in database array. In any place we want to use the object we should get it with the index. There is how we can write it for our Player class:

class Player 
  attr_accessor :skill_ids

  def initialize
    @skill_ids = [] 

  def skills
    @skill_ids.map { |id| $data_skills[id] }

player =  Player.new
player.skill_ids << 1
player.skills.include? $data_skills[1] #=> true

stored_player = Marshal.dump(player)
restored_player = Marshal.load(stored_player)

restored_player.skills.include? $data_skills[1] #=> true

$data_skills[1].damage = 300
restored_player.skills[0].damage #=> 300

That’s it for the first article. I really hope somebody would find it interesting and useful. If there will be some comments I can write one more article about how to load any simple Ruby gem or use debugger to speed up development.

Add file RSS Files
Trapped Summoner Demo v 2015-12-20

Trapped Summoner Demo v 2015-12-20


Demo version of Trapped Summoner includes battle system, traps and other functionality like class selection, language selection etc.

Iren_Rin Creator

Support us on greenlight Steamcommunity.com

Reply Good karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.