Choosing a random place

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

Post Reply
KanchanaD
Posts: 4
Joined: Tue Feb 03, 2015 7:47 am

Choosing a random place

Post by KanchanaD »

Hello!
I want to place a button in one place out of three possible places. so far im not getting very far.... :oops:

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!!!! :D
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Choosing a random place

Post 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
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: Choosing a random place

Post 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
KanchanaD
Posts: 4
Joined: Tue Feb 03, 2015 7:47 am

Re: Choosing a random place

Post by KanchanaD »

Thank You ForThe Reply Klaus, :D 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!!!!
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: Choosing a random place

Post 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
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Choosing a random place

Post by Klaus »

Hi KanchanaD
KanchanaD wrote:Thank You ForThe Reply Klaus, :D 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 :shock:

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
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Choosing a random place

Post 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!? :shock:
:D :D :D


Best

Craig
Post Reply