Page 1 of 1

Variable and Function Scope

Posted: 07 May 2012 22:47
by brianc
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.

Re: Variable and Function Scope

Posted: 08 May 2012 09:57
by bxsj
I'm not 100% sure if I understood your question right. But attached is an example on how to set variables in another container.
Hope that helps,
B.

Re: Variable and Function Scope

Posted: 08 May 2012 14:55
by brianc
Thanks! Yeah, I've tried doing it like you do here, but the Lemur editor is not liking it. I'm happy to at least see that it works! Maybe I have some small bug somewhere else that's causing the problem.

Re: Variable and Function Scope

Posted: 08 May 2012 15:12
by brianc
My problem seems to be with the pointer to the current container.

I can do:

Code: Select all

contB.myvar = .303;
But I can't do:

Code: Select all

myptr = contB;
myptr.myvar = .303;