Page 2 of 2

Re: Changing Arrays

Posted: Tue Apr 28, 2015 10:00 am
by smith8867
Ok I have found a better solution to my issue.

How would I be able to get a random value from the array: users[loop] ?

Re: Changing Arrays

Posted: Tue Apr 28, 2015 4:24 pm
by dunbarx
Hi.
How would I be able to get a random value from the array: users[loop] ?
You cannot get a random number from an element of an array, you have to put a random number into an element of an array. I suspect I am not understanding what you need. Put this in a button:

Code: Select all

on mouseUp
   repeat with y = 1 to 5
      put random(999) into myArray[y]
   end repeat
end mouseUp
Put a breakpoint at the last line. You will see five random numbers in the array. If you want a (random) one of these values, use Klaus' suggestion a post or two back. But is this what you meant?

Craig

Re: Changing Arrays

Posted: Tue Apr 28, 2015 7:13 pm
by SparkOut
Maybe something like

Code: Select all

put the keys of users into tKeys
put any line of tKeys into tChosenOne
put users[(tChosenOne)]
?????
Echoing Craig, but is this what you meant?

Re: Changing Arrays

Posted: Thu Apr 30, 2015 1:34 pm
by smith8867
Perhaps I am unclear :/
Heres what I am looking to achieve:
- Enter all users, store it in users[loop]
- Get a random name from the array users[loop]
- Output the name that was randomly chosen

Re: Changing Arrays

Posted: Thu Apr 30, 2015 2:01 pm
by Klaus
We still don't have any clue how you organize your array, means what is in what key!
We need to know before we finally can answer your question!

You are obviously NOT using any array form/format we have been discussed so far 8)

Re: Changing Arrays

Posted: Thu Apr 30, 2015 4:43 pm
by jacque
SparkOut had the answer. Get a random key and output its value.

I don't really think you need an array for this though, a simple list would be enough unless you plan to add more data to the array later.

Re: Changing Arrays

Posted: Fri May 08, 2015 11:51 am
by smith8867
Appologies for not understanding. They are being stored like so:

Code: Select all

repeat with loop = 1 to 5
ask "Please enter the users name"
put it into name[loop]
end repeat
I would like to choose a random "user" from the "name[loop]" array.I am using the usernames later on in the program.

Re: Changing Arrays

Posted: Fri May 08, 2015 11:59 am
by Klaus
Hi smith8867,

1. do NOT use reserved (by Livecode) words as variable names!
NAME is e.g. a reserved word, you will get in trouble later on :D

2. We already gave you the answer to your last question, see SparkOuts last posting!
HInt: HIs ARRAY is named "users" 8)


Best

Klaus