MIRC Scripting Language
From Wikipedia, the free encyclopedia
- The correct title of this article is mIRC Scripting Language. The initial letter is shown capitalized due to technical restrictions.
The mIRC scripting language is code written in the scripting language embedded in mIRC, a popular IRC client for Windows.
Contents |
[edit] Primary uses
- Bots that provide automated IRC channel management, trivia or other games, and other desired functions for chatters
- Commands that save typing or otherwise simplify life on IRC (such as automatically identifying as the owner of a nickname)
[edit] Other uses
- MP3 players
- mIRC games
[edit] Script storage
Scripts are stored as either plain text files, usually with a .mrc file extension, or as INI files. Multiple script files can be loaded at one time.
[edit] Language features
- Built-in functions are termed commands, or identifiers if they return a value.
- Custom text-entered functions are called aliases. Aliases that return a value are known as custom identifiers. Aliases are called from the command line or other parts of a script.
- Popups are scripted context menu items. Popups are called when they are selected by the user.
- Remotes are event-handling scripts. Remotes are called when the event they handle occurs.
- All variables are dynamically typed.
- mIRC scripts make use of sigils. Identifiers (whether custom or built-in) are preceded by $, binary variables are preceded by &, and other variables (whether local or global) are preceded by %. Commands and aliases are not preceded by any particular character (although when entered from a window's command line they must be preceded by /, like any IRC command).
[edit] File handling
- Scripts can read from and write to files [$read | write]
Hower the above is intended for singular access to the file. Because each time you issue $read or /fwrite you open and close the file for access. Multiple access, during a loop for instance, is best handled through /fopen,/fwrite and /fclose. Since this opens the file only once. In some cases /filter and /savebuf is an even more efficient (non scripted loop) method.
- Scripts also can copy and delete files. [copy | remove]
[edit] Binary variables
- Contain unlimited (8192 bytes prior to mIRC 6.1) raw data
- Globally accessible via commands and identifiers
- Automatically disappear when script returns control to mIRC (and not to another part of a script)
- Prefixed with & (eg.
&Variable
)
[edit] Hash tables
- May contain unlimited binary data or up to 941 bytes of plain text. This limit is imposed by mIRC's scripting parser's own line length limitation
- Globally accessible via commands and identifiers
- Automatically disappear when exiting mIRC
- Not prefixed
[edit] Global variables
- May contain up to 946 bytes of data (however due to line-length limitations in mIRC's scripting parser, a maximum of 943 bytes can be assigned by conventional means - this number decreasing as the variable's name grows longer)
- Cannot store NUL (ASCII 0) or trailing spaces
- Globally accessible
- Do not automatically disappear (stored automatically in a mIRC initialization file)
- Prefixed with % (eg.
%Variable
) - Created using the
set
command or%Variable = value
notation
[edit] Local variables
- May contain up to 946 bytes of data (however due to line-length limitations in mIRC's scripting parser, a maximum of 943 bytes can be assigned by conventional means - this number decreasing as the variable's name grows longer)
- Cannot store NUL (ASCII 0) or trailing spaces
- Accessible only within the scope that created them
- Prefixed with % (eg.
%Variable
) - Created using the
var
.var
is merely an internal alias forset -l
butvar
poses the means to declare multiple local variables on a single line.
[edit] Limitations
- mIRC's scripting parser only supports a maximum of 947 characters per line (not including newlines or indentation).
- Strings are not syntactically enclosed, creating ambiguities in code where characters meant as literal strings are treated as part of the language's syntax.
- Each line of code is broken down into a set of space-delimited tokens. As mIRC's parser does not support null tokens and the language doesn't provide a syntax to clearly differentiate literal strings from code, it is impossible to pass multiple consecutive spaces to any command or alias. However, there is a DLL called spaces.dll that allows the use of multiple spaces.
[edit] Code examples
The code below is in the remote scripts format. If placed into an alias file, the command names should not be preceded by the word "alias".
Here is the Hello World code example:
alias hello { echo -a Hello World! }
Here is an example to count to ten:
alias ten { var %i = 1 while (%i <= 10) { echo -a %i inc %i } }
Here is an example of a remote script event handler:
on *:JOIN:#IRChelp:{ msg $chan Hi $nick }
Here is an example of picture windows:
alias cir { var %x = 0 window -ek0p @cir while (%x < 360) { inc %x drawdot @cir 4 2 $calc(($cos(%x)*50)+200) $calc(($sin(%x)*50)+200) } }