Why should i use a scripting language???

Started by
15 comments, last by Metaphorically 18 years, 2 months ago
HI I'm developing a game and i need to know why should I use a scripting language? i've seen people talk about them a lot so they're very popular but I dont know what they do in graphics engines. by the way, for an indie 3d game which one should i use: XML or LUA??? THX in advance
Advertisement
Scripting languages allow you to modify your game more dynamically. Information that is determined through scripting can be modified without re-compiling the game, which saves large amounts of time on large games, and also allows third party users to modify the game within reasonable limits.

As for your question XML versus LUA: you don't need to choose. XML and LUA do different things: the former structures information while the second describes actions. Storing information as XML allows you to read and modify that information with ease. Using LUA to describe game actions allows you to modify these actions outside or even inside the game, as well as interact with the game using a scripting console.
Quote:Original post by ToohrVyk
Scripting languages allow you to modify your game more dynamically. Information that is determined through scripting can be modified without re-compiling the game, which saves large amounts of time on large games, and also allows third party users to modify the game within reasonable limits.

As for your question XML versus LUA: you don't need to choose. XML and LUA do different things: the former structures information while the second describes actions. Storing information as XML allows you to read and modify that information with ease. Using LUA to describe game actions allows you to modify these actions outside or even inside the game, as well as interact with the game using a scripting console.


In addition to this, there are some games that even use both XML and LUA together, World of Warcraft for an example.
As to why you should use scripting consider this: If you wanted to you could write an program that converts your data files to header files (i.e. store all the data in predefined constant arrays) and then just include all the header files instead of writing stuff that loads your data from files. Needless to say this is a bad idea, so why do the same for your game logic?
Here's why I'm using Lua: I don't want to create a separate class for every single enemy type in my game. There's going to be a lot of them, and the messiness involved in all those extra classes would get really ugly really quickly. By using scripting, I can just have a single generic "enemy" class that draws its AI from the Lua scripts. Much cleaner, and the ability to tweak the AI without having to recompile is very nice.
Jetblade: an open-source 2D platforming game in the style of Metroid and Castlevania, with procedurally-generated levels
I think Monder really nailed it. Scripting makes it possible to extend and rearrange your game without rebuilding it. It can move a lot of things from build time decisions to run time decisions.
Why use XML *and* Lua when you can just use Lua?

Lua is excellent for describing data, and you can mix code with data! Lua is fast so I wouldn't worry about the performance of using Lua to store data. Also, XML is ugly.

monster = {    hitpoints = 20,    anim = {        idle = "idle.png",        walking = "walking.png"    },    onActivate = function(self, who)                     face(self, who)                     say(self, "Hello there")                 end}


[Edited by - robinei on January 27, 2006 9:37:25 AM]
Quote:Original post by robinei
Why use XML *and* Lua when you can just use Lua?

Lua is excellent for describing data, and you can mix code with data! Lua is fast so I wouldn't worry about the performance of using Lua to store data. Also, XML is ugly.

*** Source Snippet Removed ***


It definitely makes sense to describe data in Lua internally if you're already using it. XML can be useful when you need to share data with other applications. One example would be uploading statistics to a web site.
Post Extant Graphical MUD
I don't know LUA, but XML is made for storing or transfering data, programming languages (and scripting languages) are made for doing things with data. Generally XML would be better for cases where you want to be able to do things to resources outside of the game. I could use another tool to easily load up an XML file and operate on it (maybe I want to see the prices of a bunch of items and adjust those numbers). I could make that work for a script, but it's easier with XML.

Of course there are other good approaches depending on your needs. I'm sure you could use a CSV file which could be copied & pasted into a script for some of the same kinds of processing I described above.

Conversely, there's always &#106avascript and E4X for embedding scripts in your data.<br><br>"You got your data in my script!"<br>"No, you got your script in my data!"<br>(too obscure?)<br><br>
I can't imagine keeping my DATA inside my LUA / ruby scripts ... or my C++ program, or any of that. The reason, because what the hell tools out their know how to parse LUA correctly to present the lists of data to a non-scripter so they can edit them? What tools out their exist to parse these lists and generate lists of the resource files currently used in your project.

NONE!

Plain Old Text
CSV
XML
SQL

These are THE formats to use for your pure data sets.

First, because you can convert between them relatively easily, import them into other programs, and EASILY write editor programs ...

i double dare you to crank out an Animation File Editor tool that edits your LUA script data - in a similar amount of time.


AS for the "why use a scripting language" question. Well the main reasons are:

1) The non-compiled nature often makes it slightly easier to perform small quick changes and see results. Although these benifits are usually overrated because people simply lack the knowledge of how to do this well with compiled code (dynamic plugins).

2) The smaller / simpler nature of the languages often make them easier to teach to non-professional programmers such as level/model designers. So they can be writting the detail logic, in a small sweet langauge using the tools provided to them by the engine programmer.

3) The non-compiled nature of the langauge allows code to build code dynamically. For instance a script written could enter "DoMegaDamage(true)" as the data for a certain action for a certain object. And this could call the exposed wrapper function "DoMegaDamage(true)" In C++ you would have to write a lot of scafolding / building maps and parsing to get a simlar ability.

There are more ... but I'm out of steam

This topic is closed to new replies.

Advertisement