mIRC Home    About    Download    Register    News    Help

Print Thread
#226060 17/09/10 01:20 PM
Joined: Nov 2009
Posts: 81
V
Voglea Offline OP
Babel fish
OP Offline
Babel fish
V
Joined: Nov 2009
Posts: 81
//echo $chan(any string) == $chan(0)

i think thats not normal smile

Voglea #226061 17/09/10 01:41 PM
Joined: Jul 2006
Posts: 4,150
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,150
In a lot of place in mIRC, an invalid parameter is considered as 0. It could be fixed to return $null but that's not really important


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #226064 17/09/10 04:17 PM
Joined: Aug 2010
Posts: 134
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Well, the downside is that you can't quickly check if a parameter is an existing channel. You'd first have to check if the leftmost character is found in $chantypes.

Note that $chan(#anytext) DOES return $null and not $chan(0), assuming you're not on #anytext.


Learning something new every day.
Thels #226067 17/09/10 05:34 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Two options:

if ($chan(somettext).status isalpha) { }
if ($window(somettext)) { }

The first tells you it's a valid channel that you have open. The second tells you if it's a valid window that is open -- good for checks that aren't likely to be true due to a query window or chat having the same name.

In option 1, you can also check only joined or the other types of statuses if that's useful for your script. Not really sure what your script's purpose is, so not sure what the best way to handle it would be.

As a note, $read() got changed as far as how it handled invalid strings placed into the identifier. That should be a good indicator that it's not a good idea to skip "real" checks by expecting an invalid parameter to return $null. In other words, rather than trying to use $null to know if it's a valid channel (even if it works), you would be better off using some other actual command that would tell you like the examples above rather than hoping that $chan() with invalid parameters returns $null and not an error or some other value. Just something to consider for this any all other types of commands.


Invision Support
#Invision on irc.irchighway.net
Thels #226070 17/09/10 05:48 PM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
If it's a channel, then if ($me ison #chan) will be true, which you should use to check if the channel is an "existing channel".

I'm not quite sure what you're reporting, otherwise-- you should obviously check that your channel input is a valid channel input before passing data around to identifiers. $chan() expects proper input.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #226072 17/09/10 10:45 PM
Joined: Jul 2006
Posts: 4,150
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,150
'ischan' should be used to check if it's a valid channel


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #226073 18/09/10 12:54 AM
Joined: Dec 2002
Posts: 344
D
Pan-dimensional mouse
Offline
Pan-dimensional mouse
D
Joined: Dec 2002
Posts: 344
Originally Posted By: Wims
'ischan' should be used to check if it's a valid channel


Unfortunately, "ischan" has the quirk that it will report true when a channel window is open but the server is disconnected. "ison" will give false in this case. I guess there may be situations where you would want either behavior, but you should be aware that they aren't completely interchangeable.

Voglea #226083 18/09/10 12:25 PM
Joined: Nov 2009
Posts: 81
V
Voglea Offline OP
Babel fish
OP Offline
Babel fish
V
Joined: Nov 2009
Posts: 81
I use $query($nick) for query check, $chat($nick) for dcc chat check and I just wanna using $chan(#) for channel check.

I want clear code smile

Code:
alias say {
  var %target = $active, %str = $1-
  if ($chan(%target)) msg $v1 %str
  elseif ($query(%target)) msg $v1 %str
}

Voglea #226084 18/09/10 01:39 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You know that you can use just $active with /say, right? There's no reason to check anything.

say { msg $active $1- }

Of course, say already does that, so there's no reason to change it.

So I'm not sure what your example is supposed to show or why you think that's "clear" when it can be done the way I just showed. For other things that won't use $active, you might consider $target. Or, something like $iif($chan,$chan,$nick) or something along those lines.

If you'd like help making "clear code", then please display the real reason you need to do what you're trying to do and someone can show you how to do that cleanly.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard