mIRC Homepage

echo -z[0|1]

Posted By: maroon

echo -z[0|1] - 15/04/22 09:34 AM

echo -z[0|1]
/aline [-z] [c] <@name> <text>

It would be helpful for /echo to have a -z switch that would allow either echoing a blank line, or to be a 'do nothing' command which doesn't output a line, but doesn't generate an error either. I'm seeing the -z0 as being the do-nothing-if-blank-instead-of-an-error and being the same as when -z is used without a number. And, the -z1 being -echo-1-blank-line-instead-of-an-error.

A similar function would be helpful to allow /aline /iline /rline to put a blank line into a @listbox

Unlike /writeini -z, these -z* switches would not be an error if there is text to be echoed.

I was reminded of one situation where this would be helpful while answering in THIS thread, where I discovered something I hadn't realized before, where "echo $null" is not a halting error, but "echo -a $null" is one. This means that adding a switch letter to prevent $1 being treated as if a color index or as a switch letter - would create a situation where there's an error if $1 were blank but would not be an error if that switch were not there.

This would also simplify scripting where you're not wanting to halt the script if an echo turns out to be blank.

For scripts that want to have a blank line in a @window, it's not always useful to fake it by putting the $chr(160) or some other zero-width-character, which isn't a blank line and it responds differently to /filter. The work-arounds I'm aware of are this /filter kludge to do it:

//echo -a first msg | //write -c crlf.txt $crlf | filter crlf.txt $active * | echo -a last msg

... or to echo $crlf at the end of your message. While it is possible to echo a blank line with "//echo $crlf", this requires the script to use " $+ $crlf to avoid a change in appearance should the message have a defined background color for the text.

If you don't want to add the -z switch, then it would be helpful for /help echo to mention using $crlf

Won't prevent an error:
//var %temp $chr(32) $chr(32) | if (%temp != $null) echo -a %temp
Will prevent an error but is slower:
//var %temp $chr(32) $chr(32) | if ($gettok(%temp,1,32) != $null) echo -a %temp

Examples:

//echo -z first msg | echo -z last msg
result: both display text without an error

//echo -z first msg | echo -z $null | echo -z last msg
result: first & last message both display without anything between them

//echo -z1 first msg | echo -z1 $null | echo -z1 last msg
result: first & last message both display with 1 blank line between them

The only backwards compatible issue I see is that /echo is not currently doing like many other commands where they see $1 as a switch parameter even though it contains only an invalid switch. So, scripts can do something like this to prevent a trickster from disabling their ignore list:

//var %nick off | ignore %nick
result: ignore list turned off
//var %nick off | ignore -- %nick
//var %nick off | ignore -z %nick
result: adds off!*@* to ignore list

But /echo is not working like that, unless it contains at least 1 valid switch. So, $1 being -- or -z or even -jkopuwxyz is currently displayed, but $1 being --attention!-- is treated as a switch letter because it sees at least 1 switch in there.

I don't recommend changing /echo to behave like the other commands, because I believe there are many cases where someone not using a switch letter would want to display $1 being --. A compromise might be a letter that's guaranteed to never be used as a valid switch.

Adding a new switch letter to echo would cause different behavior in situations where 'z' were the difference in whether or not $1 contained a valid switch letter, so if you want to minimize the false matches, you could require that -z0 and -z1 were valid switches but -z not followed by either number is not.
© 2022 mIRC Discussion Forums