Doubly defined variables

Winterbay

Active member
I managed, by mistake, to define a variable twice in one script. Once in the global namespace and once in a function.
So in the name of learning something I wonder: Which of these two take precedence within the function that it is defined for the second time? The local copy or the global copy?

(I have since removed the local version)
 
Learn and love the concept of "scope".
Scopes nest, and the innermost definition is valid within the scope containing it.
 
It looks like the function's copy takes precedence, once it has been defined:
PHP:
item test = $item[ seal tooth ];
boolean test()
{
	print( "Function test(), pre redifinition: test = " + test );
	familiar test = $familiar[ hobo monkey ];
	print( "Function test(), post redifinition: test = " + test );
}
test();
print( "global: test = " + test );
results in:
Code:
> call test.ash

Function test(), pre redifinition: test = seal tooth
Function test(), post redifinition: test = Hobo Monkey
global: test = seal tooth
 
Learn and love the concept of "scope".
It looks like the function's copy takes precedence, once it has been defined:

I already knew that and I love scope. When the matter of variable conflict between eatdrink and ocd was brought up my solution to fix it made my variable local instead of global. Of course eatdrink was independently modified to change the variable name, but scope is still our friend.
 
Thanks. Not being a programmer in any way makes me not know these things and now I know. KoL Mafia makes me learn new things all the time :)
 
Back
Top