mIRC Scripting Tutorial — File Browser

mIRCScriptingTutorialv1.0 / mIRCScriptingTutorialv1.0 / tutorial01 / operators.htm

operators.htm — 13.38 KB — Download this file

<html>
<head>
<title>SpyderWares</title>
<meta name="keywords" content="mIRC, mIRC scripts, mIRC addons, mIRC add-ons, scripts, scripting, mIRC scripting, IRC, mIRC, mIRC bots, bots">
<meta name="description" content="SpyderWares: Kewl add-ons for mIRC">
  <style>
body {
scrollbar-arrow-color: #2A2B2C; 
scrollbar-base-color: #363738;
scrollbar-face-color: #686A6C; 
scrollbar-highlight-color: #2A2B2C; 
scrollbar-shadow-color: #363738
}
.head { color: #3589FB; font-size:11; font-weight:bold; font-family:arial; position:absolute ; top:20; left:325 }
.body { color: #909090; font-size:11; font-family:arial }
.code { font-family: "courier new"; color: #008000; font-size: 8pt; }
.type { font-family: terminal; color: #C0C0C0; font-size: 8pt; }
.links { color: #3589FB; font-size:11; font-weight:bold }

  </style>
</head>
<body bgcolor="#000000" leftmargin="60" rightmargin="60" link="#3589FB" vlink="#3589FB">
  <span class=head>
    Scripting Tutorial: Operators
  </span>
  <div class=body>
    <br>
    <br>
    <br>
Operators are 'things' that do 'things' to 'things'. He he. Ok that was a little too vague a definition. It will become clear to you from the examples below. They basically perform operations on values. They have many functions and are classified accordingly. They may be used to perform mathematical operations, evaluate a condition etc. They are always used with <a href=statements.htm>Statements</a>. The mIRC Help File lists a table of operators but they are kind of incomplete for a beginner. So I have created my own list with a slightly different way of classification.
<br><br>
<b>Arithmetic Operators</b>
<br>
All the arithmetic operators in mIRC are used within the $calc() identifier. You don't use them like in other programming languages. 
<br>
<br>
<span class=code> + </span> &nbsp; Addition. <br>
<span class=code> - </span> &nbsp; Subtraction. <br>
<span class=code> * </span> &nbsp; Multiplication. <br>
<span class=code> / </span> &nbsp; Division. <br>
<span class=code> % </span> &nbsp; Modulo. <br>
<br>
Maybe some of the newbies are not aware of the Modulo operator. It returns the remainder when the first operator is divided by the second operand an integral number of times. This particular operator needs special coverage because of two reasons. First, many people are encountering this operator for the first time. Second, because mIRC variables use the % sign which can confuse the <span class=code>$calc()</span> identifier.
<br><br>
When performing the modulo operation always make sure the operator has spaces at it's sides or else <span class=code>$calc()</span> will assume the second operand as a variable and you could get very odd results.
<br><br>
Don't: <span class=code>$calc(5%4)</span> &nbsp; &nbsp; &nbsp; &nbsp; // The interpreter will assume a variable named %4.<br>
Do: <span class=code>$calc(5 % 4)</span> or <span class=code>$calc(5% 4)</span> &nbsp; &nbsp; &nbsp; &nbsp; // Notice 4 is not touching %
<br>
Note: Other operators need not have spaces at it's sides. <span class=code>$calc(5+4)</span> or <span class=code>$calc(5 + 4)</span>, both are valid.
<br><br>
A few examples demonstrating the modulo operator in action:
<br>
<span class=code>$calc(5 % 4)</span> returns 1. &nbsp; &nbsp; &nbsp; &nbsp; // 5 can be divided by 4 integrally only once and what remains is 1.<br>
<span class=code>$calc(8 % 4)</span> returns 0. &nbsp; &nbsp; &nbsp; &nbsp; // 4 divides 8 integrally twice with no remainder.<br>
<span class=code>$calc(15 % 4)</span> returns 3. &nbsp; &nbsp; &nbsp; &nbsp; // 4 can divide 15 to three integral parts (till 12). The result of 15 modulo 4 is 3. [15%4=3=15-12].
<br><br>
There are two special operators in mIRC which are not used within the $calc() identifier. They are used like regular operators.
<br>
<span class=code> // </span> &nbsp; The second operator is a multiple of the first operator.
<br>
<span class=code> \\ </span> &nbsp; The second operator is not a multiple of the first operator.
<br>
<br>
<b>Equality and Identity Operators</b>
<br>
<span class=code> == </span> &nbsp; Returns true if its two operands are equal. <br>
<span class=code> === </span> &nbsp; Returns true if it's two operands are identical (case-sensitive). <br>
<span class=code> != </span> &nbsp; Returns true if it's two operands are not equal. <br>
<span class=code> !== </span> &nbsp; Returns true if it's two operands are not identical. (case-sensitive). <br>
<br>
Side note: For those who have never programmed before, in most of the programming languages the <span class=code>=</span> sign is not the equality operator. Except in Pascal (and it's derivatives), Ada and Eiffel it's the assignment operator. That is, it's used to assign values to variables. In mIRC the use of the assignment operator is optional <span class=code>var %i = 0</span> does the same job as <span class=code>var %i 1</span>. If you use the <span class=code>=</span> sign make sure the two operands don't touch the assignment operator or your script won't work. Those who have programmed in Bash shell will acknowledge mIRC script is similar to Bash script in many ways and one of them being this 'touchy' property. Typed language programmers should keep in mind you don't declare the variables type in mIRC. Do that and you have a buggy script.
<br><br>
<b>Comparison Operators</b>
<br>
<span class=code> < </span> &nbsp; Less than. <br>
<span class=code> > </span> &nbsp; More than. <br>
<span class=code> <= </span> &nbsp; Less than or equal. <br>
<span class=code> >= </span> &nbsp; More than or equal. <br>
<br>
<b>Logical Operators</b>
<br>
Logical Operators are typically used to perform "Boolean Algebra". They are used in conjugation with comparison or other evaluative operators in <span class=code>if</span> and <span class=code>while</span> statements.
<br><br>
<span class=code> && </span> &nbsp; Logical AND. Returns <span class=code>true</span> if and only if it's two operands are <span class=code>true</span> else returns <span class=code>false</span>. <br>
<img src=../images/spacer.gif height=1 width=86> Eg: <span class=code> if ((%c == 24) && ($nick == %nick.002)) </span>
<br><br>
<span class=code> || </span> &nbsp; Logical OR. Returns <span class=code>true</span> if one or both of the two operands are <span class=code>true</span> else returns <span class=code>false</span>. <br>
<img src=../images/spacer.gif height=1 width=86> Eg: <span class=code> if ((%i <= 10 ) && ($nick == $me)) </span>
<br><br>
For those curious about the logical NOT operator (<span class=code>!</span>), it's used in some operators and conditions and to check the state. For example:
<br>
<img src=../images/spacer.gif height=1 width=86> <span class=code>if (%a != 25) echo -a %a is not equal to 25! </span>
<br>
<img src=../images/spacer.gif height=1 width=86> <span class=code>if (%test !alnum) echo -a %test contains things apart from letters and numbers! </span>
<br>
<img src=../images/spacer.gif height=1 width=86> <span class=code>if (!%lp) echo -a The variable %lp doesn't exist.</span>
<br>
<img src=../images/spacer.gif height=1 width=86> <span class=code>if (!$dialog(test)) echo -a The dialog named test is not open.</span>
<br><br>
<b>Alphanumerical Operators</b>
<br>
<span class=code> isin </span> &nbsp; The first operand is in the second operand. Eg: <span class=code>if (le isin apple) echo -a It's there! | else echo -a It's not there!</span>
<br>
<span class=code> isincs </span> &nbsp; The first operand is in the second operand, case-sensitive. Eg: <span class=code>if (lE isin apple) echo -a It's there! | else echo -a It's not there!</span>
<br>
<span class=code> iswm </span> &nbsp; If the first operand wildcard is in second operand. Examples:
<br>
<img src=../images/spacer.gif height=1 width=55><span class=code>if (*le* iswm pleees) echo -a It's there! | else echo -a It's not there!</span>
<br>
<img src=../images/spacer.gif height=1 width=55><span class=code>if (Hum* iswm humanity) echo -a It's there! | else echo -a It's not there!</span>
<br>
<span class=code> isnum </span> &nbsp; The first operand (a number) is in the second operand (a range).
<br>
<img src=../images/spacer.gif height=1 width=55>Eg: <span class=code>if (4 isnum 2-9) echo -a It's there! | else echo -a It's not there!</span>
<br>
<img src=../images/spacer.gif height=1 width=38>The isnum operator can also be used to check if a value is a number. In this case it takes only the first operator. 
<br>
<img src=../images/spacer.gif height=1 width=55>Eg: <span class=code>if (%u isnum) echo -a It's a number! | else echo -a It's not a number!</span> 
<br>
<img src=../images/spacer.gif height=1 width=55>For the above example to work you should have already set a variable named %u. It's whose data value we'll be checking.
<br>
<span class=code> isletter </span> &nbsp; The first operand (a letter) is in the second operand (a word).
<br>
<img src=../images/spacer.gif height=1 width=55>Eg: <span class=code>if (c isletter cat) echo -a It's there! | else echo -a It's not there!</span>
<br>
<img src=../images/spacer.gif height=1 width=38>The isletter operator can also be used to check if a value is a letter or composed of letters only. 
<br>
<img src=../images/spacer.gif height=1 width=55>Eg: <span class=code>if (%u isletter) echo -a It's a letter! | else echo -a It's not a letter!</span> 
<br><br>
The following operators take only one operator.
<br><br>
<span class=code> isalnum </span> &nbsp; The operand contains only letters and numbers.
<br>
<span class=code> isalpha </span> &nbsp; The operand contains only letters.
<br>
<span class=code> islower </span> &nbsp; The operand contains only lower case letters.
<br>
<span class=code> isupper </span> &nbsp; The operand contains only upper case letters.
<br><br>
<b> IRC Related Operators</b>
<br>
<span class=code> ison </span> &nbsp; A nick (the first operator) is on a channel (the second operator).
<br>
<span class=code> isop </span> &nbsp; A nick (the first operator) is an OP on a channel (the second operator).
<br>
<span class=code> ishop </span> &nbsp; A nick (the first operator) is a half OP on a channel (the second operator).
<br>
<span class=code> isvoice </span> &nbsp; A nick (the first operator) is voiced on a channel (the second operator).
<br>
<span class=code> isreg </span> &nbsp; A nick (the first operator) is a regular (normal) nick on a channel (the second operator).
<br>
<span class=code> ischan </span> &nbsp; If you are on a channel (the first operator).
<br>
<span class=code> isban </span> &nbsp; If an address (the first operator) is in the Internal Ban List.
<br>
<span class=code> isaop </span> &nbsp; If a nick (the first operator) is in your auto-op list for a channel (the second parameter). The second parameter is optional.
<br>
<span class=code> isavoice </span> &nbsp; If a nick (the first operator) is in your auto-voice list for a channel (the second parameter). The second parameter is optional.
<br>
<span class=code> isignore </span> &nbsp; If a nick (the first operator) is in your ignore list with an ignore switch (the second parameter). The second parameter is 
<br>
<img src=../images/spacer.gif height=1 width=48>optional. Refer the ignore command to know more about it's switches.
<br>
<span class=code> isnotify </span> &nbsp; If a nick (the first operator) is in your notify list.
<br>
<br>
Note: To negate an operator you prefix it with the Logical NOT (!) operator.
<br><br>
<b>Two more Operators</b><br>
<span class=code> $+ </span> &nbsp; This operator concatenates the two operands. It joins the parameters before and after it. They should be separated by the space<br>
&nbsp; &nbsp; &nbsp; &nbsp; character and may or may not be contained within an identifier. Eg: <span class=code>//echo -a Spyder $+ Wares</span> echoes "SpyderWares".<br>
<span class=code> | </span> &nbsp; The pipe operator. It's function is very different from the pipe in Bash, Perl etc. What it does in mIRC is equivalent to the semicolon (;) 
<br> &nbsp; &nbsp; &nbsp; &nbsp; operator in other programming languages. Not exactly to mark the end of an expression but to contain two expressions in one line.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; Examples: Refer the examples for Alphanumerical Operators.
<br><br>
There is a special identifier <span class=code>$ifmatch</span> which returns the first operand of a matching conditional statement. Examples:
<br><br>
<span class=code>
&nbsp; &nbsp; &nbsp; if (*itni* iswm mitnick) { echo -a $ifmatch } </span> &nbsp; Retuns "*itni*".
<br>
<span class=code>
&nbsp; &nbsp; &nbsp; if (pp isin apple) { echo -a $ifmatch } </span> &nbsp; Returns "pp".

<p>
That was all about Operators. Next we'll take a look at Statements without which the Operators don't have any functionality. Not that Statements can be very functional without the Operators either. Both of them are interdependent.

<p>
      <br>
      <a href=variables.htm>
        Back</a>
      |
      <a href=index.htm>
        Table of Contents</a>
      |
      <a href=statements.htm>
        Statements</a>
        

<br>
<img src=img/spacer.gif height=50 width=10>
<br>
<center>
<img src=img/spyder.gif> 
<br><br>
<font size=-2>
Copyright &copy; 2002-2004 SpyderWares.
<br>
Feel free to distribute this tutorial in part or whole, just make sure the credits stay intact.
</font>
<br>
<a href=http://spyderwares.com target="_blank">
http://spyderwares.com
</a>
</center>

<p><br><br>

</div>
</body>
</html>