What is the correct way to change the name of an array element? For example, how do I change myArray["xyz"] to be myArray["abc"].
Thanks,
Pete
Array key names
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Array key names
Hi Pete,
I don't think there is a way to do this in a single line of code. I would do something like this:
The @ before the first parameter indicates that the array is passed by reference, this allows you to mutate it inside the command and is also faster than passing the value which may be quite large.
You can use it like this:
Hope this helps.
Regards
Oliver
I don't think there is a way to do this in a single line of code. I would do something like this:
Code: Select all
command arrayKeyRename @xArray, pKeyName, pNewKeyName
local tKeyValue
put xArray[pKeyName] into tKeyValue
delete variable xArray[pKeyName]
put tKeyValue into xArray[pNewKeyName]
end arrayKeyRename
You can use it like this:
Code: Select all
on mouseUp
local tArray
put "test" into tArray["test1"]
arrayKeyRename tArray, "test1", "test2"
put tArray["test2"] --> test
end mouseUp
Regards
Oliver
Oliver Kenyon
Software Developer
Runtime Revolution
Software Developer
Runtime Revolution
Re: Array key names
Thanks Oliver. I was doing something very similar to what you suggested but hoped there might be a simpler way to do it.
Pete
Pete