lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I was reading Dylan Cuthbert and Nick Trout emails on gaming scripts ("Re:
Re[2]: why no "continue" statement for loops?") and it sparked my
interested, because the script some somewhat simular to the script design,
I'm developing in my game.   However I thought I'd start a new thread,
because this topic is slightly different (and the subject does not match the

I was wondering how others have dealt (plan to deal) with:
* scripted events in their games (or apps)?
* having scripts appear to run along side an app, without the use of

My example is slightly different from Trout, because my game is slightly
different (a space ship shooter game).


/*MissionInfo is a global object, kind like a logbook of missions.*/
MissionInfo:AddMission = "Kill whats-his-name.";

WhatHisName = new BigGuy1;
WhatHisName:x = 1000;
WhatHisName:y = 1000;
WhatHisName:z = 0;
WhatHisName:health = 1000;
WhatHisName:AI = 0; /*Very dumb*/

/* Add unit to the map */

 * This is called when WhatHisName is defeated.
 * It mite do something like change a state of some other objects that exist
in the world
 * ie Killed whathisname.spt
 * //When NoNamePeople are visited, the script "give lost treasure" is run.
 * evVist(NoNamePeople, "give lost treasure");
evKilled(WhatHisName, "Killed whathisname");

 * Activates the one-time only, big-guy-taunt script, which
 * basicly makes WhatHisName say something.
 * Player is a global object.
evNear(Player, WhatHisName, "Big Guy Taunt");


events (ev) and requests (req) are placed on a que. Events only leave the
queue once the event has occured. I guess events could also be programmed as
lua functions, but at present may are hardcoded into the engine.

At the moment, this example calls other scripts when the event occurs (note
I'm using luabind), which is reuse friendly but I'm finding a bother to do.
I'm thinking of perhaps passing a lua callback function to the events.  Is
that possible in lua? Would the functions be destroyed at the end of the
script?  Is there a better way to do this?

Anyway any ideas/suggestions/comments would be welcome, as I'm still in the
design stage of the scripting.

Trout uses threads and Cuthbert uses co-routines (which are simular I
guess). At least for my game in the case of events, I don't think threads
are a very good idea, because there would need to be to may of them.

(I won't repeat the messages here, because it just gets too long.)