Skip to main content
gamedev.net
🔒 Locked

Determining your scripting needs....

Started by TheWanderer 6 replies 1.7k views
Original Post
TheWanderer
TheWanderer
Hey guys... I'm currently developing a turn-based strategy game and I am thinking of adding in a scripting language to it. I do not, however, know much about he choices that are available out there. The first question that pops into ones head is (you might groan here) "which language is the best"?. Given that the answer is "it depends", I wanted to ask a more general questions. What should I look for when looking for a scripting language? In general, what are the things I should keep in mind when considering my choices? Reason I ask is because I am used to evaluating "normal" languages (look at efficiency, syntax, etc...). Do the same things apply to scripting languages? IS there anything else? The above question is just to get a general feel for the subject. To be more specific about my particular situation I wanted to use a scripting language for both data and parts of the game logic. (does not have to be the same language for each... I noticed an article using XML for data and Java for scripting) In the game, there are many units (combatants) which differ slightly (yet not trivially) from each other. For example, one might move faster than other units while another has the ability to ambush. The rules also can be altered by a unit having having this or that item; e.g. this unit usually is slow to attack, but if it has "the flaming quill of Ixiblat", it always strikes first. Therefore the game has to be very flexible. Any suggestions for that particular scenario? Thanks for reading :)
Kylotan
Kylotan
Quote:
Original post by TheWanderer
The first question that pops into ones head is (you might groan here) "which language is the best"?. Given that the answer is "it depends", I wanted to ask a more general questions.

What should I look for when looking for a scripting language? In general, what are the things I should keep in mind when considering my choices?


"It depends."

Quote:
I noticed an article using XML for data and Java for scripting)


I'll bet you $10 that article was written by a web developer. :P

Quote:
Any suggestions for that particular scenario?


No, not really. :|

They're called languages for a good reason. They're collections of terms and grammar but the end result is pretty much the same. What is said in one can be translated easily into another; maybe a word changes here and there but the end result is the same. Nothing you've described requires any specialist feature so it's all down to personal preference - ie. syntax, performance, and library availability tradeoffs, just like any other language.

My flippant answer might be:
- Angelscript or Gamemonkey if you're the only one using the script and speed of binding is paramount;
- Python if designers or beginners are to use this language, and powerful functionality and simple syntax are more important than (lack of) security or performance;
- Lua if neither of the above are true.
TheWanderer
TheWanderer
Quote:
Original post by Kylotan
"It depends."


;P

Quote:
Original post by Kylotan
I'll bet you $10 that article was written by a web developer. :P


Indeed... I believe it was Evolutional. I would be curious to hear what your thoughts are on the use of XML in that capacity?

Quote:
Original post by Kylotan
My flippant answer might be:
- Angelscript or Gamemonkey if you're the only one using the script and speed of binding is paramount;
- Python if designers or beginners are to use this language, and powerful functionality and simple syntax are more important than (lack of) security or performance;
- Lua if neither of the above are true.


What exactly does "binding speed" entail?

Also, are there any particular features in the languages which are important to game development?

Thank you for the answers, BTW :)
evolutional
evolutional
Quote:
Original post by TheWanderer
Quote:
Original post by Kylotan
I'll bet you $10 that article was written by a web developer. :P


Indeed... I believe it was Evolutional. I would be curious to hear what your thoughts are on the use of XML in that capacity?


Yes, it was (and still is) me. I've been sidetracked with some other (important) project and still fully intend to finish it off. The aim is to try and separate the world declaration and the scripting logic as much as possible. I feel that XML is perfect for declaration (eg: structure) and scripting is perfect for logic, so to me it makes perfect sense to separate the two (yet have them linked). One opposite theory to this is that you can use your scripting language (eg Lua) to acheieve the same result. With the article I'm trying to present an interesting method that will allow declaration of levels and game content with standard XML editing tools - something like this is useful if you don't want to code your entire level in script.

As for how the final product will be using XML and javascript, take a look at how a HTML file embeds javascript with it's DOM interfaces - you won't be far off the mark. Every entity exports various event hooks which can have a script attached to them. When the game is running, these various scripts are called as necessary.<br><br>Here's some example source...<br><br><!--STARTSCRIPT--><!--source lang="cpp"--><div class="source"><pre><br><span class="cpp-comment">// alien_scripts.js</span><br>function alien_update( alien )<br>{<br> <span class="cpp-keyword">if</span> (alien.isAngry)<br> {<br> alien.attack( Game.CurrentLevel.Player );<br> } <span class="cpp-keyword">else</span> <br> {<br> alien.moveRandomly();<br> }<br>};<br><br><span class="cpp-comment">// Parameters passed implicitly by game (see script API)</span><br>function alien_collide( collider, alien )<br>{<br> <span class="cpp-keyword">if</span> ( collider == Game.CurrentLevel.Player )<br> {<br> alien.isAngry = <span class="cpp-keyword">true</span>;<br> }<br><br> alien.health -= <span class="cpp-number">10</span>;<br><br> <span class="cpp-keyword">if</span> (alien.health <= <span class="cpp-number">0</span>)<br> alien.die();<br><br>};<br><br><br><br></pre></div><!--ENDSCRIPT--><br><br><!--STARTSCRIPT--><!--source lang="cpp"--><div class="source"><pre><br><?xml version=<span class="cpp-literal">"1.0"</span>?><br><script file=<span class="cpp-literal">"alien_scripts.js"</span> /> <!-- import script file --><br><script file=<span class="cpp-literal">"level_1_Script.js"</span> /><br><br><level id=<span class="cpp-literal">"level_1"</span> onUpdate=<span class="cpp-literal">"level_update(this);"</span>><br><br> <alien health=<span class="cpp-literal">"100"</span> posX=<span class="cpp-literal">"10.0"</span> posY=<span class="cpp-literal">"0.0"</span> <br> onUpdate=<span class="cpp-literal">"alien_update();"</span> onCollision=<span class="cpp-literal">"alien_collide();"</span><br> onSomethingElse=<span class="cpp-literal">"Game.Console.print('hello from the alien');"</span> /><br><br></level><br><br><br><br></pre></div><!--ENDSCRIPT-->
TheWanderer
TheWanderer
Quote:
Original post by evolutionalYes, it was (and still is) me.


Well, I'm glad I did not have you mixed up with someone else :).

Quote:
Original post by evolutionalThe aim is to try and separate the world declaration and the scripting logic as much as possible. I feel that XML is perfect for declaration (eg: structure) and scripting is perfect for logic, so to me it makes perfect sense to separate the two (yet have them linked).


I think you are correct in your idea. Using XML (or some other data difinition language) seems to be a much easier way of storing the information needed by a game, rather than harcoding it in either a typical language or a scripting language.

I was thinking along the same lines for my game, although I had no candiate for the language until I saw your article. (Speaking of which... Are there any other languages well suited for that tack?)


Quote:
Original post by evolutional
One opposite theory to this is that you can use your scripting language (eg Lua) to acheieve the same result. With the article I'm trying to present an interesting method that will allow declaration of levels and game content with standard XML editing tools - something like this is useful if you don't want to code your entire level in script.


Is the use of these tools the main thrust behind the articles? Is there any advantage to separating logic and data (other than cleaness of your code).
evolutional
evolutional
We all have our own subjective opinions about what is 'best', so I'll give mine. Most of my game projects ended up using XML to store the level data simply because it got tedious having to create tools to make them. You can grab something like XmlNotepad or XmlSpy and you effectively have a very basic data/level editor at your disposal. I also like the structured approach that XML gives you, meaning it's fairly trivial in actually getting the data into your program with a third party parser. XML isn't the solution to all problems, but I thought my use of it is fairly interesting. As someone pointed out to me before, Lua can also be used as a declaration language; effectively a list of createAlien( xpos, ypos, whatever ) statements. I've seen some work of another site member that uses Lua like this with a lot of success, so really my method is just another way of doing things. However, like I said - I believe it'd be simpler to write level editing tools that use XML rather than having to write routines to generate the scripts to save the datafiles (although loading would be pretty similar).

As for languages that could be coupled with this approach, I chose javascript mainly because it'd be familiar to web developers and mirrors the way the web works in that respect - but you could so very easily drop in Lua, GameMonkey, Angelscript or any of the other popular languages.<br><br>By the way, if you're checking out GameMonkey - make sure you look at my <a href="http://www.evolutional.co.uk/gamemonkey">microsite</a> which contains a few tutorials (will add more soon) and a beta of my gmBind template binding library. [/shameless_plug]
Kylotan
Kylotan
Quote:
Original post by TheWanderer
What exactly does "binding speed" entail?

Also, are there any particular features in the languages which are important to game development?


Binding speed is just the term I use to describe how quickly you can go from having an existing program and a scripting language package to having that scripting language work effectively as part of your program. Generally speaking the closer that the scripting language is to C/C++, the quicker and easier it is for a programmer to bind it to a game (providing that game is in C/C++), but the tradeoff will usually be a slightly more primitive interface that may not take full use of the language's benefits.

As for particular features... the short answer is no, not really. Since these languages are all Turing complete then you can achieve anything in one that you can in another. The long answer probably revolves around your personal preferences and the target audience (does it need to be quick to code, quick to execute, quick to debug, etc). Since you don't seem to have a real idea of what you need other than 'a scripting language', I really recommend that you just pick one based on syntax and have a go with it.
ggs
ggs
Quote:
Original post by TheWanderer
Indeed... I believe it was Evolutional. I would be curious to hear what your thoughts are on the use of XML in that capacity?

XML is great as it is a textbased format which there are a large set of tools which can be used to manipulate & create arbitary XML structures. It isnt the actual format, but the tools the format has.

However, XML is very parsing intensive, and you have the choice of using loads of memory or tightly integrating your application logic into the XML parsing layer.

XML is not going to be friendly on load times, and if you need to parse the same XML document more than once I would question your design.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.