Variable and Function Scope
Posted: 07 May 2012 22:47
I have an interface that contains several containers, let's call those containers A and B. I'm interested in getting/setting local variables of one container from another, and I'm running into some issues with scope.
From a script in container A, I can read variables from other containers, like....
A.var1 = B.var1;
But from within A, I can't set a variable in that other container, like:
B.var1 = 21;
I tried to get around this by mimicking object-oriented programming and creating a function in container B, something like:
setvar1(value)
var1 = value;
But I cannot call B.setvar1() from a script in A.
So it would appear that variables can be read globally, but assigned only locally, and functions can only be used locally. Is that correct? Aside from using global variables, does anyone have a good solution for working around this? I'm trying to avoid this since I have 8 containers storing configuration information in 10 different variables and a pointer to the "current" container, so this would create a ton of variables, and they'd all need a unique name, which would mean I'd have to duplicate a bunch of scripts instead of using the pointer.
From a script in container A, I can read variables from other containers, like....
A.var1 = B.var1;
But from within A, I can't set a variable in that other container, like:
B.var1 = 21;
I tried to get around this by mimicking object-oriented programming and creating a function in container B, something like:
setvar1(value)
var1 = value;
But I cannot call B.setvar1() from a script in A.
So it would appear that variables can be read globally, but assigned only locally, and functions can only be used locally. Is that correct? Aside from using global variables, does anyone have a good solution for working around this? I'm trying to avoid this since I have 8 containers storing configuration information in 10 different variables and a pointer to the "current" container, so this would create a ton of variables, and they'd all need a unique name, which would mean I'd have to duplicate a bunch of scripts instead of using the pointer.