kurt miller's homepage
( My development journal and homepage has moved to a new system here: kurtm.flipcode.com )

Key Value Scripts 08 November 2003, 4:32PM

While working on my game, I implemented a simple key/value script loader without really thinking twice about it. I've noticed only recently how incredibly useful they are in practice, especially given their simplicity. If you have a more sophisticated scripting system implemented in your project, they're not really neccesary. For the rest however, they're extremely handy when it comes to avoiding hard-coded values and increased organization. In its simplest form, I'm just refering to a text file with lines made up of key = value. The loader loads them up, and lets you access data like getValue("key"). No magic, nothing novel, but very useful. A lot of people are using fancy XML parsers and the like these days, but personally I favor simplicity and readability. The only complexity I added to my loader was support for nested scripts. The main advantage is not having to write specific loaders for types/keys. The flexibility provided naturally by a key/value pair reveals itself as you find it fits more and more scenarios.

I use std::map for my particular implementation. A couple example scripts from my game project are below:

map01.kvs:

; this script specifies the properties of a map;

script:map01
{
    scale  = "2000"
    map    = "map01.gamemap"
    skybox = "skybox_overcast.kvs"
}

skybox_overcast.kvs:

; overcast skybox

script:skybox
{
    name = "overcast"
    size = "10"
    
    t_front  = "overcast_front.png"                
    t_back   = "overcast_back.png"
    t_left   = "overcast_left.png"
    t_right  = "overcast_right.png"
    t_top    = "overcast_top.png"
    t_bottom = "overcast_bottom.png"
            
    script:sky_plane
    {
        name    = "clouds"
        texture = "clouds.png"
        delta_u = "0.1"
        delta_v = "0.0"
        
        src_blend = "BLEND_ONE"
        dst_blend = "BLEND_ONE"
    }
}








Complete List Of Journal Updates:
  • Auto-Terrain Texturing (15 November 2004, 12:27PM)
  • On Orientation Interfaces (14 November 2004, 7:30PM)
  • Basic Terrain Generation (10 November 2004, 4:39AM)
  • Engine Tool Interface (07 November 2004, 2:37AM)
  • Render Buffer Ranges (02 November 2004, 5:15AM)
  • wxWidgets GUI Toolkit (29 October 2004, 2:31AM)
  • Generic Rendering Interfaces (27 October 2004, 6:55PM)
  • Source Documentation with Doxygen (25 October 2004, 6:34PM)
  • Signs of Life? (25 October 2004, 5:14PM)
  • Key Value Scripts (08 November 2003, 4:32PM)
  • Octrees for Potential Colliders (01 November 2003, 4:09PM)
  • Flexporter and Game Levels (31 October 2003, 12:14PM)
  • New Project and More Updates (31 October 2003, 6:14AM)
  • HSL Color Space (07 May 2003, 6:14AM)
  • A Couple Graphics Books (02 December 2002, 5:12PM)
  • Texture Detail Using Colored Triangles (02 November 2002, 3:26AM)
  • Voxel Mesh Creation and Rendering (27 October 2002, 11:30AM)
  • Development Journal (25 October 2002, 10:57AM)



  • Site Contents Copyright (c) 2002-2004 Kurt Miller. Please do not reprint this jibberish anywhere.