Changing Arrays
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Changing Arrays
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] ?
How would I be able to get a random value from the array: users[loop] ?
Re: Changing Arrays
Hi.
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
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:How would I be able to get a random value from the array: users[loop] ?
Code: Select all
on mouseUp
repeat with y = 1 to 5
put random(999) into myArray[y]
end repeat
end mouseUp
Craig
Re: Changing Arrays
Maybe something like?????
Echoing Craig, but is this what you meant?
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
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
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
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
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

Re: Changing Arrays
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.
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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Changing Arrays
Appologies for not understanding. They are being stored like so:
I would like to choose a random "user" from the "name[loop]" array.I am using the usernames later on in the program.
Code: Select all
repeat with loop = 1 to 5
ask "Please enter the users name"
put it into name[loop]
end repeat
Re: Changing Arrays
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
2. We already gave you the answer to your last question, see SparkOuts last posting!
HInt: HIs ARRAY is named "users"
Best
Klaus
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

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

Best
Klaus