Ideas for using XML or Lua
I want to use a scripting language for my AI and I'm a little unsure how I should go about doing this. For one, should I use XML or Lua? What is easiest / most intuitive way to integrate the interpreters into C/C++/ObjC code?
Talyn Wrote:I want to use a scripting language for my AI and I'm a little unsure how I should go about doing this. For one, should I use XML or Lua? What is easiest / most intuitive way to integrate the interpreters into C/C++/ObjC code?
Lua is probably the EASIEST interpreter out there to get running.
Check the wiki for how tos and the IRC channel.
Use Lua not XML
Lua can be used for data just like XML
and Lua is easier to edit and read and fast to parse / load.
Example Lua from my game engine..
http://www.bang2d.com
-- MAKE A NEW LEVEL OBJECT
level_1 = {
-- INIT THE LAYER DATA
layers = {
-- LAYER
{
-- SETTINGS
name = 'BACKGROUND',
type = 'NORMAL',
scroll_rate_x = 1,
scroll_rate_y = 1,
tile_size_x = 64,
tile_size_y = 64,
-- DATA
tile_data = {
{ ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', },
{ ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', },
{ ' ',' ','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01',' ',' ', },
{ ' ',' ','F01','F01','F01','F01','FMC','F01','F01','F01','F01','F01','F01','F01','F01','F01',' ',' ', },
{ ' ',' ','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01',' ',' ', },
{ ' ',' ','FMC','F01','F01','F01','FMC','F01','F01','FLF','FLF','FLF','F01','F01','F01','F01',' ',' ', },
{ ' ',' ','FMC','FLF','FLF','F01','F01','F01','F01','FLF','FLF','FLF','F01','F01','F01','F01',' ',' ', },
{ ' ',' ','F01','FLF','FLF','FLF','F01','F01','F01','F01','F01','F01','F01','F01','F01','F01',' ',' ', },
{ ' ',' ','F01','F01','F01','F01','F01','FMR','F01','FMR','F01','F01','F01','F01','F01','F01',' ',' ', },
{ ' ',' ','F01','F01','F01','F01','F01','FMU','F01','F01','FMD','F01','F01','F01','F01','F01',' ',' ', },
{ ' ',' ','F01','F01','F01','F01','F01','FMU','F01','F01','FMD','F01','F01','F01','F01','F01',' ',' ', },
{ ' ',' ','F01','F01','F01','F01','F01','FMU','FML','FML','FML','F01','F01','F01','F01','F01',' ',' ', },
{ ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', },
},
}
}
}
In my software, I actually use both.
For configuration, I use xml and a dtd. I can type up the configuration in a program like Oxygen. Once I'm done then I verify what I wrote against the dtd. So, this will show any errors. Also, the dtd lets the xml editor present an interface -- now I don't have to write a gui program to interface with my config files. So, its data driven.
Otherwise, for scripting within in my game I'm using Lua. Its light weight and easy to integrate. Very easy to put in hooks for your routines. I could of used Lua for configuration too. Lua documentation is confusing.
You might want to consider SQLite. I think thats pretty cool too. Just make a data base with tables etc. Might be another good config alternative. Though, the only part that makes me nervous about this approach is multiple threads and getting a corrupt database lockup on startup.
For configuration, I use xml and a dtd. I can type up the configuration in a program like Oxygen. Once I'm done then I verify what I wrote against the dtd. So, this will show any errors. Also, the dtd lets the xml editor present an interface -- now I don't have to write a gui program to interface with my config files. So, its data driven.
Otherwise, for scripting within in my game I'm using Lua. Its light weight and easy to integrate. Very easy to put in hooks for your routines. I could of used Lua for configuration too. Lua documentation is confusing.
You might want to consider SQLite. I think thats pretty cool too. Just make a data base with tables etc. Might be another good config alternative. Though, the only part that makes me nervous about this approach is multiple threads and getting a corrupt database lockup on startup.
A much nicer alternative to XML: http://json.org/
ThemsAllTook Wrote:A much nicer alternative to XML: http://json.org/
Bases on Javascript can be used from any lanuage.
The example I posted above is basically like JSON.
Almost looks the same even.
Both of these go to show how out side fo DTDs etc theres not a hell of a lot of reason to stick with XML.
XML is hard for people to write, and hard for computers to parse (even if a library makes it look easy to the programmer). Any time you're thinking of using XML, you probably shouldn't be
As the input to a Cocoa data converter for my game, I actually use Apple's property lists, in particular the old-style ASCII format (yes, the deprecated one. Sorry) when writing by hand. No libraries needed, directly in Foundation objects, rather easy to write, there's a graphical editor - I like it.
XML is a markup language, not a scripting language. Lua is my scripting language of choice most of the time, since it is so simple to embed. C# is a much better language though, and higher-performance, so I'm still toying with the idea of implementing Mono instead, if I can ever find the time.

