mIRC Home    About    Download    Register    News    Help

Print Thread
#261700 14/11/17 06:52 PM
Joined: Jan 2004
Posts: 2,127
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
The way $envvar() has a .name property to treat a numeric property as a variable name instead of the Nth variable, and $bfind() has a .text property to treat a numeric parameter as text instead of an ASCII value, it would be nice if $timer() could have the same thing. My guess is that .name would be the more appropriate property name here.

When a timer is created without assigning a name to it, mIRC assigns it the lowest available positive integer. Yet you can't use the value returned from $ltimer or $ctimer to access characteristics about that timer without looping through all the timers looking for the $timer(N) which returns that particular numeric name. $timer(3).secs is returning info about the 3rd timer, not the timer *named* 3.

The .name property would make it simple to find properties for /timer1 by using the .name property to force the numeric string to be treated as the timer name instead of the Nth timer ID. If /timer1 is the 5th timer in the list, $timer(1).name returns 5 instead of the name of the 1st timer, and you could find properties of /timer1 with $timer($timer(1).name).secs.

maroon #265197 15/03/19 03:51 AM
Joined: Jan 2004
Posts: 2,127
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
I'm posting this update for the benefit of those searching for keyword $envvar and finding this post.

What I posted above about $envvar().name seems not actually correct, and I'm having trouble finding an older mIRC version having the behavior I described behavior above.

Instead of .name treating a numeric variable name as the name of an environment variable instead of its index in the sequential list of variables, it instead returns the actual case of the variable, regardless of the string used as the parameter.

For example, $envvar(path).name returns 'Path' because that's the literal case of the existing variable name.

I have an environment variable named '7', and instead of returning '7' or the index number where '7' appears in the list of variables, $envvar(7).name and $envvar(7) both return identical string, returning the name of the 7th item in the list of environment variables.

The only way to return the contents of the variable named '7' is to loop through all the variable names looking for the index numer where $envvar(index-number) is '7', then use $envvar(index-number).value

I'm not sure whether it would break compatibility for the .name property in this case to return the index number when the parameter is numeric, or whether it's worth the bother for this edge case.

But it is great to now be able to find the timer index for $timer(12345) without needing to loop through them until finding a string match, and now instead can use $timer(12345).name

maroon #271363 25/02/23 02:19 PM
Joined: Jan 2004
Posts: 2,127
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
The effect for $envvar().name is that for positive numeric inputs the .name property is ignored, and for non-numeric input it returns the string itself, and is always $null when the input is '0'. Since .name has never worked correctly it shouldn't be a problem to change its behavior.

My environment variables list contains:

2nd item: 0=foobar
3rd item: 7=DEADBEEF12345678
7th item: COMPUTERNAME=name_of_device

//echo -a $envvar(2) vs $envvar(2).name and $envvar(2).value
result: 0 vs 0 and foobar
//echo -a $envvar(3) vs $envvar(3).name and $envvar(3).value
result: 7 vs 7 and DEADBEEF1234567
//echo -a $envvar(7) vs $envvar(7).name and $envvar(7).value
result: COMPUTERNAME vs COMPUTERNAME and name_of_device

(numeric input ignores .name)

//echo -a $envvar(0) vs $envvar(0).name and $envvar(0).value
result: 38 vs and

(can't find the name or value for item named '0')

//echo -a $envvar(COMPUTERNAME) vs $envvar(COMPUTERNAME).name and $envvar(COMPUTERNAME).value
result: name_of_device vs COMPUTERNAME and name_of_device

(Only benefit is fixing the case-sensitive string for $envvar(ComputerName).name

Recommended solution: $envvar().name should behave like $timer().name always does, where $envvar().name would return the Nth position of the string named in the input, regardless whether it is numeric or text, or returns $null if no such variablename exists. This would always allow the correct results from $envvar( $envvar(everything).name ) the same way that $timer( $timer(everything).name ) does.

Code
$envvar(COMPUTERNAME).name	now=COMPUTERNAME	new=7 (varname is 7th in the list)
$envvar(7).name			now=COMPUTERNAME	new=3 (varname is 3rd in the list)

$envvar(0).name			now=$null		new=2 (varname is 2nd in the list)
$envvar(2).name			now=0			new=$null (no such varname)
$envvar(3).name			now=7			new=$null (no such varname)

maroon #271373 27/02/23 12:12 PM
Joined: Jan 2004
Posts: 2,127
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
Update:

From discussions in channel, I see now that I misread this thread, which explains my confusion over why it was named $timer().name, as I thought $envvar().name was added because of $timer().name rather than the other way around. Since .name for $envvar() has existed from the beginning, maybe the solution is instead a new+optional parameter that forces the 1st parm to be seen as a name rather than detecting if it's numeric, so $envvar(%string,n) would work as expected with .name and .value regardless whether the varname held in %string was text or 0 or positive-numeric.


Link Copied to Clipboard