Starting and stopping the move command

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Starting and stopping the move command

Post by dunbarx » Thu Oct 02, 2014 8:56 pm

I often feel like a beginner.

The "move" command seems to be blocking, except when another "move" command is sent. But that is not the issue.

In a new card make three buttons. Name them "player", "stop" and "go". In the script of the card AND the "go" button:

Code: Select all

on mouseUp
   put "go"
   move button"player" to the clickLoc in 3 seconds
end mouseUp
In the "stop" button script:

Code: Select all

on mouseUp
   put "stop"
   stop moving btn "player"
end mouseUp
When you click anywhere in the card, the player button will move to the clickloc. If you click somewhere else while the movement is underway, the new move command takes over. Well and good. But if you try to stop a move by clicking on the "stop" button, it is ignored. In fact, the handler in that button never fires while movement is underway. In fact, it is as if that button did not exist, and the click passed into the card itself.

Click the "go" button. Now the "stop moving" command works like it should by clicking on the "stop" button.

So.

Why, if the "move" command is in the card script, is the handler in the "stop" button ignored? More than that. WHY, during a move, can a new move be invoked right through the "stop" button as if it were not there at all, as if the user clicked on blank space on an open card???? This actually is the case with any object, even if it has a "mouseUp" handler in its script. Any click passes right through during a move event.

As a side note, is there no way to "move with messages"? Only the "stop moving" command (of course, when not invoked if the "start moving" originated in the card script) seems to be able to "interrupt" the motion.

I cannot wait to hear what simple solution there is to that last. But I am perplexed by the first issue.

Craig Newman

Vanceone
Posts: 37
Joined: Sat Dec 15, 2012 7:27 pm

Re: Starting and stopping the move command

Post by Vanceone » Thu Oct 02, 2014 10:18 pm

Hmm. What might be happening is that during the move, all other clicks are handled at the level of the message inheritance that the move command is issued at. If you create, say, a group that's a sibling to the buttons, with the same mouseUp handler, then the stop button works.

But with the card level command, maybe all messages during the move have to originate from that level--card level. And only one mouseUp message is available at card level. Since that mouseUp message is still running, it blocks any other message from lower down in the hierarchy. Probably a bug.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Starting and stopping the move command

Post by dunbarx » Thu Oct 02, 2014 10:38 pm

Hmmm.

If that were true, that the object class where the origin of a message mattered, it would be news indeed. But that still does not answer the question of how a mouseClick can ignore the control over which the cursor was located, as if it did not exist. If the "origin" was set somehow, as you say, then it is not the case that the mouseUp handler in the "transparent" object is blocked; it is not even the case that the message is passed. That handler does not fire. It is as if the control itself is "hidden", but only for mouse events, and not visibly.

It is as if there was a "hide messages" property set in the control. In that case, mouseUp would pass to the card, which at least would be sensible to me, albeit bizarre.

Craig

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Starting and stopping the move command

Post by sefrojones » Fri Oct 03, 2014 3:04 am

I think the answer here is "without waiting"

Code: Select all

   on mouseUp
   put "go"
   move button"player" to the clickLoc in 3 seconds without waiting
end mouseUp
Hope that helps :D

--Sefro

Edit: just found this in the dictionary--
If you specify without messages, built-in messages are not delivered during the move.
But in my experience, it's the exact opposite- If you don't want it to be blocking other messages, you must always "move without waiting"

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Starting and stopping the move command

Post by dunbarx » Fri Oct 03, 2014 6:32 am

You know, I tried that a million times, I thought, and it made no difference. But it does now. I was on mavericks when I fooled around this afternoon, and on OS 6.8 now, where the "without waiting" does indeed permit the stop button to halt the move. The click does not pass through.

Not sure why this is so, since the blurb on "without waiting" seems to have little to do with it.

I will check OS 10.9 tomorrow, and see if I had too little sleep or whether the OS matters. I suspect sleep.

So back to my other question, which actually started this whole thing. Is there any way to invoke any sort of message during a running move? I do not mean by clicking another button. That works fine, so it is actually improper to say the move process is blocking. It is, however, recalcitrant and unresponsive. The problem came up in another thread, where it was desired to detect an intersect while a move was underway. I saw no messages at all in the message watcher while this was taking place. It would have been nice, say, to detect an intersect, or track the loc of the moving object, while it was in motion.

I can easily solve this by setting up a recursive handler, but I was wondering if there was a way use the move process itself, similar to how "mouseMove" works, in that a message is sent every pixel change.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Starting and stopping the move command

Post by dunbarx » Fri Oct 03, 2014 2:18 pm

In Mavericks, the "without waiting" does prevent a click on an object from passing through that object. I cannot imagine why. A variant of a command, invoked from one place, has an effect on another command invoked from another place. And that variant seemingly has no pertinence at all with that effect.

Oh well.

Craig

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1682
Joined: Sat Feb 28, 2009 11:49 pm

Re: Starting and stopping the move command

Post by sturgis » Fri Oct 03, 2014 8:19 pm

While not exactly dealing with the question, this sort of thing is probably easier with a gameloop. Here is the very simple start to a breakout game. (not sure its the most up to date version, but its the one I have so...)

https://dl.dropboxusercontent.com/u/119 ... t.livecode

The game loop code is in the stack, the game code itself is in the card. All it does is give a very simple example of how to move stuff around on a screen and check for collisions. The following stuff is probably necessary for what you want to do.

To translate this to your purpose, you need to know the start position of the object, and where the mouse was clicked. Find the vector, x vector would be px2-px y vector would be py2-py where px2 and py2 are the end location.

At this point, it can be converted to a unit vector. A unit vector is a vector with a length of 1. TO do this..

The unit vector for x would be vx/vLength(vx,vy) And the unit vector for y would be vy/vLength(vx,vy)

vlength is a function that gives the length of the vector you start with. It can be done with this formula sqrt((vX ^ 2) + (vY ^ 2)) -- returns the vector length. You must check to make sure the length of the vector is NOT 0. so you'd want an if statement in there. if vLength(vx,vy) is 0 then set xdelta and ydelta to 0, else set xdelta and y delta to the unit vector values.

At this point you have a way to move your piece. However, to control speed you can multiply your x and y deltas by a factor. SO rather than moving a tiny increment each loop, you are making slightly larger jumps. Tweak as necessary. it should also be possible to keep track of the time the click occurred, and do the math so that you place the object at the correct location for the current amount of elapsed time. In this way, if there is a lag hiccup, your piece still ends up at the right location for the time in question.

As for intersect? That can be pretty complicated, and I personally am waiting for box2d to show up for some of this stuff. :D

Edited to fix the description of vlength

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”