header image
 

Writing a scripting language is hard

Zero Day. It’s a rogue-like in VB.NET that David Kidd and I have been creating on-and-off since September/August of last year. It’s based on the essentially-discontinued Heroic Adventure source.

The current prototype is up on Codeplex if you’d like to take a look, but don’t expect anything wonderful – it’s still under heavy development.

The premise is simple: Zombies. People. Surviving. It sounds a lot like Zafehouse, I know, but as I said the format is much like Nethack or ADOM, and the focus is on avoiding your undead oppressors, rather than facing them down.

Dave’s not exactly up-to-date with programming in VB.NET, but he does understand the concepts behind scripting and the like. So, I’ve slowly been migrating hard-coded data into XML files, so he doesn’t have to delve into the source to change stuff like zombie hit points or infection rates.

I realised quickly however that he’d need more power, more control, if we were to ever shift some of the coding weight from me to him. As such, I’ve started work on a basic scripting engine.

When I say basic, I mean basic. It’s only ever going to be used for defining data for specific types, and those types will be limited to items, skills, feats and furniture sets.

Huh? Furniture sets? Furniture is an important aspect of Zero Day – you use it to barricade rooms or create traps. In order to get some realistic setups, I realised I needed a data type that held information on how to construct, say, a dining table with four chairs. That way we can do some random seeding, and create a building that doesn’t look devoid of human occupation.

I played around mentally with storing it as XML, and for the most part it would work, but I wanted to have an easy way to “construct” the furniture setups in a script. Otherwise, the scripter (Dave) would have to mark out X, Y co-ordinates and input them like, well, a machine. Which is not what I wanted.

So, I wrote out a pretend script, and used it as my basis for the interpreter:

objectname=tablechairset
start objects
	h=chair
	O=table
end objects
start set
	..h..
	.....
	h.O.h
	.....
	..h..
end set

The “objectname” var gives us a key in the internal FurnitureSet array we can use to refer to it specifically during runtime. The “object” block lets the interpreter know what the ASCII characters in the “set” block refer to, and the “set” block is a visual representation of the furniture and its placement. Using a fixed-width editor like Notepad, it’s pretty easy to jot out sets without having to worry about co-ordinates – the interpreter figures it out for you.

Now, getting the interpreter to read this information wasn’t hard. Accounting for all the various errors and scripting mistakes one could make while writing the file… well, that’s just a big bucket of headaches looking for a brain to raid. I’ve made a solid start, and most of the major errors are caught and logged, but I know once Dave gets his hands on it, I’m going to be a sad panda.

Oh well, that’s what testing and good documentation is for… right?

~ by Logan on September 4, 2008.

Comments are closed.