set my_variables to {main_title:"aa", main_description:"bb"}
log main_description of my_variables
set main_description of my_variables to "XXXX"
log main_description of my_variables
I think i can’t use your method. I try to decrease amount of rows in some of my scripts. Here is example:
set_variable_to_x({{"main_title", "title here"}, {"main_description", "some data"}}) --this list has 20 variables
on set_variable_to_x(what)
repeat with counter from 1 to (count items in what)
set (item 1 in (item counter in what)) to (item 2 in (item counter in what))
end repeat
end set_variable_to_x
Result should be:
main_title variable value is “title here”
main_description variable value is “some data”
If list has 20 variables, then after this i have 20 separate variables set to correct values.
set my_variables to {{"main_title", "main_description"}, {"main_title", "main_description"}, {"main_title", "main_description"}}
set (item 1 of item 1 of my_variables) to "xxxx"
set (item 2 of item 1 of my_variables) to "xxxx"
set (item 1 of item 2 of my_variables) to "yyyy"
set (item 2 of item 2 of my_variables) to "yyyy"
my_variables
It doesn’t need to be a record nor does it need to be a listed list. You can solve this by setting the contents of a var to a reference. Then when you set a reference to a variable you need set the contents of the reference instead of changing the var. Something like this will work.
set aList to {"aaaa", "bbbb"}
set mainTitle to a reference to item 2 of aList
set contents of mainTitle to "XXXXX"
return aList --result:{"aaaa", "XXXXX"}
The reason I don’t use set mainTitle to “XXXXX” is simply because it would delete the reference mainTitle is holding and replace it with “XXXXX”. When I say set contents of mainTitle to “XXXXX” i’m changing the content of item 2 of aList (the reference) and not the content of mainTitle.