deletion while moving...

Dar Scott dsc at swcp.com
Fri Dec 19 02:13:47 EST 2003


On Wednesday, December 17, 2003, at 05:14 PM, Igor Couto wrote:

> Guess what?: it still DOES NOT DELETE!!!
>
> What gives?
>
> I feel like I'm overseeing something basic...
>
> Any help GREATLY appreciated!

What you are overlooking is not that basic; it has to do with some 
subtle characteristics of the 'move' command.

I believe the 'move' command without "without waiting" and without 
"without messages" is like a 'wait with messages'.  The move happens 
while execution freezes at that point.  During the move the script of 
the handler is considered to be still executing.

However, an object in whose script a handler is executing, even nested 
in calls, cannot be deleted.  It turns out that this happens.  In this 
case, a button click is almost always executed in the middle of the 
move _command_, not just in the middle of the move process.  It is as 
if the move command called the mouseUp.

This can also cause very strange behavior and strange delays when you 
have multiple objects doing this kind of thing.

Here is my recommendation:  Consider changing your cycling handler to 
the moveStopped message and use "without waiting".  The exact method 
depends on your goal.  Here is an illustration off the top of my head 
and without testing:
******

local moving = "false"
local direction = "300"

on mouseUp
    startMoving
end mouseUp

on startMoving
   if not moving then
       put 300 into direction
       move me relative direction,0 in 15 seconds without waiting
       put "true" into moving
   end if
end startMoving

on stopMoving
    put "false" into moving
    stop moving me
end stopMoving

on moveStopped
   if moving then
       put - direction into direction
       move me relative direction,0 in 15 seconds without waiting
   end if
end moveStopped

*****

The delete button script would be something like this:

****

on mouseUp
    send "stopMoving" to button "animatedBtn"
    delete button "animatedBtn"
end MouseUp

****

This might take some fiddling to make work.

Note that in this style, a handler executes for only a very short time. 
  I think that this is a good guideline for avoiding this kind of 
trouble.

Dar

****************************************
     Dar Scott Consulting
     http://www.swcp.com/dsc/
     Programming Services
****************************************



More information about the use-livecode mailing list