- Home /
Creating a new variable with custom function
function Update ()
{
test('testVariable', 5);
}
function test(newVariable, definition)
{
var newVariable = definition;
}
Simply I have custom function and i want to create a new variable everytime I call this function with the name which i specify in function description. My code should create a new variable testVariable which contains number 5. However I just get an error. Does anyone know how to fix it?
Answer by Bunny83 · Jun 05, 2012 at 02:25 PM
UnityScript( a Javascript based language ) is not JavaScript(ECMA script). It's a compiled language, not a dynamic scripting language. You can't create variables on the fly. Your variable is only visible and existant in the scope of your function test. As soon as the function exits the variable doesn't exist anymore.
What exactly do you want to do? If you need an instance of something you might want to create a class. UnityScript is way different from JavaScript.