Introduction
Updates
Course Notes
Course Test
Examples
 

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

     Another very important part of scripting is variables.  This is the best way to store small amounts of information to be used at a later time in the script.  There are two ways to store a variable in mIRC.  One way is more temporary, which is /var.  The other is more permanent, which is /set.  The two have slightly different syntax and usage.
     The /var command has the syntax /var %variable = stuff  and it will make the variable for only the duration of the script.  Once it finishes, the variable is deleted.   The /set command has no equals sign, so it'd be just /set %variable stuff.  This variable is saved in a special section for virtually forever.  You can view these variables by going into the aliases screen, then clicking on the last tab, variables.  Make sure you don't forget the difference in syntax, because otherwise you'll end up with variables that don't save because you forgot the =.  Or you'll have all your variables start with an = sign.
     Personally, I prefer to use the /var command whenever I only need the variable for just that script, but feel free to use either wherever you want to.  (Note: For this course, I will always use the /var instead of /set, but they are basically interchangeable if you would like to use /set).
     Another important thing to know is that variables will always have a % prefix, example names include %x  %blah  %x1  %3.  All are valid variable names.

/variables {
/var %x = hello
/echo $chan %x
}

This script will echo to the channel hello, which has been stored in the variable %x.  As you can see, variables are a pretty simple concept, but they aren't useless, for example, we can store something that the user enters:

/variables {
/var %says = $?="Enter something"
/echo $chan %says
}

     This script will echo to the channel whatever you enter in the popup box.  I like to save the channel to a variable in my longer scripts /var %chan = $chan.  Storing nicks is another good thing to use variables for.
     Variables can store either numbers or strings (letters and numbers).  Variables composed entirely of numbers can be added, subtracted, multiplied, divided etc.  There are not separate types of variables however to differentiate between a number or a string variable.  Just typing /var %x = 1 + 2 might make variable %x be a string 1 + 2 which is pretty worthless.  This is where an identifier comes in (You do remember identifiers don't you?).  This identifier is called $calc()  Basically, it will perform a calculation, so $calc(1 + 2) would yield 3, just as $calc(4 + 5 * 4 / 7 * 10) would yield....well, get your calculator.  So, let's check it out:

/addnum {
/var %chan = $chan
/var %x = $?="Enter a number"
/var %y = $?="Enter another number"
/var %z = $calc(%x + %y)
/echo %chan The numbers %x + %y equals %z
}

Run the script and enter...say...the numbers 3 and 5.  You'll see The numbers 3 + 5 equals 8.  Try out some other numbers, or try changing the script to subtracting, or dividing.  That's about all for variables, there isn't too much too them, but they are incredibly useful.

Pop-Ups