[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua state
- From: Jamie Webb <j@...>
- Date: Fri, 7 May 2004 10:54:51 +0100
On Friday 07 May 2004 09:01, Krzysztof Jakubowski wrote:
> Let's say we have functions defined in C:
> Say(txt, speech) -- play sound file 'speech' and show message 'txt'
> on the screen. Then stop lua until the message is finished
> Wait(time) -- stop lua for some time
>
> look at this:
How about this syntax, which can be acheived directly in Lua:
script = Sequence "script_name" {
Say("Hey Fox Four, any hot women out there in Aldebaran?", "1.ogg");
Say("I don't think I want to meet any women they got out there.",
"2.ogg");
Say("You don't like women with four legs and two heads? Man -", "3.ogg");
Say("One more word and you two are gone from my flight.", "4.ogg");
Wait(5);
Say("Freedom to all, GE electronic countermeasures detected.", "5.ogg");
Say("Right boys, it's gonna get warm in a minute. No sleeping, no
schlepping.", "6.ogg");
Say("Roger.", "7.ogg");
Wait(3);
CreateSomeEnemyObjects(...);
Say("Freedom to all, strong group signature growing fast at eighty
degrees, ETA forty.", "8.ogg");
Say("Copy. Sounds like you could use a radical radar upgrade there.",
"9.ogg");
}
Now the Say and Wait functions return closures which actually do the saying or
waiting. The Sequence function combines all those closures into a state
machine. You keep your variables in a table which is passed among the
closures and can be serialised to save the game state. You can define
additional operations on these sequence machines which allows them to be
composed in more complex ways, variations on the machine structure designed
for dialog, etc. The key here is to think declaratively rather than
procedurally. You get a lot more flexibility that way.
-- Jamie Webb