mIRC Homepage
Posted By: Epic $sline() - returns nothing at no line select - 19/09/21 08:25 AM
The identifier $sline(window,0) - returns nothing if there are no selected lines in the list.
It is logical to assume that the answer should be = 0. The returned numeric value is meaningful in some cases. For example, when using an enumeration in a loop "While".

For check:
//sline -r #test | echo -a $sline(#test,0)

Returns: * /echo: insufficient parameters

Would like to the returned response was as «0» (exact number) to be able to take the necessary steps to highlight a specific line in the window list:
if ($nick(#test,0) > 0 && $sline(#test,0) == 0) { /sline -l #test 1 }

Otherwise, it is likely that the script with a similar string "IF" condition will not bring the desired result or will crashes. Thanks.
I agree with such a change.

It should probably be the case that $sline(@NoSuchWindow,0) and $line(@NoSuchWindow,0) and $nick(#NoSuchChannel,0) return $null as they currently do, but if the window exists, it seems reasonable that $sline should return the zero just like $line does for an empty @window. An exception to returning $null from non-existent things is how $lines(NoSuchFIle.txt) returns zero instead of $null. I don't think the zero-vs-null behavior should differ depending on whether a window is a @listbox or not.

I doubt this affects most scripts, because they would usually use the boolean check "while ($sline(@window,0))" instead of comparing the value to zero.

In a more general case, when a script needs to defend against the possibility that a variable or identifier can be null, and wants to treat that null the same as zero, there's a couple additional ways of handling it.

if (%variable == 0)
//var %variable $null | if (0 $+ %variable == 0) echo -a match

if (%variable > 0)
//var %variable $null | if (%variable !<= 0) echo -a match

You can also use $calc(%variable) but that has the side-effect of having text strings also treated as zero.
Thanks this issue has been fixed for the next version.
© mIRC Discussion Forums