If-Then-Else

If-Then-Else adds even more power to the mIRC Scripting language, allowing you to compare variables and identifiers then perform different commands based on the results.

How it works

The statement will compare one thing with another and based on the result will execute command(s). All statements are enclosed in {}, so for every { you'll have a }. If these get off it will not work right and might throw off the rest of that section. You can have if-then-else statements in any section except the user list. I keep the majority of my if-then-else statements in the alias section. The statements are not running constantly, they only run when specified. If you are just starting in writing if-then-else statements then you're bound to write an infinite loop sometime, when you do the only way to get out of it is to hit Ctrl+Break.
Infinite Loop Example:
loop {
  :next
  echo 4 Help I'm stuck in an infinite loop!!!
  goto next
}
Remember that Ctrl+Break will halt the loop if you ever get stuck in one.

Structuring

The structure of your if-then-else statement is very important, you need to have the {}'s and the ()'s in the right place at the right time. Here is the basic structure of a few statements:
Example 1:
aliasname {
   if ( value1 comparison value2) {
      if that happens or is true 
      execute the commands here
      else {
        if that didn't happen 
        do this
      }
   else if ( another value comparison another value) {
      then do this
      }
   }
}
Example 2:
aliasname {
   if ( value1 comparison value2) {
      then do these things
   }
   if ((value1 comparison value3) || (value2 comparison value3)) {
      execute these commands
   }
}
Example 3:
aliasname {
   set %testvar 1
   :next
   if (%testvar comparison value2) {
      then do these things
   }
   if (%testvar comparison value3) {
      goto done
   }
   inc %testvar 1
   goto next
   :done
}
These are just a couple basic examples of the many different ways to structure if-then-else statements. Just remember if (value1 comparison value2) { do these things }, and thats basically all there is to it.

Comparing Identifiers and Variables

==          string 1 equal to string 2
!=          string 1 not equal to string 2
<           string 1 less than string 2
>           string 1 larger than string 2
<=          string 1 less than or equal to string 2
>=          string 1 greater than or equal to string 2
//          string 1 multiple of string 2
\\          string 1 not a multiple of string 2
isin        string 1 is in string 2
iswm        wildcard 1 matches string 2
ison        nick 1 is on channel 2
isop        nick 1 is op'd on channel 2
isnum       number 1 is in range 2
ischan      you are on channel 1 
isauto      nick 1 is autoop for channel 2
isignore    nick 1 is in ignore list with ignore swith 2
isprotect   nick 1 is in protect list for channel 2
isnotify    nick 1 is in notify list
&&          and
||          or

Example Comparisons

optest {
   if ($$1 isop $$2) {
     echo 4 $$1 does have ops in $$2
     halt
   }
   echo 4 $$1 does not have ops in $$2
}
Then when you /optest {nick} {channel} the statment would check to see if {nick} had ops in {channel} and if they did it would echo 4 {nick} does have ops in {channel} and then halt(stops the statement right there). If {nick} did not have ops in {channel} it would echo 4 that they did not.

jointest {
   if ($me ison $$1) {
     echo 2 You're already on that channel!
     halt
   }
   join $$1
}
Now you can /jointest {chan} and the statement will check to see if you($me) are already on(ison) that channel($$1) and if you are it will echo that you're already on that channel then stop(halt). If your not on that channel it will join it($$1).

awaytest {
   if ($away == $true) {
     echo 5 You are currently marked as being away.
   }
   if ($away == $false) {
     echo 5 You are currently not marked as being away.
   }
}
awaytest2 {
   if ($away == $true) {
     echo 4 Yup, you're away.
   }
   if ($away != $true) {
     echo 4 Nope, you're still here.
   }
}
awaytest3 {
   if ($away == $true) {
     echo 6 Where'd you go?
     halt
   }
   echo 6 You're here.
}
Note: The $away identifier returns $true if you're marked away and $false
      if you are here.
There are many different ways to write a single if-then-else statement as shown with the awaytest statements . They all will do the same thing, but are quite different from each other.
timecheck {
   if ($left(2,$time) >= 20) {
     echo 2 It's past your bedtime. mIRC Shutting down. Go to bed.
     quit Goodnight Everyone
     .timer 1 10 /exit
     halt
   }
   echo 2 Its still early, you can chat a while longer.
}
This takes the left 2 characters,the hours, from the current time and if its equal to or greater than(>=) 20(10pm) it tells you to go to bed, quits irc, starts a timer to close mIRC, and stops there(halt). If its not 10pm yet it says you can stay up a little longer.


This page hosted by Get your own Free Homepage
©1996 The Scripters Guild All Rights Reserved
Please send all questions and comments to TiAMaT


1