A Question regarding Variables

Hello,

I am new to Eggplant and SenseTalk, and now I got stuck.

I try to address a variables content as a global variables' name - but how?

I pass a parameter to a function, eg "button35" and store it in a variable myCurrentBtn.
set myCurrentBtn to item one of paramters


Now I want to access the already set global variable "button35". This gets set in a different script.
This works:
global button35.(global env.variable)
This does not:
global myCurrentBtn.(global env.variable)

I need to use a variable cause "button35" will be passed to this function and might be something else...

Please Help

Comments

  • Hi--

    Has myCurrentBtn been declared as a global variable? You either need to declare it as global at the top of the script:
    global myCurrentBtn
    

    or inline:
    set global myCurrentBtn to item one of paramters
    

    Hope this helps!
  • hard to explain what I mean, be gentle

    the variable myCurrentBtn is local, its content is "button35" which is passed into this function.

    Now my problem is, that whatever is passed to this function eg "button35" is also the name of a global variable. So if I pass "button35" to the function there will be a global button35 out there.
    So I kind of need a "pointer" to myCurrentBtns' content - to adress this content as a global var...

    I really hope You can follow my idea
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    To access the contents of a variable whose name is held in another variable you can use the value() function:
    set button35 to "OK"
    set myCurrentButton to "button35"
    put myCurrentButton -- shows "button35"
    put value(myCurrentButton) -- shows "OK"
    
    Or, for a global variable:
    set global button35 to "OK"
    set myCurrentButton to "button35"
    put myCurrentButton -- shows "button35"
    put value("global" && myCurrentButton) -- shows "OK"
    
    Is that close to what you're looking for?

    Another approach you might consider for this sort of thing would be this: Instead of storing values in a lot of different global variables for each button, store the values in a single global property list with keys for each button. So then you'd have something like:
    params myCurrentButton
    global allButtonValues -- this is a property list that has a "button35" key
    put allButtonValues.(myCurrentButton)
    

    Hopefully one of those approaches will get you where you want to go.
  • This might be it SenseTalkDoug,

    I will give it a try, Thank You

    -

    Just implemented it - it works, Thank You!
    value("global" && variable)
    
Sign In or Register to comment.