mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2013
Posts: 87
I
Iire Offline OP
Babel fish
OP Offline
Babel fish
I
Joined: Aug 2013
Posts: 87
It seems if you set a variable locally first, and then use /set or /var -g to change the value of the same var, the /set or /var -g will act as a local variable setter rather than a global one.

Here is a rather verbose example:

Code:
//var -s %X! Ok | set -s %X! Hello | echo -gaec i ** % $+ X! is local: $var(%X!,1).local | echo -gaec i ** During Script Processing: % $+ X! = %X! | .timer 1 0 echo -gaec i ** After Script Processing: % $!+ X! = % $+ X!


The same happens if used in a script file. (e.g., as an alias).

Initially, I thought this behavior was related to how the %var = value method of setting a variable acts as a local variable setter if the same var is set locally first, but now I'm being told that this is not the case and that what I have described is actually a bug, which (naturally) is why I'm reporting it here.

Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
A variable is declared local or global when it is created, not when it's modified. So if a local variable already exists and you use /set or /var -g to change it, it stands to reason the variable will remain local.

If you want to change it into a global variable, you should unset it and then re-create it, like so:

Code:
//var %x = test | echo -a $var(%x,1).local | unset %x | var -g %x = test | echo -a $var(%x,1).local | unset %x


The first %x is local and the second is global.

The somewhat odd thing is that this works the opposite way when you first create a global variable:

Code:
//var -g %x = test | echo -a $var(%x,1).local | var %x = testloc | echo -a $var(%x,1).local ~ %x | unset %x


The first %x is global and the second %x is local. The unset %x at the end unsets the local %x and not the global one.

If you declare a local variable with the same name as a global one, the only way to get the global one's value is by using $var()


Link Copied to Clipboard