Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / About 'data'
- - By kaBOOM Date 2011-07-30 20:07
So I'm making a game editor completely in Ruby, and its shaping well. I does what I need, the way I want it.
I'm using the marshall module to create my 'data'. My game engine is also made in Ruby and I realize how limited this is. I also would like to explore XNA or switch to the C++ version of Gosu in the future.
So my questions are:
1. Is there a way to use the data I created for my Ruby game in those other engines/languages?
2. I heard of XML, but how would data unique to ruby, like for example a ruby-Hash or a ruby-Symbol, be translated to another language?

Thank You. :)
Parent - - By Trebor777 Date 2011-07-30 21:19
Have a look at Json :p It's a bit easier than xml

And well... for stuff unique to ruby.. don't serialize it or find another way to do it.
Json allows you to create your own serialization (like xml) so you might have to write something specific for the hash or the symbol
and decode that json in your engine. :)
Since it's controlled by you. you know what is what and therefore should be able to create the equivalent data with the other language.
Parent - - By Spooner Date 2011-07-31 01:08
Marshal is great for Ruby-ruby and is extremely optimised for that job. Just useless outside of that domain.

JSON doesn't support symbols - it will just write them out as strings instead. When you read them back into Ruby, you can convert them back into symbols or just be happy with them as strings. Hashes are pretty central to JSON, so I assume that there is at least a way to read them so you can put them into your own data structres in other languages.

I can't say anything good about XML apart from the fact that everyone uses it.
Parent - By meustrus Date 2011-07-31 02:21
XML is better if you have unnamed entries in an array. For example, you can better represent a database of a bunch of items with a similar format using XML and it's got support for tons of metadata to be added later in whatever format you like. However, I doubt that your data is that complicated, so the primary consideration should be what formats are best supported. Can you find a good decoder for your target platform? Also be considering whether you want a long-term data format (going to save it in this format forever), or if you just want to use it to move the data from Marshal to whatever XNA uses. The latter is probably a better idea. If you want the former, you should also be considering what format will be compact and extensible. An interesting format for that goal might be extprot, which is designed specifically for network applications (so it's compact) that expect data formats to change and need to be forward-compatible (so it's super-extensible and extensions don't invalidate old data).

No matter what you do, you'll have to write the encoder yourself to customize the data organization. So, make sure you understand the format you're using; if you're a big web guy you might be comforted by the similarities between XML and HTML, but otherwise JSON is simpler and generally more concise.
Parent - - By erisdiscord Date 2011-07-31 04:25
There's also YAML, which is both easier and more concise than XML and much more powerful than JSON, if you need it to be. Some people find its significant indentation (like Python or CoffeeScript) infuriating, but YMMV. I find the indented block syntax to be extremely readable.

All objects in YAML are represented as either maps, lists or scalars, but they can be tagged to tell the deserialiser what kind of object they should become. This might seem like overkill, but it's extremely useful if you want to dump objects from one language and load them in another. Provided that your YAML library supports custom tags, I mean. The one for Ruby does, but I know some implementations are kind of half-assed.

A bonus feature of YAML is that, as of 1.2, all valid JSON is also valid YAML. This is a one-way relationship and most YAML is probably not valid JSON. :)
Parent - - By kaBOOM Date 2011-07-31 19:07
Thanks to everyone for the replies.
My data is mere  hashes, arrays, symbols, bools and numbers. I don't expect to make it more complex. So I guess Json!?
Parent - By tjbladez Date 2011-08-02 14:56
I would recommend you to use JSON and yajl-ruby gem for parsing.
Up Topic Gosu / Gosu Exchange / About 'data'

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill