Page 1 of 1
Sorting buttons by random
Posted: Mon Nov 04, 2013 12:57 am
by PoLyGLoT
Hi all,
I have a group of buttons on a card. I want these buttons to be sorted randomly each time the card opens. Any easy way to do this?
Thanks,
PoLyGLoT
Re: Sorting buttons by random
Posted: Mon Nov 04, 2013 4:29 am
by dunbarx
Hi.
Sort buttons.
What do you mean? Sort their positions, as if you put them in a cup and shook them out onto the card? Sort their names or creation number?
Please write back.
Craig Newman
Re: Sorting buttons by random
Posted: Mon Nov 04, 2013 2:11 pm
by PoLyGLoT
Hi,
I mean - shuffle their positions. For instance, their layout on the screen to vary each time the card is opened. I will not create any new buttons or generate anything new - rather, the same buttons will just be rearranged each time the card is opened.
Thank you for any assistance.
PoLyGLoT
Re: Sorting buttons by random
Posted: Mon Nov 04, 2013 2:19 pm
by Klaus
HI Poly,
maybe somethig like this:
Code: Select all
on preopencard
## I shuffle button 1 to 5 in this example:
repeat with i = 1 to 5
## Collect LOCs in a list:
put the loc of btn i & CR after tLocList
end repeat
## Delete trailing CR
delete char -1 of tLocList
## Randomize list:
sort lines of tLocList by random(100000)
## Now set the locs:
repeat with i = 1 to 5
set the loc of btn i to line i of tLocList tLocList
end repeat
end preopencard
You get the picture
Best
Klaus
Re: Sorting buttons by random
Posted: Mon Nov 04, 2013 3:05 pm
by PoLyGLoT
Hi Klaus,
Thanks for the tip. I think there is a problem though - it leaves them too scattered on the screen.
Is there any code to automatically align certain buttons on the left and right?
Thanks,
PoLyGLoT
Re: Sorting buttons by random
Posted: Mon Nov 04, 2013 3:16 pm
by Klaus
Hi Poly,
aha, so you do not mean to SHUFFLE the exitsing positions
but rather spread all your button randomly over the card?
That will require some more "sophisticated" scripting
Bst
Klaua
Re: Sorting buttons by random
Posted: Mon Nov 04, 2013 8:08 pm
by dunbarx
Hi.
So you need to set the boundaries of the area in which the buttons will fall, and create random locs that fall within those boundaries, and also do two other things. Can you say what those two are? If you do, I will give you hints on how to execute.
Unless someone else just tells you. But this is something that would be a great learning exercise.
Craig
Re: Sorting buttons by random
Posted: Mon Nov 04, 2013 9:53 pm
by PoLyGLoT
Hi all,
Thanks as always for the help. I believe I've found a better way to do it for my purposes. Instead of using radio buttons, I'm going to use regular buttons that can contain script and advance the screen. Then, I'm just going to have fields of text next to each button, and randomly sort what goes into those text fields each time the card opens. This will bypass the "loc" and "size" code requirements (hopefully).
Thanks!
PoLyGLoT
Re: Sorting buttons by random
Posted: Mon Nov 04, 2013 10:58 pm
by dunbarx
There is an old saying that $100 worth of analysis is worth $1,000,000 worth of programming.
Glad you worked it out.
Craig
Re: Sorting buttons by random
Posted: Mon Nov 04, 2013 11:11 pm
by PoLyGLoT
Thanks again Klaus and Craig. Great info as always.
Nice phrase, too.
