Changing Arrays
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Changing Arrays
Is there a way to go to a certain level in an array, and change the value?
Thanks
Thanks
Re: Changing Arrays
Hi Smith,smith8867 wrote:Is there a way to go to a certain level in an array, and change the value?
Code: Select all
put 42 into cheese[1][2][3]
-- or
put 42 into cheese["camembert"]["cheddar"]Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Changing Arrays
Thin ice, Thierry, very thin ice!Thierry wrote:cheese["camembert"]["cheddar"]
Re: Changing Arrays
I'm storing arrays in this form: variable[output]
Basically, I need to go to a certain level in the array and change the value of it. Is that possible?
Basically, I need to go to a certain level in the array and change the value of it. Is that possible?
Re: Changing Arrays
Hi smith8867,
what Thierry said:
...
put "new value" into variable["output"]
...
If that is not what you mean we may need a "real" example of your array,
resp. what you mean with "a certain level of the array".
Best
Klaus
what Thierry said:
...
put "new value" into variable["output"]
...
If that is not what you mean we may need a "real" example of your array,
resp. what you mean with "a certain level of the array".
Best
Klaus
Re: Changing Arrays
Nice to see you KlausKlaus wrote: Thin ice, Thierry, very thin ice!
![]()
![]()
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Changing Arrays
Ok so, example:
Run a loop to collect 3 pieces of data.
pupilData[name];
Sam is stored at position 1
Peter is stored at position 2
Jake is stored at position 3
Lets say we choose position 2, is there a way to change "Peter" to something different, without running the loop again?
Run a loop to collect 3 pieces of data.
pupilData[name];
Sam is stored at position 1
Peter is stored at position 2
Jake is stored at position 3
Lets say we choose position 2, is there a way to change "Peter" to something different, without running the loop again?
Re: Changing Arrays
Hm, what do you mean with "position X"?
Something like this:
pupilData["name"][1]["Sam"]
pupilData["name"][2]["Peter"]
pupilData["name"][3]["Jake"]
?
Then use: put Oswald" into pupilData["name"][2]
Result -> pupilData["name"][2]["Oswald"]
Something like this:
pupilData["name"][1]["Sam"]
pupilData["name"][2]["Peter"]
pupilData["name"][3]["Jake"]
?
Then use: put Oswald" into pupilData["name"][2]
Result -> pupilData["name"][2]["Oswald"]
Re: Changing Arrays
Thats what I am looking for, only I am not using that kind of array structure. I am using arrays like this: myVariable[data], Is the method you showed the only way I could do what I am after?
Re: Changing Arrays
I may be able to tell you if you can actually explain your array structure!smith8867 wrote:...Is the method you showed the only way I could do what I am after?
Still have no clue about this...
Re: Changing Arrays
Hi.
Is it possible that you are asking this question? Put this in a button:
Note that the first answer gives you "firstStuff", but the last answer does not. Is that what you are asking, to find intermediate level values of an array?
Craig Newman
Is it possible that you are asking this question? Put this in a button:
Code: Select all
on mouseUp
put "firstStuff" into yourArray[firstLevel]
answer yourArray[firstLevel]
put "secondStuff" into yourArray[firstLevel][secondLevel]
answer yourArray[firstLevel][secondlevel]
put "thirdStuff" into yourArray[firstLevel][secondLevel][thirdLevel]
answer yourArray[firstLevel][secondLevel][thirdLevel]
answer yourArray[firstLevel]
end mouseUpCraig Newman
Re: Changing Arrays
I'll try the best I can to explain.
So say the random number generated is 3, it will go to the 3rd string in the array, and change it. Hope that makes sense
Code: Select all
on mouseUp
repeat with loop = 1 to 5
put "You have not won the prize" into output[loop]
end repeat
//
//Here I want to get a random number, go to that level in the array "output"
//and change the string to something like "You have won the prize"
end mouseUp
Re: Changing Arrays
Like this?
Code: Select all
on mouseUp
repeat with loop = 1 to 5
put "You have not won the prize" into output[loop]
end repeat
get random(5)
put "You have won the prize" into output[it]
end mouseUpRe: Changing Arrays
So if i had to run a loop and output that array using "answer", that wouldn't display 4 non prize winners, and 1 prize winner would it?
Re: Changing Arrays
EX-ACTLY!smith8867 wrote:So if i had to run a loop and output that array using "answer", that wouldn't display 4 non prize winners, and 1 prize winner would it?
Yes:smith8867 wrote:So say the random number generated is 3, it will go to the 3rd string in the array, and change it.
...
put random(5) into tRandomNumber
put "You have won the prize" into output[tRandomNumber]
...
Best
Klaus
