Newbie wants to know if one can run two handlers simultaneously

Dar Scott dsc at swcp.com
Sun Dec 8 13:13:01 CST 2002


On Sunday, December 8, 2002, at 09:09 AM, MFitz53 at cs.com wrote:

> I'm attempting to make a simple little shootem up game. I have the 
> basic shoot button that draws a line from one loc to the loc of 
>  button"enemy" and plays a sound effect. What I'd like to do is 
> initiate a handler to move the button around the screen(I have that 
> covered) and use the mouseUp handler from the shoot btn to stop the 
> first handler from running it shoots, sounds off and changes the btn 
> icon. At this point, I have to wait until the first handler finishes 
> running before being able to shoot at a motionless target. I'm making 
> this for a kid just turned 4 years old, but I think even that would be 
> pretty unexciting for him. All ideas are appreciated.
>
You are about to enter the Revolution way of doing real-time 
programming.  It might take a new way of thinking.  It will require 
rewriting how you move the button around the screen.  It will be worth 
the effort.

1.  Limit the time it takes to execute a handler.  Don't wait around in 
handlers.
2.  Use a handler to change the state of your game, start moves and then 
get out of there.
3.  Use game messages to execute the handers:
          A.  Mouse messages (as you are doing)
          B.  "send ... in time" messages (might be new)

Read about "send" and "cancel" commands.  To stop a cycle of sends, use 
cancel or clear a flag.

Here is an example for a flashing light.  It is a simplification of one 
of my first scripts using send.  I put this script in a circle:
*************************
local flashingID

on change
   if backgroundColor of me is red then
     set backgroundColor of me to green
   else
     set backgroundColor of me to red
   end if
end change

on startFlashing
   if flashingID is empty then cycle
end startFlashing

on cycle
   change
   send cycle to me in 333 milliseconds
   put the result into flashingID
end cycle

on stopFlashing
   cancel flashingID  -- don't bother testing for empty
   put empty into flashingID
end stopFlashing
****************************

My "Start" button has this script:
******************************
on mouseUp
   send startFlashing to graphic "Flasher"
end mouseUp
*******************************

The stop button is similar.

You should be able to adapt that to your moving enemy.

Dar Scott






More information about the use-livecode mailing list