detecting movement finished
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
detecting movement finished
Hi,
I have things moving around the screen, at different speeds and taking different times to finish moving. Each object starts its movement via a send message to a movement function, and the message can be delayed. That is, I end up with a load of objects moving, and starting and finishing their movement at different times.
Once all movement has stopped, I need to grab these objects into a group.
The problem is, I can't put them into a group while they are moving, well, I can, but that stops the movement.
So I need a way of finding out when things have stopped moving.
Is there any message generated when all movement has stopped, or some flag somewhere ?
Thanks.
I have things moving around the screen, at different speeds and taking different times to finish moving. Each object starts its movement via a send message to a movement function, and the message can be delayed. That is, I end up with a load of objects moving, and starting and finishing their movement at different times.
Once all movement has stopped, I need to grab these objects into a group.
The problem is, I can't put them into a group while they are moving, well, I can, but that stops the movement.
So I need a way of finding out when things have stopped moving.
Is there any message generated when all movement has stopped, or some flag somewhere ?
Thanks.
Re: detecting movement finished
Assuming you are using the move command for this?
If so, just to test I put the following script in a card and added 2 buttons. (once set up, just execute the moveit command from the msg box)
So it seems to me (again, if you're using 'move' to do your movements') that a) when you queue something up to move you add its name to a list.
whenever movestopped is triggered, you remove its name from the list. When the list is empty, all moves are done.
The same can be done if you're using 'set' to position things. You most likely have a condition that is met when the move is done, so a) if you again track a list of currently moving objects and then b) remove each object from the list when your condition to stop motion is met, remove it from the list. Once the list is empty, all moving items must have been stopped, so you do whatever it is you need to do under that circumstance.
If so, just to test I put the following script in a card and added 2 buttons. (once set up, just execute the moveit command from the msg box)
Code: Select all
on movestopped -- this is called each time an object finishes its move
-- puts a line delimited list of objects that have finished moving into the msg box
put the short id of the target && return after msg -- as you can see, the target (the object that was moved) is recognized.
set the topleft of the target to the topleft of this card -- just moves the buttons back to the top
end movestopped
command moveit
put empty -- clears msg box
lock moves -- lock moves so all moves are concurrent
move button 2 to the bottomleft of this card without waiting -- tell the stuff where to move to
move button 1 to the bottomright of this card without waiting
unlock moves -- begin moving
end moveit
whenever movestopped is triggered, you remove its name from the list. When the list is empty, all moves are done.
The same can be done if you're using 'set' to position things. You most likely have a condition that is met when the move is done, so a) if you again track a list of currently moving objects and then b) remove each object from the list when your condition to stop motion is met, remove it from the list. Once the list is empty, all moving items must have been stopped, so you do whatever it is you need to do under that circumstance.
Re: detecting movement finished
Thanks for this - that does the trick.
It occurs to me that one could also just increment a move counter each time an object is told to move, and on each movestopped just decrement the counter. Zero would mean everything has stopped.
Thanks for the answer, it has shown me the way forward.
It occurs to me that one could also just increment a move counter each time an object is told to move, and on each movestopped just decrement the counter. Zero would mean everything has stopped.
Thanks for the answer, it has shown me the way forward.
Re: detecting movement finished
A variation would be to have each item put it's name after a variable as it completes the move or it's counter goes to zero. Then you have everything collected and ready to group or deal with as you need to.
Kelly
Kelly
Re: detecting movement finished
Thanks Kelley !
What I'm unclear about concerning handlers is the following :
A : do stuff
B : start a load of objects moving over different times...
C : do stuff
D : do more stuff
E : even more stuff
and a handler for movestopped. The movestopped handler can do what is being suggested here, but what if a move stops between steps C and D ? The handler is invoked, but upon completion, does execution continue with step D ?. What if step C is a loop - does the loop get interrupted ?
What I'm unclear about concerning handlers is the following :
A : do stuff
B : start a load of objects moving over different times...
C : do stuff
D : do more stuff
E : even more stuff
and a handler for movestopped. The movestopped handler can do what is being suggested here, but what if a move stops between steps C and D ? The handler is invoked, but upon completion, does execution continue with step D ?. What if step C is a loop - does the loop get interrupted ?
Re: detecting movement finished
if C is a loop and you WANT it to get interrupted you can set a flag in movestopped that will stop the loop. If the loop is a repeat type make sure you have a wait with messages in there somewhere.
Depending on the outcome you want you can use the flag for c, d, e to determine if you want them to execute or not. Hard to give better solutions without a more concrete example of what you're working towards but hopefully this will get you farther along the way.
Depending on the outcome you want you can use the flag for c, d, e to determine if you want them to execute or not. Hard to give better solutions without a more concrete example of what you're working towards but hopefully this will get you farther along the way.
Re: detecting movement finished
Sorry, but I'm still struggling with this.
Basically, when a bunch of objects have all stopped moving, I want to group them.
So I can use what has been suggested here, which is to handle it in a movestopped handler, which on its final invocation can do the grouping. The problem I am having is how to then carry on with the rest of the program, without having the rest of the code piled into the movestopped handler. That is, I need the equivalent of a GOTO statement at the end of the mousehandler, so the rest of the program can continue. Can't get my head round this !
Basically, when a bunch of objects have all stopped moving, I want to group them.
So I can use what has been suggested here, which is to handle it in a movestopped handler, which on its final invocation can do the grouping. The problem I am having is how to then carry on with the rest of the program, without having the rest of the code piled into the movestopped handler. That is, I need the equivalent of a GOTO statement at the end of the mousehandler, so the rest of the program can continue. Can't get my head round this !