Page 1 of 1

Lock Moves

Posted: Thu Jun 26, 2014 5:48 pm
by pink
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.

Re: Lock Moves

Posted: Thu Jun 26, 2014 5:51 pm
by magice
have you tried lock screen?

Re: Lock Moves

Posted: Thu Jun 26, 2014 5:54 pm
by pink
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

Re: Lock Moves

Posted: Thu Jun 26, 2014 6:08 pm
by dunbarx
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