[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: LUA and AI
- From: "Ashley Fryer" <lua@...>
- Date: Mon, 27 Mar 2000 13:50:37 -0800
> From: Christophe Gimenez
> Sent: Monday, March 27, 2000 5:05 AM
> 1) we have (will have) 100 functions available for the scripts (ex:
> castOf(who), isPlayer(who))
> 2) we have 10 or 20 incoming type of message (ex: on_hitBy(who),
> Some NPC must be able to be pre-programmed to execute a succesion of
> commands : that's the problem, I have no idea of doing a such thing and I
> don't know of to avoid TONS and TONS of "if then else".
It looks like you are planning to use an event-driven approach, which is
Some additional event-hooks you might use:
Time-based callbacks: on_Time(who)
This allows you to write loops. Each iteration of the loop is another
callback. This keeps the other scripts from hanging while the loop is going
Pathfinding callbacks: on_GoalSuccess(who), on_GoalFail(who)
This calls the object back when the path-finding engine stops moving it.
Animation callbacks: on_AnimationFinished(who)
This calls the object when its one-time animation is finished. This is
important if you want to string a series of animated behaviors together.
Input callbacks: on_KeyDown, on_MouseMove, etc.
This lets objects track user input. If you have NPCs which can have dialog
with the user, you'll need some way for the NPC to get input.
About implementing callbacks... work out a way for each callback to carry
extra data from the object. For example, suppose you would normally
register a pathing callback with:
WalkTo( who, goal_x, goal_y )
Allow the caller to attach optional extra data to the callback with:
WalkTo( who, goal_x, goal_y, EXTRA_DATA )
Then when the callback occurs:
on_GoalSuccess( who, EXTRA_DATA )
The object's data is passed back. There are millions of situations where
this comes in handy, and it can simplify your code.
For the rest of your NPC programming, take a look at finite state machines.
The behavior of your NPCs can be modelled as FSMs, where each state
transition is triggered by one of the on_Events. Lua's tables and
function-objects make it a good language for implementing this.