lua-users home
lua-l archive

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


Hello, I'm trying to figure if I could use LUA as a scripting language for a
part time game project.
If the system was event driven I would not even ask for that, but events are
only a part of the problem because the hardest stuff is building a "goal
oriented" system.
I know (a little) LUA and done several test just to see the way it can be
embedded in a C++ application, it's easy (at least, the bare bone stuff is
easy).

Until last week I was considering to design my own language. I think I can
do it and I've done several tests too using CocoR. But it's a hard work,
will take a lot of time and I would appreciate not to reinvent the wheel...
So, I would like to share my thoughts with you and maybe find a solution to
use LUA

Here is the pseudo language I would need (this is only an example, a draft,
you name it) :

Sub Init
RunGoal("JohnAtWork1")
EndSub

Goal John_AtWork1
Conditions
TimeBetween(9,22)
Not GoalRunning(John_AtWork2)
Prerequisite
MoveTo(X,Y) // Point1 into the inn
Actions
RandomNoise()
Wait(30)

Goal John_AtWork2
Conditions
TimeBetween(9,22)
Not GoalRunning(John_AtWork1)
Prerequisite
MoveTo(X,Y)	// Point2 into the inn
Actions
RandomNoise()
Wait(10)

Goal John_LightOn
Triggers
TimeChange(18)
Prerequisite
MoveTo(X,Y) // The inn, in front of the torch
Actions
Activate("InnWhiteHorseLight1")

Goal John_CloseTheInn
Triggers
TimeChange(22)
Prerequisite
MoveTo(X,Y)	// in the inn, in front of the door
Actions
MoveTo(X,Y)	// outside of the inn in front of the door
DeActivate("InnWhiteHorseLight1")
DeActivate("InnWhiteHorse")
DeActivate("InnWhiteHorseDoor")
RunGoal(John_AtHomeMakeSomeFire)

Goal John_AtHomeMakeSomeFire
Prerequisite
MoveTo(X,Y)	// in his house in front of the mantlepiece
Actions
Activate("JohnHomeFire") // make some fire
MoveTo(X,Y)	// in front of the dinning table
RunGoal(John_AtHome)

Goal John_AtHome
Conditions
TimeBetween(22,24)
Prerequisite
MoveTo(X,Y)	// in front of the dinning table
Actions
Animate("Eat")
Wait(5)
Animate("Drink")
Wait(20)

Goal John_AtHomeSleep
Prerequisite
MoveTo(X,Y) // in front of his bed
Animate("YAWN")
Conditions
TimeBetween(24,9)
Actions
Animate("SLEEP");

Goal John_GotoWork
Triggers
TimeChange(9)
MoveTo(X,Y)	// outside of the inn, in front of the door
Activate("InnWhiteHorse")
Activate("InnWhiteHorseDoor")

Goal John_GetPaid RunOnce
Trigger
CharGiveObject("Player","Money")
Prerequisite
MoveTo(X,Y) // in front of the church (front of door)
Actions
UseObject("ChurchKey","ChurchDoor")
Say("So, have a look and talk to fooman")

----------------------------------------------------------------------------
-------

As you can see each goal is eligible when a trigger condition is fullfilled
(is TRUE), if eligible the preriquisite statement is executed until
statisfied, then the actions are executed.

This morning I had an idea.
I thought I could (with LUA) adopt a naming convention like that and declare

function Goal_foo
end
function Trigger_Goal_foo
end
function Prerequisite_Goal_foo
end

So, as the host app can know what are the globals declared in a script it
would be possible to define a goal the way I want.
Of course, the stuff behind the scene would be handled by the host app (what
goal is running, what trigger to call, and so on).

The only point for which I can see a solution is stepped execution of
actions. What I mean is that actions (for fonctions calls) like "UseObject"
last a certain amout of time (in a 3D real time world).

If I design my own virtual machine I could execute the opcodes this way :
- execute all the opcodes on one shot
- BUT don't step to the next statement when the current one is a function
call (an action). Until the function call as not return a ACTION_TERMINATE.
At each turn, the state of the virtual machine is frozen, so the same action
is call is made again.

Another good point is that I would be able to control the amount of time
that can be spent inside vm code execution.

So, NOW, could I do to have the same stepping execution with LUA ? I don't
want to use the tricks about using the debug hook...
Is there a full LUA solution for that ? (using tables or whatever)...

Thank you


___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com