lua-users home
lua-l archive

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


Thanks again for all of the replies everybody!

Zigmar, can you explain what you mean when you say "register a
function itself, not its name"?

For example, in your lua code you have:
mud.onTimer(10, function() mpc:say("Hello") end )

It looks like mud is a table filled with cfunctions.  Am I right? 
Furthermore it looks like you are calling this cfuntion (whereever
mud.onTimer is mapped) and passing it a lua function parameter.  Am I
right on this as well?  If so, how would you declare the cfunction
onTimer that would handle this input?  Delphi examples are preferred
but C/C++ will work too =)

Thanks!!





On 12/9/05, Pavel Antokolsky aka Zigmar <zigmar@gmail.com> wrote:
> On 12/9/05, Torsten Karwoth <agonizer@t-online.de> wrote:
> > > Let's say I want to have a script do something like this:
> > > (pseudo-code)
> > >
> > > npc = CreateNPC("Bob");
> > > npc:SetRoom("main");
> > > npc:Say("Hello everybody in the room!");
> > >
> > > SLEEP(1000);  -- Sleep for one second
> > > npc:Say("Hello again!!");
> > >
> > > SLEEP(1000);  -- Sleep for another second
> > > npc:Say("I'm being really annoying now!!");
> > >
> >
> > Well, _I_ would implement this as:
> >
> > npc = CreateNPC("Bob");
> > npc:SetRoom("main");
> > AddEvent("BobsFunction", os.time(), { npc, event=1});
> >
> > where 'AddEvent' would be a function wich would take three arguments:
> > A function name to call, the time WHEN to call the function, and a
> > 'private' object.
> Just an idea - I think it will be much more convinient and flexible to
> register a function itself, not its name. Then, you can write
> something like:
>
> -- Every ten seconds
> mud.onTimer(10, function() mpc:say("Hello") end )
>
> This system can be also extended to handle different events. For example:
> mud:onRoomEnter("main", function(who,where) npc:say("Hello, " .. who.name) end )
> it can be, for example, extended to handle rooms with masks
> mud:onRoomEnter("dungeon_*",
>    function(who, where)
>        if where:name != "dungen_saferoom" then
>            local monster = mud:spawn("monster",where)
>            monter:attack(who)
>        end
>   end
> )
>
> And so on... I can't even think of all possibilites with such system :)
>
>
>
> --
> Best regards,
> Zigmar
>