Introduction
Updates
Course Notes
Course Test
Examples
 

Getting Started | Aliases | /msg and /echo | Identifiers
If-Then-Else | Variables | Pop-Ups | Remotes

    You'll find that if-then-else and goto commands are vital to a complex script, so you'll need a good grasp of how to use them.  If you've done any programming before, you'll know basically what if-then-else statements do.  In short, If something is true, Then a command will be evaluated, or Else another command will be executed.  The Else is optional, and I rarely use it.  It can be useful if you want the script respond to an input in different ways depending on what it is.  For example, in my pinfinder script, if the pin is for a TC pin, then a different set of commands must be run than if it is a DB pin.  The following is the syntax:

If (v1 operator v2) [Then commands]
Elseif (v1 operator v2) [Then commands]
Else [commands]

     Elseif is another optional part of IF-THEN statements which I rarely use.  Basically, the first IF statement isn't true, so it checks a different statement, the ELSEIF.  You can have as many elseif's within a single if statement as you want.
     (v1 operator v2) are the two things you are comparing, for example (1 = 1), if the operation is true (1 = 1) then the next commands will be executed.  If the operation is false (1 = 2) then the next commands will not be executed, and it will move on to an elseif or else if they are present.  If the next one is an else if, the same thing will happen as above, check the operation, if true, execute commands.  If not, move to the next one.  When the script gets to the else line, it will execute those commands no matter what.  (Note: Once an if or elseif is true and runs the next commands, it will skip the remaining elseifs and else.)
     That above was a heck of a lot of if, else, then, execute, command, operations.  Probably is a bit confusing, so let's try it out.  Make a new alias:

/iftest {
if ($?="Enter a number" == 1) /echo $chan x equals 1
elseif ($! == 2) /echo $chan x equals 2
elseif ($! > 10) /echo $chan x is greater than 10
elseif ($! < 5) /echo $chan x is less than 5
else /echo $chan x is not a very good number
}
(Remember what the {} brackets, $? and $!, /echo and $chan do?)

     Ok, let's see what happens, type /iftest in a channel.  You'll be asked to enter a number.  Try 1.  You'll see x equals 1.  Try out 2.  Now it says x equals 2.  If you try 3 you'll see x is less than 5.  The number 12 will yield x is greater than 10.  While 7 will tell you x is not a very good number.

Let's take a closer look at operators.  Here are a couple of the most useful  :

== equal to
!= not equal to
< greater than
> less than
>= greater than or equal to
<= less than or equal to
isin string v1 is in string v2

You may have seen some of these in math class before, and they are pretty self explanatory.  The one you don't recognize is probably isin, which you've never seen in math class, unless you had a strange math class.  Basically, it test to see if one string of characters is in another string of characters.  So ("ell" isin "hello") would be true, but ("no" isin "hello") would not be true.  There are in all about 30-40 different operators in mIRC, a complete list can be found in the mIRC help file (do a search for ==).

{} Brackets can be used in if-then-else statements, so your commands after the if statement can go on as long as you want, let's take a look:

/ifstuff {
if ($?="Enter a number" == 1) {
/echo $chan This is line 1
/echo $chan This is line 2
/echo $chan all these are part of the if
}
/echo $chan this is not part of the if
}

(Note: Make sure that you close all {} Brackets you open in a script)

Notice that I didn't use any elseif or else lines in this script, they are always optional.  Run the script by typing /ifstuff.  You'll see the following output if you enter the number 1:

This is line 1
This is line 2
all these are part of the if
this is not part of the if

Now run it again, but enter the number 2:

this is not part of the if

So all commands within the {} brackets of an if statement are considered part of it.  If lines are a very important part of any complex script that responds to things entered.

Variables