mIRC Homepage
Posted By: xrn0id quick question, which code is right? - 27/02/03 03:35 AM
if ($2 == on) && ($nick ishop || isop #ftpxdcc-wolf) .run command here

or:

if ($2 == on) && ($nick ishop $chan) || ($nick isop $chan) { .run commands }
Posted By: pod2oo5 Re: quick question, which code is right? - 27/02/03 03:45 AM
if ($2 == on) && ($nick ishop $chan) || ($nick isop $chan) { .run commands }

:| simple isnt it? jus' take a guess next time...
Posted By: Hammer Re: quick question, which code is right? - 27/02/03 08:35 AM
All of these are correct if you mean to allow normal operator precedence (&& is higher than ||):
Code:

if (($2 == on) && ($nick ishop #ftpxdcc-wolf) || ($nick isop #ftpxdcc-wolf)) { .run command here }
if ($2 == on) && ($nick ishop #ftpxdcc-wolf) || ($nick isop #ftpxdcc-wolf) { .run command here }
if ($2 == on && $nick ishop #ftpxdcc-wolf || $nick isop #ftpxdcc-wolf) { .run command here }
if $2 == on && $nick ishop #ftpxdcc-wolf || $nick isop #ftpxdcc-wolf { .run command here }
 
if (($2 == on) && ($nick ishop #ftpxdcc-wolf) || ($nick isop #ftpxdcc-wolf)) .run command here
if ($2 == on) && ($nick ishop #ftpxdcc-wolf) || ($nick isop #ftpxdcc-wolf) .run command here
if ($2 == on && $nick ishop #ftpxdcc-wolf || $nick isop #ftpxdcc-wolf) .run command here
if $2 == on && $nick ishop #ftpxdcc-wolf || $nick isop #ftpxdcc-wolf .run command here
 
if (($2 == on) && ($nick ishop #ftpxdcc-wolf) || ($nick isop #ftpxdcc-wolf)) $&
  .run command here
if ($2 == on) && ($nick ishop #ftpxdcc-wolf) || ($nick isop #ftpxdcc-wolf) $&
  .run command here
if ($2 == on && $nick ishop #ftpxdcc-wolf || $nick isop #ftpxdcc-wolf) $&
  .run command here
if $2 == on && $nick ishop #ftpxdcc-wolf || $nick isop #ftpxdcc-wolf $&
  .run command here
 
if (($2 == on) && ($nick ishop #ftpxdcc-wolf) || ($nick isop #ftpxdcc-wolf)) { 
  .run command here 
}
if ($2 == on) && ($nick ishop #ftpxdcc-wolf) || ($nick isop #ftpxdcc-wolf) { 
  .run command here 
}
if ($2 == on && $nick ishop #ftpxdcc-wolf || $nick isop #ftpxdcc-wolf) { 
  .run command here 
}
if $2 == on && $nick ishop #ftpxdcc-wolf || $nick isop #ftpxdcc-wolf { 
  .run command here 
}

If you don't want ($2 == on AND $nick ishop #ftpxdcc-wolf) OR ($nick isop #ftpxdcc-wolf), then you need to at least group the two OR'd conditions together.
Code:

if (($2 == on) && (($nick ishop #ftpxdcc-wolf) || ($nick isop #ftpxdcc-wolf))) .run command here
if ($2 == on) && (($nick ishop #ftpxdcc-wolf) || ($nick isop #ftpxdcc-wolf)) .run command here
if ($2 == on && ($nick ishop #ftpxdcc-wolf || $nick isop #ftpxdcc-wolf)) .run command here
if $2 == on && ($nick ishop #ftpxdcc-wolf || $nick isop #ftpxdcc-wolf) .run command here

NOTE: if your ".run command here" really consists of multiple commands, then { and } are required to group those commands within the condition block.

Also, you might think about switching those two ($nick is___ #ftpxdcc-wolf) conditions to a single ($nick(#ftpxdcc-wolf, $nick, oh) != $null). If you leave the parentheses around the $nick() identifier, you don't even need the != $null.
Code:

if (($2 == on) && ($nick(#ftpxdcc-wolf, $nick, oh) != $null)) .run command here
if ($2 == on) && ($nick(#ftpxdcc-wolf, $nick, oh) != $null) .run command here
if ($2 == on && $nick(#ftpxdcc-wolf, $nick, oh) != $null) .run command here
if $2 == on && $nick(#ftpxdcc-wolf, $nick, oh) != $null .run command here
 
if (($2 == on) && ($nick(#ftpxdcc-wolf, $nick, oh))) .run command here
if ($2 == on) && ($nick(#ftpxdcc-wolf, $nick, oh)) .run command here
if ($2 == on && ($nick(#ftpxdcc-wolf, $nick, oh))) .run command here
if $2 == on && ($nick(#ftpxdcc-wolf, $nick, oh)) .run command here

How you choose to format your script is largely a matter of personal choice. Some of those configurations are faster than others, some conditional expressions require parenthesis or braces to delineate when the conditional expression has stopped (such as isin or iswm). If you're not interested in optimizing your script for speed, then pick the one that makes the most "sense" to you or the one you happen to like the looks of the best. Try to stick with the same format through your script, wherever you can. You'll get used to seeing the same constructions which will make it easier for you to grasp the sense of what a section of script is supposed to be doing.
Posted By: qwerty Re: quick question, which code is right? - 27/02/03 03:46 PM
Quote:
All of these are correct if you mean to allow normal operator precedence (&& is higher than ||):


Too bad operator precedence doesn't work in mirc frown The expressions you wrote do what they're supposed to, but not because && precedes ||; only because && is to the left of ||: /if statements in mirc are just evaluated from left to right (unless otherwise specified with grouping parentheses) and the precedence of && over || is ignored.
© mIRC Discussion Forums