mIRC Homepage
Posted By: saxon $chan - 23/07/03 04:02 PM
//echo -a $chan(fsdfsdljfakjglkfdjglkdjgldfgfdsfafsdfsdf)

Should return * /echo: insufficient parameters

However it returns: 1
Posted By: feud Re: $chan - 23/07/03 04:18 PM
umm.. it returns "0" for me (6.03).
Posted By: saxon Re: $chan - 23/07/03 05:06 PM
Im using WinXP pro, mIRC 6.03 and it returns 1.

Also, //echo -a $isalias(chan) returns $false, before anyone asks.
Posted By: codemastr Re: $chan - 23/07/03 05:35 PM
It returns the number of channels you are currently on, not sure why it does this, but that explains why some see a 0 and some see a 1. Try joining another channel and you'll see it then returns 2.
Posted By: saxon Re: $chan - 23/07/03 05:45 PM
Your right. I was trying to use it as a way of determing if the active window is a channel i'm in. Like:
if ($chan($active)) { commands }

Because if for example your in channel #test, and type:
//echo -a $chan(#test), it returns: #test

So i assumed if I wasn't in the specified channel it should return $null. Oh well, guess I will have to use a loop or some other method.
Posted By: qwerty Re: $chan - 23/07/03 05:51 PM
It's not a bug. You already know that $chan(N) returns the Nth channel, if N is a number greater than 0. If it's zero or a non-numeric string the first character of which is not in $chantypes, it returns the total number of channels (if N is a string that begins with one of the chars in $chantypes, mirc returns the channel name if you are on that channel, otherwise $null). So, if you are on #foo and #bar and $chantypes for that network returns "#&":
$chan(#foo) returns #foo
$chan(#mirc) returns $null
$chan(&mirc) returns $null
$chan(+mirc) returns 2
$chan(foo) returns 2

Many mirc identifiers do the same thing, fex, $gettok(a b c,a,32), $line(status window,a), a fact that suggests this is intentional.

Edit: and once more, somebody sneaked in an posted while I was previewing my post...
Posted By: qwerty Re: $chan - 23/07/03 05:55 PM
You can use $window($active).type
Posted By: codemastr Re: $chan - 23/07/03 06:08 PM
Yeah thats the way it seems to work, however I can't seem to find anything in the helpfile that says that's how it is supposed to work. All I see is:
If you specify a channel name, information on that channel is returned but only if you are on that channel already.

Doesn't say "if you specify something that isn't a valid channel name, then the total number of channels you are on is returned"
Posted By: Hammer Re: $chan - 23/07/03 07:41 PM
if ($chan)

or

if ($active ischan)

or

if ($window($active).type == channel)

or

var %re = /^[ $+ $chantypes $+ ].+$/
if ($regex($active, %re))

There are obviously lots more ways to do this if you start getting into multiple if conditions and checking for valid values in the channel name.
© mIRC Discussion Forums