To use, or not to use XML?

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
I've been tinkering with XML lately, and I'm confident this is your best bet for external data in your games.

What is XML? http://en.wikipedia.org/wiki/XML

How to XML? http://www.w3schools.com/xml/

I can safely say, XML is by far the easiest thing I've used to export and import data.  Why?  Because its sequential, its easy to edit manually, and it works in EVERY PROGRAMMING LANGUAGE once you get your logic correct.

First you can just go write tools in another language you're more comfortable with, like C#, VB.net, visual C++, Java, or another quick-prototype language.  Use these tools to create large amounts of data in a quick prototype environment, then import the data into your game running whatever language at runtime.  Quick prototyping and quick implementation saves time and effort.  If your tools don't exist, and you need to make them, and you need them to work, I would suggest creating an xml model for your data, then recursing your data saving it.

Second, its easy to mod and change the data.  I for one, enjoy tinkering with and destroying games from the file-base to figure out the programmer's mentality while making something.  This makes XML quite awesome for me in fact.  You can build mod support into your games with XML, and use the XML like an easy to use add-on system for your games.  Obviously it would need to retain syntax, and it would only fit a certain set of criteria to be changed.  There would no doubt be tremendous cheating, and tons of people writing mods you didn't intend with it.  However, I feel this would generate more attention towards your projects, just because of its open database capabilities.

I know XML files can get rather bulky, for even small sets of data.  This can be optimized through good coding practices however, chopping lines to a fraction of what they could be if you included all the empty lines.

----------------------------------------------------------------------------------------------

I for one believe XML is a great choice of data designs, and think it should be implemented as a possible feature for the future RPG Maker engines as an alternative output, instead of the default database serialized objects.  

This would allow players to write their own data editing tools for things like custom weapons, custom statistics, whatever.  This would ease the process of including new statistics into the database systems currently implemented in the makers, for the more advanced users, without being confined in the construct entirely, but still wanting to make use of many of the provided tools.

<weapon id="0">

 <name>Stupid Sword </name>

 <custom>

   <customElement1 customAttribute="whatever">

      <customChild1>1232</customChild1>

   </customElement1>

</custom>

"whatever" << $game_weapons[0].custom.get("customElement1").attribute("customAttribute")

1232 << $game_weapons[0].custom.get("customElement1").getChild("customChild1").text.to_i

----------------------------------------------------------------------------------------------
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
I think serialization is a good idea for storing data. There are plenty of them, varying from text-based formats like JSON or YAML to binary formats like the one ruby generates.


If I had a choice between XML or JSON or something, I'd go with something less verbose.


If the data is meant to be purely machine generated and I don't have to look at or touch it myself, I don't really care what is being used.


Sure, XML is more verbose and seems to be something that was meant for computer consumption anyways, but that doesn't seem like a real issue.


For example, I went and grabbed an XML parser and got it to work in RPG Maker: https://github.com/Hime-Works/RMXML


But this is because no library exists for parsing generic JSON or YAML in RPG Maker.
 
Last edited by a moderator:

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
I think serialization is a good idea for storing data. There are plenty of them, varying from text-based formats like JSON or YAML to binary formats like the one ruby generates.

If I had a choice between XML or JSON or something, I'd go with something less verbose.

If the data is meant to be purely machine generated and I don't have to look at or touch it myself, I don't really care what is being used.

Sure, XML is more verbose and seems to be something that was meant for computer consumption anyways, but that doesn't seem like a real issue.

For example, I went and grabbed an XML parser and got it to work in RPG Maker: https://github.com/Hime-Works/RMXML

But this is because no library exists for parsing generic JSON or YAML in RPG Maker.
Yaml seems very cool.

I've honestly never looked into JSON until you mentioned it.  It seems pretty easy to use, and I could probably write a parser for it with a little effort.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
If you are interested in providing a script that will support JSON, I'll request that the kind of JSON parser/generator I am looking for is one that will support ruby object serialization.

For example, suppose you have a Game_Actor class. You might serialize it like this

{ "actors": [{ "Name": "Hime", "class_id": 4 }]}Which is OK, if you were working in an environment where the specifications don't really change.However, given the nature of RPG Maker scripting, anyone can have any arbitrary number of instance variables defined for an object, and you don't want to create a framework that forces every script to add extra code just to support it.

Based on REXML's approach to serialization, I would go with something like this

Code:
{    "object": {        "class": "Game_Actor",        "attributes": {            "name": "Hime",            "class_id": 4        }    }}
Though at this point, to me there's really no significant difference between XML and JSON in the context of RPG Maker.
Code:
<object>  <class>Game_Actor</class>  <attributes>    <name>Hime<name>    <class_id>4</class_id>  </attributes></object>
 
Last edited by a moderator:

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
I'll learn a bit about its syntax and model later on, then fork a repo for it.  Should have it up and running by Sunday, but I doubt it'll fully work.

I'll use a custom parser generator model.  It won't be a lexer though. I don't have the spare time to write a lexer for it, so it'll probably be pretty buggy.

I assume it uses a similar set of terms as XML such as, element, attribute, parent, and child.  It shouldn't be too difficult to learn.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Just saw the edit

"whatever" << $game_weapons[0].custom.get("customElement1").attribute("customAttribute")


1232 << $game_weapons[0].custom.get("customElement1").getChild("customChild1").text.to_i
This is way too verbose lol


It would be better to just load them as ruby objects before letting them be used.


Although when I read through XML vs JSON questions, I'm starting to think XML would be more appropriate.
 
Last edited by a moderator:

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
Just saw the edit

This is way too verbose lol

It would be better to just load them as ruby objects before letting them be used.
Show me the syntax you'd like to use when using an object in Ruby from JSON.

could do like,

tempElement = $game_weapons[0].custom.get("customElement1")

"whatever" << tempElement.attribute("customAttribute").text

Although when I think about it, it would probably need to recurse and then match the proper ID to find the correct customElement1.  In this example though, the data only has 1 customElement1 so it doesn't matter.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Show me the syntax you'd like to use when using an object in Ruby from JSON.
What I mean is

Code:
weapons = XML.parse("weapons.xml")armors = JSON.parse("armors.json")weapons[1] # this is a regular ruby objectarmors[1] # this is also a regular ruby object
Separate the way data is stored on disk from the way it will be used in the application.
 

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
What I mean is

weapons = XML.parse("weapons.xml")armors = JSON.parse("armors.json")weapons[1] # this is a regular ruby objectarmors[1] # this is also a regular ruby objectSeparate the way data is stored on disk from the way it will be used in the application.
so you want like, weapons[0].customElement1 as your object?

Still have to worry about attributes, which can be attached to XML elements as well as the text contained within.  There needs to be some sort of hierarchy supporting the items.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
so you want like, weapons[0].customElement1 as your object?
Suppose weapons.xml contains the entire weapons database.

First we load our database as usual

$data_weapons = load_data("weapons.xml")Now $data_weapons is an array of RPG::Weapon objects just as I would expect if I was using Marshal.loadI can access weapons as I would expect in Ruby

$data_weapons[2].name # returns the name of weapon with ID 2$data_armors[5].params[3] # returns the def value of armor 5.Nothing about my project will change.The only thing that changes is that load_data now will support XML, JSON, rvdata2, and any other serialization format as necessary.

Compatibility with everything? 100%.
 
Last edited by a moderator:

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
What about custom attributes?  Should i build in support for that?

Seems like you want this default implementation, which is fine.  I just want something extra.

First thing I'm going to do is dump a small database of weapons to xml format.
 
Last edited by a moderator:

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
XML is actually the modern standard on data interchange between applications.

Another alternative would be csv, but XML carries more information and is really more flexible and compatible.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
What about custom attributes?  Should i build in support for that?


Seems like you want this default implementation, which is fine.  I just want something extra.


First thing I'm going to do is dump a small database of weapons to xml format.
What do you mean by "custom attributes"?


If a weapon originally starts with


-name


-params


And you wanted to add a new attribute


-durability


?
 

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
I fell asleep, I can work on it now.

<weapon_database object_type="Array" rgss="3">

  <weapon object_type="RPG::Weapon" id="0">

    #todo stuff here.

  </weapon>

</weapon_database >
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Right now, what I do is just use an external .txt file and load database values from there... But of course only if I want the game to be moddable... If I don't want it, then before I release the game I serialize the text file first and make the game load the serialized file instead.
 
Last edited by a moderator:

Funplayer

Self proclaimed sponge.
Veteran
Joined
Oct 9, 2013
Messages
120
Reaction score
35
First Language
English
Primarily Uses
Phew this is gonna take a bit longer than I thought.  I probably can't finish it this weekend, as I am already overworked from this week.  I'll work on it occasionally, but I doubt it'll be finished by Sunday.  I have more pressing matters to attend to.
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Don't push it too hard, take your time. :)   :)
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,583
Latest member
write2dgray
Top