lua-users home
lua-l archive

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

Think of it this way:

function x() mpc:say("Hello") end

mud.onTimer(10, x)

John Klimek wrote:
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 =)


On 12/9/05, Pavel Antokolsky aka Zigmar <> wrote:
On 12/9/05, Torsten Karwoth <> wrote:
Let's say I want to have a script do something like this:

npc = CreateNPC("Bob");
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");
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, " .. end )
it can be, for example, extended to handle rooms with masks
   function(who, where)
       if where:name != "dungen_saferoom" then
           local monster = mud:spawn("monster",where)

And so on... I can't even think of all possibilites with such system :)

Best regards,