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

Re: Scripting



Ingo Ruhnke wrote:

> Isn't it much easier in such situations to do it in an event driven
> way:
> 
> light_switch = make_light_switch(...)
> 
> # Define a function that should be started when someone hits the light
> # switch
> def on_lightswitch_press ():
>      toggle ( switch_graphic )
>      toggle ( lightbulb_graphic )
>      ...
> 
> # Register the function for the on_press event of the light_switch
> light_switch.on_press = on_lightswitch_press

Well, that doesn't reproduce what my switch does - which is to make
it impossible to turn the light switch off for ten seconds after you
turned it on...but in any case, this was just a silly example - real
scripts get much more complex.

You *can* turn any simple program into a state machine and vice-versa
(you can prove that with math) - but it gets increasingly hard to get
your head around the resulting code as you have more ongoing activities
for your game object.

That's why we program in C and C++ (or Python, etc) instead of writing
all of our programs as state machines using systems like SDL (that's
Specification and Design Language - not Simple Directmedia Layer).

There are "programming languages" (well - I guess you'd call them that)
like SDL which are organized as state machines, (I used to use these
when I was working on software for telephone exchanges) but nobody uses
them for generalized programming because they are hard to use for anything
but some quite special niche applications.  You *could* write a compiler
or a text editor in SDL - but I certainly wouldn't recommend it!

Similarly, I've found that the expressiveness of state-machine (or
event-driven) scripting mechanism becomes very limiting when you want
something complicated - so you end up building more stuff into the
game engine to compensate for that - and thereby end up limiting the
flexibility of the scripting mechanism.

----------------------------- Steve Baker -------------------------------
Mail : <sjbaker1@airmail.net>   WorkMail: <sjbaker@link.com>
URLs : http://www.sjbaker.org
       http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net
       http://prettypoly.sf.net http://freeglut.sf.net
       http://toobular.sf.net   http://lodestone.sf.net