mIRC Home    About    Download    Register    News    Help

Print Thread
if ( [ [ ] ] ) vs $iif( [ [ ] ] ) #87726 21/06/04 02:32 PM
Joined: Apr 2003
Posts: 701
K
Kelder Offline OP
Hoopy frood
OP Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
It may not really be a bug, but it's strange anyways smile

First some normal things
if (a == b) || ( [ [ a == b ] ] ) || $iif (a == b, $true,$false) -> all $false

Strange at first, but correct ($strip doesn't return $null, 0 or $false)
if ( $strip( a == b ) ) -> $true
$iif ($strip(a ==b), $true,$false) -> $true

And now the strange stuff:
if ( [ [ $strip( a == b ) ] ] ) -> $true
$iif ( [ [ $strip(a ==b) ] ] , $true,$false) -> $false

This means that, if you get the actual tests from file/hash/%var/$id you need either of these to do it:
if ($iif( [ [ %test ] ] ,$true,$false)) { commands }
$iif( [ [ %test ] ] ,commandiftrue,commandiffalse)
while this will not work (the same way)
if ( [ [ %test ] ] ) { commands }

Re: if ( [ [ ] ] ) vs $iif( [ [ ] ] ) #87727 21/06/04 08:28 PM
Joined: Dec 2002
Posts: 788
C
Coolkill Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
This isnt a bug, just an inconvience you might say..

$strip( ) should be used to remove control characters from strings which is what you are doing.. however the contents of $strip( ) are not evaluated, and as a result the if statement is merely checking that there is a value inside and not IF A = B.

if you notice $iif($strip(a) == $strip(b),$true,$false)) - returns False.

now try, echo $iif($strip($false == $false),$ifmatch,f) - which returns $false == $false - so it wasnt evaluated...

now, if we do.. $iif([ [ $strip($false == $false) ] ],t,f) - you get the right answer after all, by reevaulating it.

So the short and sweet answer is, that it isnt a bug, just that the contents of $strip() are not evaluated so the == isnt checked as a normal if statement.

Hope this clears it up.

Eamonn.

Re: if ( [ [ ] ] ) vs $iif( [ [ ] ] ) #87728 21/06/04 09:38 PM
Joined: Apr 2003
Posts: 701
K
Kelder Offline OP
Hoopy frood
OP Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
First of all, the use of $strip was for example purposes, replace it by $hget(test,test5) or $readini(tests.ini,tests,textmatch) or %script.startuptest or something like that for more useful applications smile

now, if we do.. $iif([[$strip($false == $false)]],t,f) - you get the right answer after all, by reevaulating it.

Make sure there are spaces around the brackets, or you'll get different results.
Wether or not $iif( [ [ $strip($false != $false) ] ] ,t,f) returns the right answer is not really the point, just that it's different from the answer of /if ( [ [ $strip($false != $false) ] ] ) { ... }

I think it has something to do with when the parameters of $identifiers are parsed (with or without [ ] )

ps: don't get me wrong, i want that ability to stay, writing a parser for all tests (isin, iswm, isop, isnum, ===) is one big slow script...

Re: if ( [ [ ] ] ) vs $iif( [ [ ] ] ) #87729 21/06/04 09:51 PM
Joined: Dec 2002
Posts: 788
C
Coolkill Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
The point that i was trying to get across is the fact that

In some cases the way you write it may determine how its evaluated for example:

//echo $iif([ [ $readini(mirc.ini,chanfolder,n1) ] ],true,f)
//if ([ [ $read(mirc.ini,chanfolder,n1) ] ]) { echo true }

- both return TRUE.. because the IF statement is checking whether there is something inside it so

if (ANYTHINGGOESHERE) { echo true } - would still be true.. which is what was happening with your $strip(A == B) example above.. however the evaulation of it using [ ]'s made mIRC reevaulate so..

if ($strip(A == B)) { .. } became..
if (A == B) { .. }

Dunno whether this will help some, lemme know..

Eamonn.