mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Now I'm lost, because that's exactly what I said. confused

"($1 == $null) and ($1) are the same (equally false) when $1 is 0 or $false"

//tokenize 32 0 | if ($1 == $null) { this condition is false }
//tokenize 32 $false | if ($1 == $null) { this condition is false }
//tokenize 32 0 | if ($1) { this condition is false }
//tokenize 32 $false | if ($1) { this condition is false }

All equally false (not the method, but rather the result and the conditions ($1 being 0 or $false)). Maybe that's clear now.

Last edited by cold; 25/12/06 09:32 PM.

* cold edits his posts 24/7
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Here is an example situation that I have seen several times:

Code:
;Code #1
on *:TEXT:!say*:#:{
if ($2 == $null) msg $nick Syntax: !say <your message here>
else msg $chan $2-
}


Code:
;Code #2
on *:TEXT:!say*:#:{
if (!$2) msg $nick Syntax: !say <your message here>
else msg $chan $2-
}


Now, if a user types this:
!say my message

In code 1, the text 'my' is not equal to $null, so the message is sent to the channel. The same happens in code 2 because 'my' isn't 0, $false, or $null.

Now, the user type this:
!say 0
(a completely valid thing to have a bot say)

In code 1, the text '0' is not equal to $null, so the message is sent to the channel, but in code 2, '0' IS equal to 0, $false, or $null, so the syntax message is sent to the $nick instead.

(BTW, Riamus2 was correct about the typo in my original post, I missed the !).

Also, I tried doing:
!say $false

And code 1 worked as expected, but to my surprise, code 2 evaluated $2 twice and read the $false as a false value instead of literal text '$false'. That's not how I would have expected it to work, so I retract my above statement about that behaviour.

-genius_at_work

Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Yeah, that's a good example on both subjects.


* cold edits his posts 24/7
Joined: Dec 2006
Posts: 18
B
bits Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Dec 2006
Posts: 18
Just to clear this up, only 0, null and "false" are false? all else is true?(eg 42 or "moo" would be true)
Is the text "null" a false? or only an empty string?

And to clarify the section of script in question was a section ripped from others and not my own to begin with.

Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
the text 'null' would be true, the text '$null' by itself is a false, however when used in the example above (code 1 doing !say $null) it would wrongly return the syntax error message.


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Quote:
Just to clear this up, only 0, null and "false" are false?


Only 0, $null, and $false are false.

The text "false" is not false.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: cold
Now I'm lost, because that's exactly what I said. confused

"($1 == $null) and ($1) are the same (equally false) when $1 is 0 or $false"

//tokenize 32 0 | if ($1 == $null) { this condition is false }
//tokenize 32 $false | if ($1 == $null) { this condition is false }
//tokenize 32 0 | if ($1) { this condition is false }
//tokenize 32 $false | if ($1) { this condition is false }

All equally false (not the method, but rather the result and the conditions ($1 being 0 or $false)). Maybe that's clear now.


As a note, your example above isn't correct. if (!$1) instead of if ($1) if you are comparing it to if ($1 == $null). Anyhow, if you tried the examples I gave you, you'd see that you'd get different results.


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
No, you just got it wrong, due to my lack of clearer words, I guess. I said: "($1 == $null) and ($1) are the same (equally false) when $1 is 0 or $false"; that is correct, and the example above is telling you exactly that. I even said I wasn't talking about the method, but rather the result. All the situations in the example represent a false statement, that's all I was talking about.
I never said ($1 == $null) and ($1) are the same comparison, and the examples you gave me are merely examples of the differences between both comparisons, which I agreed to since my first reply...


* cold edits his posts 24/7
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Originally Posted By: Om3n
the text 'null' would be true, the text '$null' by itself is a false, however when used in the example above (code 1 doing !say $null) it would wrongly return the syntax error message.


No, it wouldn't. $null isn't like $true and $false, since it doesn't return itself: it actually returns a null value.
If you enter "!say $null", both scripts from the example above will message "$null" to the channel.

What you said would happen if a timer was used before checking $2, or scid/scon commands, or $eval($2-,2), because only then mIRC would evaluate "$null" as an identifier, which value is null.
Examples:
/timerblah 1 0 if (! $+ $2-) msg $nick Syntax: !say <your message here>
/if (!$eval($2-,2)) msg $nick Syntax: !say <your message here>


To clarify (sorry if I repeat things too much from now on):

The conditions ($null), (0) and ($false) are false.
If you use "if (%blah)" and %blah is $null (really NULL, not the literal text "$null"), 0 or $false (or even the literal text "$false"), the condition will be false.

About the difference between $null/$false/$true and its literal text counterparts - $!null ("$null"), $!false ("$false"), $!true ("$true"):
$!null isn't the same as $null.
$!false is the same as $false.
$!true is the same as $true.

About ($1) and (!$1):
(!$1) is the same as ($1 == $null) || ($1 == 0) || ($1 == $false). The additional conclusion is that you could add here a "|| ($1 == $!false)" as well, since $false is the same as $!false. That would be pointless, though.
($1) is the same as ($1 != $null) && ($1 != 0) && ($1 != $false). Same thing here, you could add a "&& ($1 != $!false)".

About $null, $false and the example script by genius_at_work:
If someone says "!say $null" and your ON TEXT script checks for $2, your $2 won't be $null (the null value represented by the identifier), but rather the literal text "$null" (which is the same as $!null). The same will happen for every other identifier.
However, note that if you use this...
Code:
on *:TEXT:!say*:?:{
  if (!$2) msg $nick Syntax: !say <your message here>
  else msg $nick $2-
}

...and someone says "!say $false", your script will message the syntax warning, since your $2 will be $!false ("$false"), which is the same as $false.


That's something I find difficult to explain in english. I hope it's not too confusing.

Last edited by cold; 26/12/06 08:19 PM.

* cold edits his posts 24/7
Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
Your right i wasn't concidering its pre evaluation


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Page 2 of 2 1 2

Link Copied to Clipboard