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

Re: Scripting

Katie Lauren Lucas wrote:

> Suddenly, game animations turn into simple scripts:
>   with actor Fred
>     walk forwards 10m 10s
>     say "Hi, I'm Fred."
>     with actor Fred's arm
>       point at Joe
>     say "This is Joe, my sidekick."
> You can't do all this in a single frame loop (easily).

With a state machine, you can. For example, in this situation you would
have the following states for the Fred AI (this would be a lot easier
if I could draw the STD...)

saying sentance 1 (SS1)
moving arm
saying sentance 2 (SS2)

the transitions would be

start -> walking
walking -> not in position -> walking
walking -> in position -> SS1
SS1 -> still talking -> SS1
SS1 -> finished -> moving arm
moving arm -> not poining at Joe -> moving arm
moving arm -> pointing at Joe -> SS2
SS2 -> still talking -> SS2
SS2 -> finished -> end

Of course, it's certain there would have to be more transitions and states
for Fred, but given a state at the start of the frame you can perform an 
action and then update the state, either to a new one or retaining the 
current one depending on whether specific conditions have been met.

>   sleep 600s
>   check ( target1.isDestroyed && target2.isDestroyed )
>     gosub wingame
>   else
>     gosub timeout
> Again, without instructions that can span frames, this cannot be a simple 
> script that's part of the game world.

Actually, this can be done with another state machine, for example:

states: reduce counter,  win,  timeout

The reduce counter state does something like

static int oldsecs;

if(gametime.seconds != oldsecs) {
     counter --;
     oldsecs = gametime.seconds;

the transitions:

start -> set counter to 601 -> reduce counter
reduce counter -> counter > 0 -> reduce counter
reduce counter -> counter == 0
               and target1.isDestroyed
               and target2.isDestroyed -> win
reduce counter -> counter == 0
               and !target1.isDestroyed
               or  !target2.isDestroyed -> timeout

the win and timeout states could then trigger some function in the engine..

  .------{ http://www.starforge.co.uk }-----. .--------------------------.
=[     Explorer2260, Designer and Coder     \=\ P: TexMaker, ROACH, site \
=[___You_will_obey_your_corporate_masters___]==[ Stack: EETmTmTRRSS------ ]