[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Best way to pause (sleep?) inside of lua script
- From: John Klimek <jklimek@...>
- Date: Thu, 8 Dec 2005 20:06:33 -0500
Thanks for the reply!
So basically you're saying to have C++ (or Delphi in my case) call my
lua script several times... I like that idea!
I'm a little confused on the private object part though. Are you
saying I should have C++/Delphi call my lua script function and pass
in an object? Would that be a userdata object? (I'm still confused
on how to share objects between lua and C++/Delphi [see my other
e-mail about that])
Also, do you have any class diagrams or any kind of layout plan for
the classes in your program? I'd like to see some kind of outline of
the object managers you have and how everything works... (without
looking through thousands of lines of code to figure out which classes
are doing what... [in a general sense])
Thanks again!
On 12/8/05, Torsten Karwoth <agonizer@t-online.de> wrote:
> Hi John,
>
> perhaps you may look at the game "fish-fillets" (http://fillets.sf.net)
> for hints.
>
> > 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.
>
> AddEvent() would then call the function at the given time (or if the time
> is in the past) and REMOVE the function from the list when the fn gets
> called.
>
> Pseudocode:
>
> BobsFunction(Object)
> if not Object.event or Object.event == 0 then
> Object.npc:Delete(); -- or whatever to free workspace
> return;
> end;
> local e, npc = Object.event, Object.npc;
> Object.event = e + 1; -- inrement private event number
> if e == 1 then
> npc:Say("Hello everybody in the room!");
> AddEvent("BobsFunction", os.time() + 5, Object); -- call in 5s
> return;
> elseif e == 2 then
> npc:Say("Hello again, foobars!!!");
> AddEvent("BobsFunction", os.time() + 10, Object); -- call in 10s
> return;
> end;
> npc:Say("I'm being really annoying now!! Bye :(");
> npc:Delete(); -- no re-adding
> end;
>
>
> This way you also could switch functions for 'Bob'.
>
> HTH,
> Torsten
>
>