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!
Hello all...I am attempting to move some buttons around on a card when the card opens. No big deal but I am having troubles keeping them within the boundaries of the card. I have written a simple button script that randomly generates x,y loc and moves the button, but I am unsure what upper limit I need to use, or if I can pass multiple values in the random command to keep it within the boundary of the card...see below
local vNewLoc,vOldLoc
on mouseUp
put random(512) into item 1 of vNewLoc
put random(384) into item 2 of vNewLoc
put the loc of me into vOldLoc
move me from vOldLoc to vNewLoc in 10 ticks
put empty into vNewLoc
end mouseUp
as soon as I figure this out, I am going to use the intersect command to keep the buttons from overlapping each other, but first I need to get this straight! Thanks all...
I see two ways
1. Using a loop that check the intersect for each loc with the risk to get a loop without end
2. Create a list of locations and get "randomed lines" of this list
Thanks Jean-Marc,
I didn't consider using pre defined locations and using a loop to assign new locations. This method would prevent me from having to assess each buttons location to ensure each button doesn't overlap or intersect with another. I am currently working on this now and will report back with my code so others can see...
I like your way better than pre-defined locs, and there is nothing wrong with your handler. But what is happening to your buttons? Is it possible that the card window is smaller than the "512,342" you assign? If so, either lower those values or make the window bigger.
Remember that the loc is the center of an object, so you may have to deduct half the height and width of your values so that portions of the objects do not fall off the edge.
Hey Craig...thanks for the response...here is what I am trying to do.. I have attached a pic of the program...it is a simple math program to teach my daughter her math facts. I just want to move the answers around the screen on openCard so she doesn't get used to where the answers are located on the screen. We will call the answers the "answersGroup" so as to keep the other buttons out of the movement process. The code I wrote logs the position of the "answers" only and puts them in a variable called vLoc. I then am trying to randomize that list and then use a loop to assign "random" locations for each button. I made a loop within a loop but it only works with unexpected results. Maybe you can give me a little insight on what I am doing wrong here..
local vLoc
on mouseUp
put 85,212 & cr & 171,318 & cr & 71,392 & cr & 187,484 & cr & 65,576 & cr & 951,162 & cr & 885,272 & cr & 969,372 & cr & 847,438 & cr & 951,586 into vLoc
sort lines of vLoc by random(the number of lines of vLoc)
repeat with x =1 to the number of btns in group "answers"
repeat for each line tLine in vLoc
set the loc of btn x to tLine
end repeat
end repeat
put empty into vLoc
end mouseUp