[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scripting
On Wednesday 2002-04-17 19:06, Steve Baker wrote:
> 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.
def on_lightswitch_press ():
if (last_pressed < (now - 10 sec))
toggle (switch_graphic)
toggle (lighbulb_graphic)
last_pressed = now
...
> 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.
Note that Ingo is *not* talking about a state machine but about
event-driven code!
--
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)
Results 1 - 10 of about 1,170,000,000. Search took 0.31 seconds
- http://www.google.com/search?q=a