# Dynamic variable edited through a function?

**URL:** <https://forum.kirupa.com/t/dynamic-variable-edited-through-a-function/313616>\
**Category:** programming\
**Created:** [September 4, 2010, 2:49pm UTC](https://forum.kirupa.com/t/dynamic-variable-edited-through-a-function/313616 "2010-09-04T14:49:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skribble](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Skribble](https://forum.kirupa.com/u/Skribble)\
**Post date:** [September 4, 2010, 2:49pm UTC](https://forum.kirupa.com/t/dynamic-variable-edited-through-a-function/313616/1 "2010-09-04T14:49:57Z")

</div>

**Solution** - You can refer to variables through other variables by wrapping them in \_root[&]. So for my example I can use \_root[keyToSet] = newKey to set a variable from inside my function.

* * *

Hullooooo again. I’ve hit another snag with my project and Im not sure how to proceed.

I have a function that is used to customize the controls, and I pass a variable to it for updating the screen with which keys are assigned to what controls.

For examples sake, this is the code:

```auto
upKey = 87;

upKeyBTN.onRelease = function(){
     setCustomKeys(upKey);
}

function setCustomKeys(keyToSet){
     newKey = *key pressed by user*;
     keyToSet = newKey;
}

```

What I can’t seem to do is get upKey updated with the new key from inside the function. As my example shows, I tried using keyToSet = newKey, but that doesn’t seem to work. I need to use upKey in a few other places in the function too, so how can I make a direct reference to it from inside the function?

The whole point of doing it this way is so that I can customize each key with just one function.

Any ideas on how I can achieve this? Thanks!=)

Brendan
