Page 1 of 1
Choosing a random place
Posted: Fri May 08, 2015 11:01 am
by KanchanaD
Hello!
I want to place a button in one place out of three possible places. so far im not getting very far....
set the loc of button "Mons" to random (322,412), (468,344),(638,414)
if its possible i want to move a botton from A to B, then B to A repeating..
Thank YOu!!!!

Re: Choosing a random place
Posted: Fri May 08, 2015 11:55 am
by Klaus
Hi KanchanaD,
Looks like you need something like htis:
...
## 1. Create a 3 line text list, one LOC on each line
put "322,412" & CR & "468,344" & CR & "638,414" into tLocList
## 2. Now you can choose a RANDOM line and use it as the new loc for your button:
set the loc of button "Mons" to ANY line of tLocList
## ANY = RANDOM, but fits better in this situation.
...
if its possible i want to move a botton from A to B, then B to A repeating..
Not sure I understand completely?
Best
Klaus
Re: Choosing a random place
Posted: Fri May 08, 2015 3:07 pm
by dunbarx
Hi.
Klaus implied that you might look up the "random" function in the dictionary. You will see that there is no syntax to choose a random number from a list of items. The function takes a single argument, though if you look in the third example, you can see that this can be exploited in quite a powerful way.
As for that button, write a repeat loop that sets the loc in the alternate locations "locA" and "locB":
Code: Select all
repeat 10
set the loc of btn "yourButton" to locA
wait 20
set the loc of btn "yourButton" to locB
wait 20
end repeat
Craig Newman
Re: Choosing a random place
Posted: Fri May 08, 2015 5:55 pm
by KanchanaD
Thank You ForThe Reply Klaus,

although i dont understand clearly what you are saying, could you write it in code because its hard to understand.

And the other thing i mentioned was, always moving an object from Position A to Position B , then moving it back to Position A.. so for example a car goes from their house to the supermarket, and then goes back home, and the car is always going back and forth.... i hope this makes sense?
Thank You soo much for your time!!!!
Re: Choosing a random place
Posted: Fri May 08, 2015 7:00 pm
by dunbarx
Klaus.
Thank You ForThe Reply Klaus,
Does he mean you or me? And I think he will rather like to "move" rather than "set".
Craig
Re: Choosing a random place
Posted: Sat May 09, 2015 1:59 pm
by Klaus
Hi KanchanaD
KanchanaD wrote:Thank You ForThe Reply Klaus,

although i dont understand clearly what you are saying, could you write it in code because its hard to understand.

well, I actually posted CODE, but witjouth a wrapping handler
Maybe it will be clearer this way:
Code: Select all
on mouseup
## 1. Create a 3 line text list, one LOC on each line
put "322,412" & CR & "468,344" & CR & "638,414" into tLocList
## 2. Now you can choose a RANDOM line and use it as the new loc for your button:
set the loc of button "Mons" to ANY line of tLocList
## ANY = RANDOM, but fits better in this situation.
end mouseup
Here is what I do:
1. I create a variable with 3 lines, one LOC on each line!
The resulting variable tLocList will now look like this:
322,412
468,344
638,414
2. Then I use the keyword ANY, which is equivalent to RANDOM but will work better in this situation
Please look up all terms in the dictionary to get more info!
Since Livecode is VERY english like, I can now "say":
...
put ANY line of tLocList into tAnotherVariable
...
And will have a RANDOM loc in this new variable.
Best
Klaus
Re: Choosing a random place
Posted: Sat May 09, 2015 2:01 pm
by Klaus
Hi Klaus,
dunbarx wrote:Klaus.
Thank You ForThe Reply Klaus,
Does he mean you or me?
Klaus
No idea, its just too irritating since we both have the same name!?
Best
Craig