Making Buttons Solid

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

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Making Buttons Solid

Post by d.m.holdawayGA2553 » Wed Mar 21, 2012 10:05 pm

hello,

i have been researching " Intersect " and the use of layers in this but i am still drawing blanks.

i have a number of buttons on the screen which move about but they can move over each other, what i would to try and do is make them solid so you cant move them over each other.

does that make sense.

i would rather be told what to go and read and work it with out trial and error than someone post the answer.
Last edited by d.m.holdawayGA2553 on Wed Mar 21, 2012 11:48 pm, edited 1 time in total.

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

Re: Making Buttons Solid

Post by dunbarx » Wed Mar 21, 2012 11:45 pm

Your buttons already move over each other, right? Did you mean "so you CAN'T move them over each other"?

If so, please write back. There are easy ways to do this. How do your button move now?

Craig Newman

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: Making Buttons Solid

Post by d.m.holdawayGA2553 » Wed Mar 21, 2012 11:47 pm

yes Craig thats what i ment, i am really sorry for getting that mixed up i have corrected the post.

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: Making Buttons Solid

Post by d.m.holdawayGA2553 » Wed Mar 21, 2012 11:53 pm

I move them with

on touchMove pId, pX, pY
if the cType of the target is "shape" and sMoving is true then
set the loc of the target to pX, pY
end if
end touchMove

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: Making Buttons Solid

Post by d.m.holdawayGA2553 » Thu Mar 22, 2012 12:12 am

i have just found a good example

http://revonline2.runrev.com/stack/281/ ... ic-Control

i will have a look at this.

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

Re: Making Buttons Solid

Post by dunbarx » Thu Mar 22, 2012 2:35 am

Thought so. Anyway, you don't make the movng objects "solid". Rather you control them; herd them like sheep. Make them do your bidding.

Try this: on a card place three buttons. Name one "starter". Name another "mover". Name the third "theTarget". Place the btn "mover" far to the left of btn "theTarget", but on the same horizontal line. Put this in the script of btn "starter":

Code: Select all

on mouseUp
   put the loc of btn "mover" into startLoc
   repeat until intersect(btn "mover",btn "tTarget") = "true"
      get the loc of btn "mover" 
      set the loc of btn "mover" to item 1 of it + 1 & "," & item 2 of it
      wait 2
   end repeat
      set the loc of btn "mover" to startLoc
end mouseUp
Please try to understand what each line does. This is homework. Experiment and play around. Can you change the speed in more than one way? The starting position? Does it matter where you place the button "starter"? Can it be between the other two?

The example above is just a bit verbose, for readability. Can you shorten it?.

Write back with the completed homework.

Craig Newman

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Making Buttons Solid

Post by Dixie » Thu Mar 22, 2012 3:56 am

Yes Sir, Mr Newman... Where should I put your apple ?... :D

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

Re: Making Buttons Solid

Post by dunbarx » Thu Mar 22, 2012 5:48 am

Dixie.

In The Marx Brothers movie "Horse Feathers", Harpo gives the professor a watermelon.

Soon after, that professor was thrown out of his own classroom.

Craig

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: Making Buttons Solid

Post by d.m.holdawayGA2553 » Thu Mar 22, 2012 10:44 am

ok.

well

Code: Select all

put the loc of btn "mover" into startLoc
takes the current location of the button "mover" and puts it into a variable

Code: Select all

repeat until intersect(btn "mover",btn "theTarget") = "true"
      get the loc of btn "mover" 
      set the loc of btn "mover" to item 1 of it + 1 & "," & item 2 of it
      wait 2
this code makes the button mover move until it hits the target, but i am unsure about this line

Code: Select all

 set the loc of btn "mover" to item 1 of it + 1 & "," & item 2 of it
its doing the moving part but i dont understand

Code: Select all

to item 1 of it + 1 & "," & item 2 of it

Code: Select all

wait 2 
is the time it takes for mover to hit theTarget

then upon hitting it, its breaks the loop and sets the mover button back to the location

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Making Buttons Solid

Post by dave_probertGA6e24 » Thu Mar 22, 2012 11:34 am

Just for reference:
a 'loc' variable consists of two components - x and y position - eg. "100,200"

Using the 'get' command will get the value of a variable/function/whatever and put the result into a special variable named 'it' (see the dictionary for more info on this)

Using 'chunk' access notation ( 'item 1') the various parts of the loc (inside the 'it' variable) can be used - item 1 of it would return '100' from the loc example above - item 2 returns '200'!

To set the loc of something you need to provide both the x and y - comma separated text - "444,555".

So the line:
set the loc of btn "mover" to item 1 of it + 1 & "," & item 2 of it

basically creates a new 'loc' from the old loc by breaking it down into it's component parts, adding a value to the 'x' part (item 1) and reconstructing a new loc from those modified parts.

Wow, that is a long an laborious way of explaining this :) :) But I hope it helps someone.

Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: Making Buttons Solid

Post by d.m.holdawayGA2553 » Thu Mar 22, 2012 11:45 am

no thats really good!

so if i was to say

Code: Select all

set the loc of btn "mover" to item 1 of it + 1 & "," & item 2 of it + 1 
it would move diagonal

that would make the loc 1,1

so if i wanted to move it quicker i could just change item 1 and item 2

Code: Select all

set the loc of btn "mover" to item 1 of it + 10 & "," & item 2 of it + 10 

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

Re: Making Buttons Solid

Post by dunbarx » Thu Mar 22, 2012 5:47 pm

YES! You are on your way. Congrats.

And yes, again, two ways of changing the rate are to modify the "wait" duration or to increase the offset of the loc parameters. There are even others.

I might have been more helpful with that one line if I wrote:

set the loc of btn "mover" to (item 1 of it + 1) & "," & (item 2 of it) --better readability

How about making the "mover" button bounce around the card at random til it hits the target? If you can do this you should have most of the mental tools you need for your game. A word of warning: be careful that you limit the playing field to the rect of the card or your button will disappear off an edge. You may want to make a button that manually relocates it if it gets lost. Do you know how to terminate a running script? (command-period)

Good luck, play all day, write back.

Craig Newman

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: Making Buttons Solid

Post by d.m.holdawayGA2553 » Fri Mar 23, 2012 12:17 am

cool i like this!

what if my buttons are in a group, how would i use intersect then?

thanks for the command-period heads up

that is most helpful!

thanks again for the advice and the tips

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

Re: Making Buttons Solid

Post by dunbarx » Fri Mar 23, 2012 2:34 am

Keep going.

Intersect will use the overall extent of the group, regardless of the locations of its component objects, and use that as the basis for returning a value. Try it. Make a group with two objects located diagonally. The group will be a rectangle.

Where is that random game? An exercise like this will advance your learning dramatically.

Craig Newman

d.m.holdawayGA2553
Posts: 81
Joined: Mon Jan 09, 2012 4:48 pm

Re: Making Buttons Solid

Post by d.m.holdawayGA2553 » Fri Mar 23, 2012 4:34 pm

i have started on the random bouncing homework.

but could you explain
Intersect will use the overall extent of the group
i am not sure what you ment by that.

Post Reply