[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Best way to pause (sleep?) inside of lua script
- From: Pavel Antokolsky aka Zigmar <zigmar@...>
- Date: Fri, 9 Dec 2005 19:14:20 +0200
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