Intersecting Buttons

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

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Intersecting Buttons

Post by marcelloe » Wed Mar 05, 2014 9:14 pm

This is what i have figured out so far while playing around. I can get this script to work somewhat right until it exceeds its limit. I don't know how to send the buttons that are intersect to a new location. I know how to move 1 button to a specific locations, but not sure how to handle multiple buttons.

Code: Select all

on preOpenCard
   repeat with i = 1 to 10
      set the loc of button ("b" & i) to random (the width of this stack) , random (the height of this stack)
   end repeat
   repeat with i = 1 to 10
      if intersect (button ("b" & i), button ("b" & i)) then
        preOpenCard
   end if
   end repeat
end preOpenCard

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: Intersecting Buttons

Post by KennyR » Wed Mar 05, 2014 11:16 pm

Okay...I didn't take the time to read ALL the posts here so I apologize if I am completely off here...but I understand you want to move multiple buttons around the screen and are having trouble? I am currently doing this and using the existing locations of the buttons and having them switch places....here is an idea..


Code: Select all

---Card Script---
Global vLocation
on preOpenCard
repeat with x=1 to the number of btns in group "someGroup"
put the location of btn x of group "someGroup" & cr after vLocation
end repeat
end preOpenCard

--Button Script--

Global vLocation
on mouseUp
put vLocation into vOldLoc
repeat with x=1 to the number of btns in group "someGroup"
put any line of vOldLoc into vNewLoc
move btn x of group "someGroup" to vNewLoc in 10 ticks
filter vOldLoc without vNewLoc
end repeat
put empty into vOldLoc
end mouseUp
Hope this helps

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

Re: Intersecting Buttons

Post by dunbarx » Thu Mar 06, 2014 12:40 am

Marcello.

Did you run this as I instructed? The buttons do not overlap. Your homework was to use this idea to place the buttons you have in your own project in a random pattern. Where are you with this?

Craig

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Intersecting Buttons

Post by marcelloe » Thu Mar 06, 2014 3:01 pm

I have been playing with the script you posted all night. I can't seem how to figure out how to make it work and keep the buttons appear at random places. The next best thing I can think of is to take the current button positions and move the button to those current locs. I can talk myself what needs to be done, but not sure how to script it.

The things that hangs me up is how your script creates buttons. I don't know how to use my current buttons.

Mark

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

Re: Intersecting Buttons

Post by dunbarx » Thu Mar 06, 2014 3:30 pm

Marcello.

My example was just to point you in the right direction, or at least one possible direction.

Since you have that list of non-overlapping locs, and you have a bunch of buttons, all you need to do is to assign a loc (taken from that list) to each button. I assume that there are more locs in the list than there are buttons on the card. You will want to make sure that when you assign a loc, you delete that loc from the list, so that it cannot be used again. Can you do this?

You might want to read the recent thread in this forum called "regarding random???". It has details about extracting random numbers from a list and preventing duplicates.

Craig

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Intersecting Buttons

Post by marcelloe » Thu Mar 06, 2014 3:56 pm

ok, I am going to talk this out to see if I understand the concept.

I want to create a list of the current button locations.
I want to take the lines from the list and assign to a button and delete that line.
I want to repeat for all 10 buttons

If I understand this correctly that this will only use the current positions of those locs.

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

Re: Intersecting Buttons

Post by dunbarx » Thu Mar 06, 2014 4:53 pm

Correct. But I do not know what this means;
f I understand this correctly that this will only use the current positions of those locs.
If I understand:

You will create a list of ten (or more) locations. You have ten buttons. You will map each button to a location, set a button to that loc, and then delete that loc from the list so it cannot be used for the next button.

Did you read that "random" thread?
Did you run the handlers in my earlier example, where a list of possible locs were assembled into the variable "temp", based on hard-coded values for the separation of those locs?

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”