Lock Moves

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

Lock Moves

Post by pink » Thu Jun 26, 2014 5:48 pm

I'm moving a bunch of buttons around the screen. Whether or not a button moves depends on if the space it is moving into is empty.
The below script works in terms of properly selecting and moving the buttons to where they should be, but i would like all of the moves to be done at the same time.
I tried using "lock moves" but each button still moves individually when the handler is called.

Code: Select all

on moveAtom
     put "p16,p17,p18,p1,p2,p3,p4" into tRow1
     put "p15,p29,p30,p19,p20,p21,p5" into tRow2
     lock moves
     --take each "pair" of cells from above for comparison
     repeat with xx=1 to 7
          put item xx of tRow1 into tDestiny
          put item xx of tRow2 into tStarting
          --if there's a value in B, but nothing in A, then move B to A
          if gHex[tStarting]["atom"] is not empty and gHex[tDestiny]["atom"]  is empty then 
               put gHex[tStarting]["atom"] into gHex[tDestiny]["atom"] 
               put gHex[tStarting]["value"] into gHex[tDestiny]["value"] 
               put empty into gHex[tStarting]["atom"] 
               put 0 into gHex[tStarting]["value"] 
               put gHex[tDestiny]["atom"]  into tAtom
               put top of graphic tDestiny+24 into tTop
               put left of graphic tDestiny+24 into tLeft
               move button tAtom to tLeft,tTop
          end if
     end repeat
     unlock moves
end moveAtom
if it helps to get an idea of what I am doing, this is a game similar to Threes or 2048 where you are picking a direction and all the items in your grid get shifted over.
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Lock Moves

Post by magice » Thu Jun 26, 2014 5:51 pm

have you tried lock screen?

pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

Re: Lock Moves

Post by pink » Thu Jun 26, 2014 5:54 pm

I didn't use lock screen because I still wanted the movement to be seen.

Anyhow, through more trial and error I came across the missing piece, I added "without waiting" to my move command. This, along with the lock moves command, did the trick.

Code: Select all

               move button tAtom to tLeft,tTop without waiting
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10335
Joined: Wed May 06, 2009 2:28 pm

Re: Lock Moves

Post by dunbarx » Thu Jun 26, 2014 6:08 pm

Pink.

Bravo.

This has come up before. All should know this detail, noted in the dictionary in the comments section, though NOT in the syntax section. The "without waiting" is a key component of making this command work as you might expect.

Craig Newman

Post Reply