mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2003
Posts: 655
Om3n Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
Not sure if this is a possible bug or known bug or intended behavior, or maybe i am misunderstanding it completely? But concider this simple exameple

alias test {
if ($2) { something }
}

Using both /test and $test methods with the provided values of $1 and $2 bleh and 0 respectively, this will fail to do 'something' because it thinks $2 does not exist when infact it does and the value is just 0.

I guess understandably, and intentionally, if the provided value of $n is $null or $false then such an if fails, but in the case of the value of $n being 0 this should not occur

Hmm, i suppose this isn't anything new when i think about it, in much the same way $(bleh,) will treat the non existance of $2 as $(bleh,0) instead of ignoring the parimatre and treating is as $(bleh)


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
It's not a bug. if ( blah ) is intended to check if blah is true/false.

0 is considered to be false in just about every language I can think of.

Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
if ( $2 == $null ) would be more appropriate to determine if it's non existant

Joined: Jun 2003
Posts: 195
N
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
wouldnt you use if ($$2) ? I thought $$ meant to fail if $2 didnt exist. So if you want to test for 0 (i.e false) as well

if ($$2) {
your code here test for 0 as well
}
else {
it didnt exist
}

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Using double $$ will make the current alias, and any higher level alias halted. In other words $$ acts like halt if the parameter had no value ($null). That else statement wouldn't even get triggered.

Just so people are clear on it:

if (value) is $false when value is: $false, $null, or 0


Gone.
Joined: Jul 2003
Posts: 655
Om3n Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
I guess given that its only to check true/false its the correct behavior, i suppose just misunderstood and figured if (bleh) checks if bleh exists/has a value.

Which is infact the impression that the mirc help files gives. In the if then else section you will find....

if (!%x) echo x has no value

So logically you would assume that "if (%x) echo x has a value" would work when the value was 0, perhaps something that should just be cleared up in the help file.

In any case, its just a few extra charactors in the code to correct the if statement, just seemed odd behavior given my understanding of its purpose.


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby

Link Copied to Clipboard