lua-users home
lua-l archive

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


Derek Wong wrote:

> offer me some advice at implementing cooperative multitasking with
> lua scripts. I'm an amateur programmer so please excuse me if I've
> used the wrong terminology.

I'm not sure multitasking is what you need. I think it is hard to keep
track of running scripts, synchronize their data accesses, they may need
to interact with one another... lots of problems. Look below.


> is that clear? I'm not even sure that's clear to me, but I think
> that's what I want.

Hmm.... it sounds like you've some design work to do ;)


> ps: for those that want the nitty gritty details, I'm working
>     on a mud, and I'd like to use lua scripts to respond to
>     player actions.
>     ie: A player says Hi to a Monster...
>         the Monster's script gets called and performs the following...
>         Monster says 'Hello.'
>         [pause for a second, during which time other stuff is going on]
>         Monster says 'You look yummy' and proceeds to attack player.

Now that's clear ;) I think you should implement finite state machine and
update its behaviour repeatedly. It's easier now to implement interaction
between monsters, because each can 'look around' and interact with any
object that is 'near' enough by simple method call. I'm not very
proficient with AI programming but how I would see this is: let the
monster have several 'preferences' (rules on which it makes its
decisions). You call its 'performAction' method repeatedly (it can be done
by separate thread if you're using threads). During this call monster
'looks around', 'makes decision what to do' and does it (it can be
perfectly well just sitting where it was before because nothing
interesting happened).
Designing this kind of stuff _well_ is a quite advanced topic and you
should definitely look for tutorials/docs out there (a search engine
wouldn't be that bad idea). You may take a look at gamasutra.com or
unreal.epicgames.com. UnrealScript controls monster behaviors in Unreal
and it is THE source you should read and understand - others are using
UnrealScript as reference in designing their own scripting engines (for
example CrystalSpace project).

Bye,
Max


--
------ Max Gilead  (gilead@linart.krakow.pl) ------
| http://3d.linart.krakow.pl/OfficinaArtificialis |
---------------------------------------------------
{EOF}