You are not logged in.
I have discovered an interesting quirk in the beanshell scripting language. Every variable has global scope. This has some positves, functions can refer to objects (such are random number generators) declared outside of themselves. A number of negative include the fact that it is really easy to mess yourself up by i.e. using variable in a function that is a loop counter for a loop calling the function. A really easy way to confuse yourself.
A simple workaround is to pre or post append a unique function identifier to each variable used in a function.
I thought I might pass on this interesting piece of information to save people some time debugging their script in AOI.
Offline
Hum, interesting, this was new to me. But there's another way around it, which (I think) is a little better: Declare all your variables. 
This prints out "10, 10":
i = 5;
void work()
{
i = 10;
print(i);
}
work();
print(i);This one prints "10, 5" as expected:
int i = 5;
void work()
{
int i = 10;
print(i);
}
work();
print(i);Actually, it seems that this is "correct" behaviour as the manual reveals (see also). So in the first example, the outer "i" is simply a "global" variable by definition. You can surely argue about this. It makes sense once you know it -- but it's not really intuitive if you ask me. 
If you want to continue working with "untyped" variables, you can use "var" instead of a real type like "int". This will work as expected without having to assign a proper type:
var i = 5;
void work()
{
var i = 10;
print(i);
}
work();
print(i);(I think properly typed variables save you from a lot of trouble, however -- but that's a matter of taste.)
Offline
well, that makes sense. I started scripting with the information that beanshells is Java but you don't have to declare variables. I guess I just assumed that it was like Python, where variables have scope unless declared otherwise. Thanks for the information TroY, I am sure others will find it useful as well.
Offline