[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Game oriented usage of Lua?
- From: "Vincent PENQUERC'H" <vpenquerch@...>
- Date: Fri, 28 May 1999 09:03:46 +0100
> I hope people don't mind that this was so specific... I
> realize that many
> people on this list are not interested in adventure game
> engine internals
> and certainly haven't played Grim Fandango. But I'd like to
> hear how other
> people have used Lua as well!
I'm new to Lua, and thus I may not have taken the best path, but
here is the way I used it:
I have several 'entities' in my game, most of them are items
or characters. Each of them, when created, creates a Lua table
representing it.
This table is composed of data and function fields. The only
data field known to C++ is set at the object construction, and
is the 'owner' field, initialized to the C++ pointer to the
object (a Lua userdata). All other data fields are left to the
use of Lua scipts.
The functions depend on the type of table. For a character, for
example, several functions are predefined and have special
meaning for the C++ game engine: 'onthink', 'ontalk', 'onhit',
'ondeath', etc... Whenever something happens which correspdonds
to one of those, the function is called (if defined).
This way, default behavior is executed if the function is not
defined in the table, and it can be overriden by defining the
function.
for example, 'onthink' is called regularly for a character to
determine which actions are to be taken by it.
The default behavior, if no 'onthink' function is defined in its
table, is to stay immobile, and to fight if attacked, etc. But
if the function is defined, the default behavior is not executed
(or it can be by being explicitely called by this override, as a
kind of inheritance) and the specific 'onthink' function is exevuted
in its place.
This set of predefined Lua table functions have at hand a set of
registered C functions that access everything's necessary
(examples include CharFindPathTo, CharFindPathAround, CharAttack,
CharSay, CharStopMoving, CharGetInventory, etc...). some of these
basic bricks are very low level (CharGetXPos) but my goal is to
write high level ones (CharScheduleActions(action1,action2...)
so that Lua functions has a broad range of powerful bricks to
use, thus making script writing quick and efficient.
Hope I did not put this in a too confuse way ;)
Like I said, I came with this after several days of thinking,
and it was tweaked three or four times before getting to this
final design, so it may or may not be a good way to do.
Vincent Penquerc'h