From WikiChip
mirc/introduction
< mirc
Revision as of 01:54, 10 December 2013 by David (talk | contribs) (Where does the code go?)

Template:mIRC Guide

This article focuses on the very basics of mIRC. The articles target audience are people with no knowledge or very limited knowledge of the mIRC scripting language.

Where does the code go?

All your code, regardless of its type should go in the Script Editor. To open the script editor type: <Alt>+R. Alternatively, you can go to the Tools Menu -> Script editor.

All Events go in the "Remote" tab of the script editor. Popups go in the "Popups" tab of the script editor. Aliases are special. An alias may go in "Remote" tab if and only if the code is prefixed with the "alias" keyword. Otherwise it must go in the "Aliases" tab.

Remote Editor

The very basics

Before we can do anything productive, we must understand some of the most basic parts of a script.

Statements

Every script is composed of one or more statements. Each statement must go on its own line or separated by a pipe. For example, the following two are the same:

statement 1 | statement 2 | statement 3 | statement 4

and:

statement 1
statement 2
statement 3
statement 4

What's with the slashes?

If you asked any script related question in a help channel, you were probably told to type some code that begin with a forward slash. In order to execute any code from the mIRC editbox (the chat box where you normally talk), you must prefix the code with two forward slashes (in some cases only a single slash, we will talk about these cases later).

/echo command

A statement describes something that needs to happen. The most common type of statements are commands. Commands are a way to tell mIRC to perform a basic operation. By far the most common command you will be using is the /echo command. The /echo command simply prints text to the screen. Every echo command prints on a line of its own.

Let's go to an example. Type the following code from your editbox:

//echo Hello World!

You should see the following result:

Hello World!

Recall we said earlier that multiple statements can be combined by using the pipe (|)? Let's print 3 lines. Run the following code from your editbox:

//echo Scripting | echo Is | echo Fun!

You should hopefully see the following results:

Scripting
Is
Fun!

Let's make it into an alias, shall we?

At the beginning of this tutorial we talked about aliases. We said it's used to describe any script that can be reused. An alias has a name by which we can refer to it and it has a body. The body contains a statement or a list of statements that execute when we call that alias. A basic alias will look like this:

alias name <statement>

We can tweak that syntax just a little to perform multiple statements using the pipe symbol:

alias name statement 1 | statement 2 | statement 3

Let's make the code we used above to print "Scripting Is Fun!" to make an alias called "fun"

alias fun echo Scripting | echo Is | echo Fun!

A few things I should note about the code above before we continue. The first is the fact that the two // where removed; we only really need it when we want to execute code directly from the editbox. Using slash in your script editor adds nothing but clutter. Secondly, because we used the alias keyword, the code must go in the Remote Tab of the script editor. In order to use that code from the aliases tab, you must remove the "alias" keyword. The rest of the code stays the same.

Remote tab

Aliases tab

Note: When you want to execute an alias you would say you want to "call the alias".

To call our alias "fun", all we have to do is use its name:

/fun

That should print our text again:

Scripting
Is
Fun!

A block of code:

When we have a group of related commands, we call it a block of code. Most scripts, however, are not as short as our example and putting it all on one long line is messy. We can use the second format we talked about which is storing each statement on a new line. In order to do that, we have to tell mIRC "this block of code belongs to this alias". We do that by enclosing the block of code in a pair of brackets:

alias name {
  statement 1
  statement 2
  statement 3
}

A few notes about the language limitations:

  1. The opening bracket ("{") must be on the same line as the alias keyword.
  2. The opening bracket must not touch anything.
  3. The closing bracket must not touch anything else.
  4. The closing bracket must be the last part of the block of code.

Wrong examples

alias example{echo hello! }

The opening bracket is touching the "example" and "echo".

alias example { echo hello!}

The closing bracket is touching the "hello!".

alias example
{
  echo hello!
}

The opening bracket must be on the same line as the "alias" keyword.