mIRC Home    About    Download    Register    News    Help

Print Thread
$sline() - returns nothing at no line select #269376 19/09/21 08:25 AM
Joined: Jan 2012
Posts: 173
Epic Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Jan 2012
Posts: 173
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:
Code
//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:
Code
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.


πŸ…ΈπŸ†πŸ…² - 𝔦'𝔱𝔰 𝔸 π•‚π–ŽΙ΄π™™ ᴏ𝙛 π•„π™–π–Œπ™žπ™˜
Re: $sline() - returns nothing at no line select [Re: Epic] #269377 19/09/21 11:27 PM
Joined: Jan 2004
Posts: 1,620
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,620
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)
becomes
//var %variable $null | if (0 $+ %variable == 0) echo -a match

if (%variable > 0)
becomes
//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.

Re: $sline() - returns nothing at no line select [Re: Epic] #269394 26/09/21 08:06 AM
Joined: Dec 2002
Posts: 5,003
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,003
Thanks this issue has been fixed for the next version.