Difference between revisions of "How to start"

From Scriptwiki
Jump to: navigation, search
m (Aliases-Tab)
m (added some info here and there)
Line 1: Line 1:
This tutorial is supposed to give an introduction into scripting in mIRC. It will explain the so-called ''Scripts-Editor'' and it's functions, followed by a little example. At the end it will give some hints about how to debug a script.
+
This tutorial is supposed to give an introduction into scripting in mIRC. It will explain the so-called ''Scripts-Editor'' and its functions, followed by a little example. At the end it will give some hints about how to debug a script.
  
  
Line 6: Line 6:
 
If you want to begin to script in mIRC, you need to open the Script-Editor. You can do it in two ways: pressing "Alt + R" or with mIRC's menubar (Tools -> Scripts Editor).
 
If you want to begin to script in mIRC, you need to open the Script-Editor. You can do it in two ways: pressing "Alt + R" or with mIRC's menubar (Tools -> Scripts Editor).
  
If you are using a premade script (for example nnscript), you will probably see a lot of code. Note that it is difficult to implement own scripts in such a premade one, as functions could interfere (if you want to change mIRC's default output for example).  
+
If you are using a premade script (for example nnscript), you will probably see a lot of code. Note that it is difficult to implement own scripts in such a premade one, as your code may interfere with the existing code (if you want to change mIRC's default output for example).  
  
 
At first, you should open a '''new remote file'''. To do it, click on File -> New (see picture below).
 
At first, you should open a '''new remote file'''. To do it, click on File -> New (see picture below).
Line 32: Line 32:
 
  moo { return moo }
 
  moo { return moo }
  
Notice that you don't need to write 'alias' infront of the new alias. Note that you cannot add events in this section.
+
Notice that you don't need to write 'alias' infront of the new alias if it's in the Aliases section and note that you cannot add events in this section.
  
 
=== Popups-Tab ===
 
=== Popups-Tab ===
Line 71: Line 71:
 
[[Image:Firstscript.png]]
 
[[Image:Firstscript.png]]
  
If you are scripting something more complex, you want to use the "{}"-button in the upper right corner (see below).
+
If you are scripting something more complex, you want to use the "{}"-button in the upper right corner (see below). That button is used to check for bracket mis-matches in the scriptfile.
 +
 
  
 
[[Image:Bracket-button.png]]
 
[[Image:Bracket-button.png]]
  
  
If you've pressed it and nothing happended, everything is ok (note that it doesn't mean that your scripts will work, just that there is no obvious bracket mistake (mIRC just counts the open and closed brackets)). If something's wrong, you will get the following popup:
+
If you've pressed it and nothing happended, everything is ok (note that it doesn't mean that your scripts will work, just that there are no obvious bracket mistakes (mIRC just counts the open and closed brackets)). If something's wrong, you will get the following popup:
  
 
[[Image:Bracketerror.png]]
 
[[Image:Bracketerror.png]]
 +
 +
Even if it says that the bracket error is ''around'' line 1, it could be almost anywhere. Start you search from that line and look at the indentations to find out where you're missing a bracket.
  
 
=== Users-Tab ===
 
=== Users-Tab ===
  
In this file your userlist is saved. You don't need to edit it manually, as there are aliases to do so. See [[auser]], [[guser]] and [[ruser]].
+
In this file your userlist is saved. You don't need to edit it manually, as there are commands to do it. See [[auser]], [[guser]] and [[ruser]].
  
 
=== Variables-Tab ===
 
=== Variables-Tab ===
Line 99: Line 102:
 
  }
 
  }
  
With this method, you can exactly see where it stops to work and correct this part.<br>
+
With this method, you can see exactly where it stops to work and correct this part.<br>
'''Note''' You cannot trigger on text, on notice, on action... events by yourself, for that you will need someones help or another client or multiserver (/server -m ...) to test them.
+
'''Note''' You cannot trigger on text, on notice, on action... events by yourself, you will need someone's help or another client or multiserver (/[[server]] -m ...) to test them.
  
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Revision as of 10:50, 11 September 2006

This tutorial is supposed to give an introduction into scripting in mIRC. It will explain the so-called Scripts-Editor and its functions, followed by a little example. At the end it will give some hints about how to debug a script.


The Remote Editor

If you want to begin to script in mIRC, you need to open the Script-Editor. You can do it in two ways: pressing "Alt + R" or with mIRC's menubar (Tools -> Scripts Editor).

If you are using a premade script (for example nnscript), you will probably see a lot of code. Note that it is difficult to implement own scripts in such a premade one, as your code may interfere with the existing code (if you want to change mIRC's default output for example).

At first, you should open a new remote file. To do it, click on File -> New (see picture below).


Newfile.png

Note that your script files will be saved automatically; all you need to do is pressing 'Ok'.

The next part is about the five different tabs of mIRC's Scripts Editor:

Scriptseditortabs.png


Aliases-Tab

Basically, you do not need to use aliases.ini (that you can edit using this tab). Usually, if you want to add a new alias, it would look like:

alias moo { return moo }

in your 'Remote-Section' of the editor (the one that's active after pressing Alt + R).

You can add the same alias in your Aliases-Section:

moo { return moo }

Notice that you don't need to write 'alias' infront of the new alias if it's in the Aliases section and note that you cannot add events in this section.

Popups-Tab

Again you do not need to use this section. It's the same as using the menu alias in the remote section. Usually, there will be some menus added in this section (for example your nicklist-menu).

Popupsview.png

Remote-Tab

This is the "maintab". Every script is supposed to be saved in here.

Note that you should not have two same events in one file, as only the first matching one will be triggered. Example:

; will be triggered
on *:Text:*:*: { echo moo }

; will never be triggered
on 10:Text:*:*: { echo maa }
; will be trigger for level 10
on 10:Text:*:*: { echo maa }

; will be triggered for all but level 10
on *:Text:*:*: { echo moo }


So if you aren't sure whether it will work or not, just use another (a new) file (look above to see how to make a new file).

The following script will trigger on every "!moo" in every channel and response with "moo00oo00":

on *:TEXT:!moo:#: {
 msg $chan moo00oo00
}

This would look like:

Firstscript.png

If you are scripting something more complex, you want to use the "{}"-button in the upper right corner (see below). That button is used to check for bracket mis-matches in the scriptfile.


Bracket-button.png


If you've pressed it and nothing happended, everything is ok (note that it doesn't mean that your scripts will work, just that there are no obvious bracket mistakes (mIRC just counts the open and closed brackets)). If something's wrong, you will get the following popup:

Bracketerror.png

Even if it says that the bracket error is around line 1, it could be almost anywhere. Start you search from that line and look at the indentations to find out where you're missing a bracket.

Users-Tab

In this file your userlist is saved. You don't need to edit it manually, as there are commands to do it. See auser, guser and ruser.

Variables-Tab

All your global variables are saved in here. Again, you don't need to edit it manually, as you can use set, unset or unsetall.


How to debug

After you've written some lines and you've tested it, you will most likely notice, that it doesn't do what you expect it to do. The next step is to debug your script. At first take a look at your Status Window and check for error messages. If there are any, search for these errors in your script and correct them. If they aren't any, you should add echo's in your script to see where it stops to work. For example:

on *:TEXT:*:*: {
 if (%moo) { echo -a we are here }
 elseif (%moo2) { echo -a we are here 2 } 
 echo -a after the if clauses
}

With this method, you can see exactly where it stops to work and correct this part.
Note You cannot trigger on text, on notice, on action... events by yourself, you will need someone's help or another client or multiserver (/server -m ...) to test them.