Level Scripting ? Or just Level Loading ?

Started by
7 comments, last by KahunaCoder 13 years, 6 months ago
Hi everybody,

Working on the level loading in a demo i'm preparing, i used up to now to load the game levels trough xml files (the xml snippet indicates positions of different buildings). But i'm wondering if i should do it trough a Lua script.
But i cannot really find any extra value by doing it so rather than just a simple xml file.

Do you have any idea about it ?

Thanks !
Advertisement
XML is a great way of doing it, and the XML can refer to lua files where needed. (IE: a game object that does some action).

you can use Lua to parse your XML level file and create the level that way. IMO the scripting interface should be the only place where you create your level.

------------------------------

redwoodpixel.com

Quote:Original post by AsifFromBrussels
Hi everybody,

Working on the level loading in a demo i'm preparing, i used up to now to load the game levels trough xml files (the xml snippet indicates positions of different buildings). But i'm wondering if i should do it trough a Lua script.
But i cannot really find any extra value by doing it so rather than just a simple xml file.

Do you have any idea about it ?

Thanks !


Or to twist the statement on it's head. I cannot really find any extra value by doing it so rather than just a simple Lua file :)

Why would i use a Lua script to read the xml file ???
To construct the level is the job of the game engine based on the design indicated in the xml file (or the lua script). Isn't it ??

So i use either an xml file or a lua script but i don't get i should use both !?

Than a last question ; what do we really call level scripting ? Is loading the level from an xml file also considered level scripting ?


Thanks guys !
To try to explain this better...
You are already using XML to load a level. The XML file is describing the physical state of the level. It has all the objects that you need to load, and any information that goes with it. But it is static data that does nothing.

You would add ontop of this a layer of Lua, or any other scripting language to represent the dynamic states of the game objects.
You could have scripts that represent the Update() for your enemy. The script contains all the runtime code to decide what actions the enemy should take.
You could have scripts that describe effects, like multiple part explosions that spawn debris and then set a game flag like "passage open".

Lua lets you move logic out of your game code and into script code. Scripted code is better for iteration time, since you can edit the scripts on the fly instead of having to recompile and restart your game to see the changes. While a small project may have a really short recompile->restart cycle, even a 30sec cycle feels slow compared to being able to edit something and see the changes the moment you hit "save".
If you were going to use lua as your data definition language, then you could do things like use a function to return a property for an entIty. This function could use math.random to vary the entity every time it is loaded. You can't do that with XML as easily. Also, lua is less verbose that XML for data definitions. Just my 2 cents.

Cheers,

Bob

[size="3"]Halfway down the trail to Hell...
I guess this is more particular depending on your current setup, but. If your game engine has a Lua API, meaning you can create game objects and and receive events from your engine IN Lua, then you can do a lot more than just define what a level should look like.

XML is universal in the sense that it is brain dead simple to parse both from C# or Lua (using LuaXML). C# allows you to build XML visually using winforms or WPF, so if you REALLY want to talk level design, you could write an editor that generates xml and feeds it to your Lua API, which would then construct not just your level, but your game logic and game rules as well. You COULD define your level in lua, but its much harder to automate such a thing than it would be to automate generating the xml. make sense?

------------------------------

redwoodpixel.com

You can compare it to coding your game logic in c++ vs lua. Xml is more powerful like c++, it is "type-safe" , you can use XSD to define structures, you can use XSLT to transform etc.. On the other hand lua is more simple and much easier to use.

In my game I use XML to save "engine" data and lua to save level data. To load lua levels is by far more easier than doing the same thing with xml. Simple example:
-- lua level readertriggers = {}trigger_counter = 0trigger = function( _input)  -- do some checking  if _input==nil or _input.id==nil or triggers[_input.id]~=nil thnen    ... error logging    return  end  -- transfer data  triggers[_input.id] = _input  trigger_counter = trigger_counter + 1end


A simple level file could look like:
trigger {  id = "start_trigger",  on_trigger = my.functions.doTrigger,  delay = 1000,  message_on_trigger = "Hello world!",}trigger {  id = "goal_trigger",...
If all you're concerned about is loading up a level and creating various objects through XML, I think that's good enough. However, whenever I hear "Level Scripting", I think about the level's functionality. Things such as events and level logic. Those can be scripted using Lua.

This topic is closed to new replies.

Advertisement