Jump to content
  • Advertisement
Sign in to follow this  
Roots

Need scripting advice for my project

This topic is 5191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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();
}
}


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!