![]() |
|
YAML for Game Configuration Files |
Billybob
Member #3,136
January 2003
|
This will be a kind of review of YAML, mostly to spark interest in this unique file format. When I first heard about YAML, a superset of JSON, I thought it looked quite ugly and cumbersome. That isn't to say JSON, or XML don't look ugly, but it had lots of funky characters and no clear separators. Today, I used it for the first time in my game to define the available weapons and their attributes. For this task, it was pleasant, concise, readable, and easy to work with. Here's a piece-by-piece sample: # Weapons! Defined in YAML! What a crazy language ... very handy, though, and easy to type
A comment! - &hornet_missile_launcher name: Hornet Missile Launcher type: missile cost: 10000 slots: 1 reloadtime: 4 lifespan: 4 image: images/missile1 size: 1.5 damage: [0.3, 1.5] maxturn: 0.04 velocity: 40 This is the definition of a single weapon. - marks the beginning of a new array element. &hornet_missile_launcher is an "anchor", and allows me to reference this weapon later in the file. The rest is an associative array definition. You'll notice the lack of quotes, which aren't needed unless you need to disambiguate. damage is an array of numbers, [0.3, 1.5] Now for the really cool stuff! - <<: *hornet_missile_launcher name: Hornet Missile Launcher MkII cost: 40000 reloadtime: 2 damage: [0.6, 3.0] A new weapon, based on a previous weapon. <<: *hornet_missile_launcher copies all the key:data pairs from the hornet_missile_launcher, allowing me to "extend" it (in some sense). Very neat! The rest of my configuration is just like that, with some parent definitions, and weapons that extend those and tweak little things here and there. Things I Liked
Things I Didn't Like
PyYAML is Broken? That's it! So, go ahead, give YAML a try!
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
It looks a lot nicer than the equivalent XML would, that's for sure. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Elias
Member #358
May 2000
|
I'm using YAML both in my C (libyaml, a bit verbose API but easy to wrap) and Python (just "import yaml", whatever that uses) code and like it. So far I'm not using tags/anchors or types besides the 3 base types so I avoided all the syntax oddities so far. Just nested mappings and sequences using plain/implicit styles. I guess if I don't change to Allegro config files I could start using more of YAML's features. In the C case, one advantage of config files is that C has no standard mapping type but you need something to put the libyaml data into. With config files you get the mapping built in. Quote: To elaborate, it throws an error when you use tabs to separate things.
Well, most of us Python people never use tabs because the style guide advices against using them -- |
SiegeLord
Member #7,827
October 2006
![]() |
Back when I was reviewing YAML I couldn't find an easy to use C library for it, so I didn't use it. Ended up making my own format. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Audric
Member #907
January 2001
|
Looks pretty handy for all those gameplay constants. I generally manage them in Excel and generate C source from a formula column , but this is more direct: it's tweakable without recompiling, even the end-user can "mod" the game somehow. |
|