This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

How do I do a if != with 2 expresions

Old posts that have not been replied to for several years.
Locked
E
Eliminator

How do I do a if != with 2 expresions

Post by Eliminator »

hey im trying to do a script that checks for 2 difrent keywords
example "1" "2" I want to be able to
detect if $myvar != "1" || $myvar != "2"
but how do I do that without each running into each other?



Mike.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Re: How do I do a if != with 2 expresions

Post by strikelight »

Eliminator wrote:hey im trying to do a script that checks for 2 difrent keywords
example "1" "2" I want to be able to
detect if $myvar != "1" || $myvar != "2"
but how do I do that without each running into each other?



Mike.
Looks like you have it figured out already... I'm not sure what you are asking....

To tidy it up a bit:

Code: Select all

if {$myvar != "1" || $myvar != "2"} { ... }
Although, logically, what I think you may want is
"If myvar isn't "1" and if myvar isn't "2" then..."

If that's what you want, you'd need to do something like:

Code: Select all

if {$myvar != "1" && $myvar != "2"} { ... }
E
Eliminator

Post by Eliminator »

thanks man that worked jsut fine..
here is my final code that worked just great:

if {$badword(kb$chan) != "kick" && $badword(kb$chan) != "ban"} { putserv "PRIVMSG $chan :[bold]Debugging:[bold] END" ; return }

that was just a test to see if it would work.. it did so now I can remove the debuging txt and move on to the next step.. thanks..



Mike.
User avatar
TeDDyBeeR
Voice
Posts: 21
Joined: Tue Sep 02, 2003 7:11 am

Post by TeDDyBeeR »

Eliminator wrote:thanks man that worked jsut fine..
here is my final code that worked just great:

if {$badword(kb$chan) != "kick" && $badword(kb$chan) != "ban"} { putserv "PRIVMSG $chan :[bold]Debugging:[bold] END" ; return }

that was just a test to see if it would work.. it did so now I can remove the debuging txt and move on to the next step.. thanks..



Mike.
The best what to use 2 variabal checks, it set the 2 between ( ) like :

Code: Select all

if {($badword(kb$chan) != "kick") && ($badword(kb$chan) != "ban")} { putserv "PRIVMSG $chan :\002Debugging:\002 END" ; return }
note : [bold] must be \002 in tcl's :)

you can also use more checks in if:

Code: Select all

if {((expr1 != "whatever") && (expr2 == "whatever")) || (expr3 == $var)} { .... }
this is procedure will run when :
expr1 is NOT TRUE and expr2 is TRUE
or when
expr3 is TRUE
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

that's not necessary in his case, no need for the ()

it might be needed in cases when && and || are combined in the same if phrase.
example :
if {($first != "1") && ($second != "2" || $second != "3")} {...}
this means if something and anotherthing ....
another thing will be something or something. (if you know what I mean)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The && means "and" and the || means "or".. also, for bold use \002 as TeDDyBeeR sugested.
So the "if {($first != "1") && ($second != "2" || $second != "3")} {...}" should means: "If $first is not equal with 1 and $second is not equal with 2 or 3 do something.." :)
Once the game is over, the king and the pawn go back in the same box.
User avatar
TeDDyBeeR
Voice
Posts: 21
Joined: Tue Sep 02, 2003 7:11 am

Post by TeDDyBeeR »

It was just try to help you with more information about the if { ... } esle { ... }

;)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Oh, and bwt, the use of () is just for user (not the user user :) ) knowledge to see/understand the code more better/efficient or something similar to this.
Once the game is over, the king and the pawn go back in the same box.
Locked