mIRC Homepage
Posted By: Om3n if ($n) failes when $n is 0 ? - 28/12/05 11:25 AM
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)
Posted By: Collective Re: if ($n) failes when $n is 0 ? - 28/12/05 11:34 AM
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.
Posted By: ClickHeRe Re: if ($n) failes when $n is 0 ? - 28/12/05 11:47 AM
if ( $2 == $null ) would be more appropriate to determine if it's non existant
Posted By: Narusegawa_Naru Re: if ($n) failes when $n is 0 ? - 28/12/05 12:31 PM
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
}
Posted By: FiberOPtics Re: if ($n) failes when $n is 0 ? - 28/12/05 04:16 PM
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
Posted By: Om3n Re: if ($n) failes when $n is 0 ? - 29/12/05 06:46 AM
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.
© mIRC Discussion Forums