Need scripting advice for my project

Started by
26 comments, last by Diodor 19 years, 6 months ago
I'm currently working on a game called Hero of Allacrost and I'd like some outside opinions on our scripting methods. I've never done game scripting before, but I have written some small programs in Python and Perl. The game is a 2D RPG and is written in C++ and SDL. Currently, the plan is to use XML configuration files for data storage like character attributes, etc. Additionally we are thinking of using Lua for scripting events like when the game takes control of the character(s). What do you guys think about that? Oh, also we are making the game cross-platform (Linux, Windows, Mac) so we are trying to write the code as platform-independent as possible. Thank you.

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

Advertisement
Sounds good to me. That's how I do a lot of my scripting, with the XML/Script Language combination. You can even customise the Xml by specifying which function is called for a given event. For example, two characters may wish to have different AI scripts...

 // XML  <character name="Gandalf" think="Gandalf_think" class="mage" />  <character name="Thor" think="Thor_think" class="warrior" /> // Script file function Gandalf_think() {   me.examineArea();   if ( me.mana > 100 )   {     me.castSpell( "somecoolspell" );   } } function Thor_think() {   me.examineArea();   if ( me.health > 10 )   {     me.say("raaaa");     me.attackEverythingInSight();   } }
Personally I'd just use the script file for those XML-based attributes too.
I would also be inclined to agree, not knowing the complexity of your level file.
Hmm, well the only scripting I can imagine us doing for now are things like "move the character 4 tiles left on the map, then stop and say something". The reason we are using both is because we started out with XML at another person's advice and we've already gotten a little work done with it. XML is currently being strictly used for storing class attributes, like weapons, armor, map data, etc. There is still enough time to turn around and do configuration files and scripting in 100% lua. Would this be a wise step or does XML provide something that lua does not? Thanks you guys.

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

Quote:Original post by Roots
Would this be a wise step or does XML provide something that lua does not?


Structure.

I'd much rather see my data in nice, cohesive storage container files (such as XML) than have to create everything in script. For starters you can easily load the Xml into your level editor, something which would be difficult to do as easily with just pure script. I prefer Xml for Data and script for logic, but both sides have their merits. I'd say stick with what you have planned, but others will present valid arguments to the contrary which will have as much merit as my method. What it comes down to is personal choice IMHO.
I will put it this way: if you represent your data in XML, you have to write some code to translate from XML to your internal data structures. Whether that's reading a DOM tree or setting up SAX handlers or writing your own parser.

On the other hand, if you represent your data in Lua, you get to re-use your existing Lua integration. If you're gonna be scripting with Lua then Lua will have access to Gandalf and Thor. So why not let Lua handle the initialisation rather than duplicating your effort to let your XML parser access it too?

There's not much difference between these two:
<character name="Gandalf" think="Gandalf_think" class="mage" />
CreateCharacter("Gandalf", "mage", Gandalf_think)

Or you could use a global character table; there are several ways you could approach it in Lua.

If you weren't using Lua, I'd say stick with XML. But since you do plan on using the scripting language, my personal recommendation would be to kill 2 birds with the 1 stone.
Quote:does XML provide something that lua does not?


Yes, you get to write all tags twice.

Quote:Structure.


Lua has structure, and is actually designed to be read and written. Example. That you also get a very powerful programming language for free is that much better.

There are so many things one could do with Lua scripts that XML can't dream of.
I recommened Simkin: http://www.simkin.co.uk/

It's a scripting language integrated inside of XML. I think it would suit your project very well since you already plan to use XML for your data storage.
Quote:Original post by Kylotan
If you're gonna be scripting with Lua then Lua will have access to Gandalf and Thor. So why not let Lua handle the initialisation rather than duplicating your effort to let your XML parser access it too?


A valid point, however I doubt people would create their entire game's level content in Lua, for that you'd need a data container such as a custom file format or Xml. The benefit of Xml is that parsing it is trivial with the plethora of good libraries out there.

Quote:
There's not much difference between these two:
<character name="Gandalf" think="Gandalf_think" class="mage" />
CreateCharacter("Gandalf", "mage", Gandalf_think)


The difference here is that you would need to code up a custom extraction routine to integrate such content in your game/level editor. With Xml you can serialise your internal game structures quite easily, something that would be much more difficult in script alone - especially when your game content doesn't revolve around just scripting.

Quote:Original post by DiodorYes, you get to write all tags twice.


That often seems to be the typical anti-Xml argument, that all tags need entering twice. That's only true if the tag is a container element for other elements. Even then, the amount of time you'd be hard coding the xml will be minimal if you create a tool to edit your content. Xml has the benefit of being hand tweakable too.

Quote:There are so many things one could do with Lua scripts that XML can't dream of.


Xml doesn't pretend to be a scripting language and hence shouldn't have the capability of Lua - unless of course you consider the hideous xml-script hybrid that is "Water".

As ever, I'm inclined to argue the case for using both as I believe they can both be used together sucessfully, however as other have pointed out there are solutions availbale using one or the other, I guess it's up to your development team and game as to which one of the solutions you take.

This topic is closed to new replies.

Advertisement