GDE Example: RPG Character Data

Posted September 9, 2015

GDE is super flexible. It helps organize your game data in logical ways. The visual representation of your data helps to associate the data pieces together cleanly - which leads to a more solid game design. Today I’m going to manage Character, Weapon, and Armor data using GDE. If you would like to use these Schemas, download the Data File and import it into GDE or download and import the Google Spreadsheet.

Character Data

I’ve put together a list of common data associated with characters. I want my character to have a name and some hit points. I’ve also added in some data related to combat like attack power and defense. Here’s what my Character data looks like:

Getting access to your character’s data depends on how your schema is defined. All fields become read/write Properties in the generated GDE Data class.

characterData.name;
characterData.defense;
//And so on

GDE loads the data of any associated custom fields and makes those data items immediately accessible. That means any Weapons or Armor associated with a Character item is accessed via its field Property:

characterData.head.name;
characterData.chest.cost;
//And so on

Weapon and Armor Data

I want to give my character some gear. I’ve created some leather items, a sword, and a shield. When I access my character’s data, the associated armor and weapon items are also loaded and available. Having these data items connected, I can easily compute my character’s total defense value with a small method like this:

float totalDefense(GDECharacterData data)
  {
    float total = 0;
    if (data != null)
    {
      total = data.defense +
              data.main_hand.def_delta +
              data.off_hand.def_delta +
              data.head.def_delta +
              data.chest.def_delta +
              data.pants.def_delta +
              data.shoes.def_delta;
    }
    return total;
  }

This becomes cumbersome pretty quickly. Perhaps having explicit fields for each Weapon and Armor isn’t necessary. Instead, I can define an armor list and a weapon list. This way computations can be done with a loop.

If any new slots are added (ex. shoulder guards, amulets, rings, etc.), they can be added to the armor list. Maybe one character can wield three Weapons instead of two, add the third weapon to the Weapon list.

Some characters can have lots of Armor and no Weapons, or max number of Weapons and no Armor. Regardless of how many Weapons or Armor are associated with a particular Character, computing the Total Defense value using the lists account for such differences.

float totalDefense(GDECharacter data)
  {
    float total = 0;
    if (data != null)
    {
      total = data.defense;

      for(int i=0;  i<data.armor.Count;  i++)
      {
        if (data.armor[i] != null)
          total += data.armor[i].def_delta;
      }

      for(int i=0;  i<data.weapons.Count;  i++)
      {
        if (data.weapons[i] != null)
          total += data.weapons[i].def_delta;
      }
    }
    return total;
  }

These examples illustrate one way to organize game data. Your game might require more Schemas and/or different structures. My goal is to get your creative juices flowing. Feel free to download this Data File and modify it to fit your needs. Or download and import the Google Spreadsheet.