Assigning values to variables stored in variables

hi all,

i have an issue that i am not sure how to tackle.

i have a property list that i would like to transform into var:value pairs.

for example:

set plist to (a:10,b:15)
repeat with each item of keys(plist)
set it to plist.(it)
end repeat
put b -- should output 15, instead it puts "b"

is there any way to do this?

I just thought of another example of what i want to do.
set variablePtr to "a"
set value(variablePtr) to 10
put a -- should output 10

i have read a bit about references but i am not sure that's what i want... because potentially the local variable does not exist yet.

is there no hope for what i want to do?


  • lrojaslrojas Member
    In case somebody faces the same question as me,

    i found a way to do it

    set plist to (a:10, b:20, c:30, d:40)
    set validKeys to (a, b, c, d)
    repeat with each item of keys(Parameters)
        if it is in validKeys then
            set command to "set" && it && "to plist." & it
            do command
            log warning "extra key,value ( " & it & ", " & &") ignored because not expected"
        end if
    end repeat
    put a -- outputs 10
    put b -- outputs 20
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    That's a good solution, and shows an appropriate use of the 'do' command to construct a command using a dynamic variable name.

    In this case, since it appears that you want a selected set of the properties rather than all of them, here's a simpler approach (taking advantage of SenseTalk's multiple assignment and ability to access a list of properties at once) that might also suit your needs:
    set plist to (a:10, b:20, c:30, d:40)
    set (a,b,c,d) to plist.(a,b,c,d)
    put a,b,c,d
  • lrojaslrojas Member
    Amazing, thank you so much, that is much simpler than my approach
Sign In or Register to comment.