====== Scripting ======
To meet user-specified tasks, mAirList is offering a powerful scripting engine which provides extended control functions. With it, users may write their own programmes and expand mAirList’s functionalities significantly.
The code resembles a subset of the //Delphi/TurboPascal// language, for which a comprehensive and well-structured reference can be found under [[http://delphibasics.co.uk/|delphibasics.co.uk]]. mAirList-specific functions and procedures are to be found, formatted as a Windows help file, [[https://www.mairlist.com/download/current/mAirList/v6.1/scriptinghelp/mAirListScript.chm|here]].
**Note:** The full set of mAirList functions and -procedures is featured only in the latest version of mAirList. Therefore, unaltered scripts originating from well-aged portions of the [[https://community.mairlist.com/|mAirList Support Forum]] may be prone to cause issues (see below).
**Note 2:** Currently there is no listing which keywords of the complete //Delphi/TurboPascal// catalogue will work and which don’t. However, the subset is sufficent for most of all scripting projects. In case of doubt, the respective keyword just will not work – nothing will be damaged.
\\
===== Creating Code =====
The code can simply be typed into a text editor, Windows-supplied ''notepad.exe'' does the trick flawlessly. However, for major projects the use of some dedicated code editor, like [[https://notepad-plus-plus.org|Notepad++]], might be considered. The finished code is to be saved in UTF-8 format into a file **with the extension ''.mls''**.
The structure of a simple //Delphi/TurboPascal// programme is as follows:
const
// Constant declarations
var
// Variable declarations
{ Subprogramme definitions: }
procedure DoSomething;
begin
// Executable statements
end;
(* Main programme: *)
begin
// Executable statements
end.
**Note** the different use of semicolon '';'' and period ''.'' after the keyword ''end'' in subprogrammes and main programme respectively.
**Comments** may be typed into ''{'' curly brackets ''}'', a combination of ''(*'' parentheses and asterisk ''*)'' or behind a ''//'' double slash. While the former two can be expanded over multiple lines, the latter works for a single line or part of it only.
It is highly recommended to structure the code by indenting the statements with two whitespaces at a time.
[[https://community.mairlist.com/t/scripting-hilfe-grundkurs-1-wie-schreibe-ich-code/12387|A beginner’s tuorial]] as well as a great many of code examples can be found in the Support Forum, the tutorial however, at the time being, in German language only. {{:wiki:zeichen_123_-_arbeitsstelle_stvo_2013.svg.png?nolink&20|}}
\\
==== Background Scripts ====
For particular events within the mAirList programme, i. e. when a player is started or some marker is passed whilst playback, mAirList is calling an associated procedure by default. If no background script is available, no further action is taken. However, if a background script exists, the code therein will be executed on the said event.
An overview of the provided background script procedures is supplied with each version of mAirList within the file ''Background Script Template.mls''.
As mAirList is calling //procedures// in background scripting, their code is to be placed in the //subprogramme part// of the script. This may usually leave a sole
begin
end.
at the end (''end.'' with period!), which must not be forgotten of.
=== Parameters ===
Certain procedures provide parameters related to the regarded event – for instance the ''procedure OnPlayerStart'' yields information about the assigned player, the item being played and its position within the playlist. These can be used as variables within the procedure’s code as such:
// This code writes the item’s title into the System Log whenever a player is started:
procedure OnPlayerStart(PlaylistIndex: integer; PlayerIndex: integer; Item: IPlaylistItem);
begin
SystemLog(Item.GetTitle);
end;
begin
end.
**NOTE: It is absolutely essential to adopt the parameters in these ''On…''-procedures as given in the current version of ''Background Script Template.mls''!** Notably older scripts have to be checked thereupon before being implemented.
\\
===== Running Scripts =====
**Standalone scripts** are run by external action, such as the menu item
''mAirList > Run Script...''
or the [[reference:remote_control_commands|remote control command]]
''RUNSCRIPT ''.
For making **background scripts** actually work with mAirList, the file has to be registered in the mAirList Control Panel:
{{ :config:scripting:scripts_2.png?nolink&600 |}}
While loading, the syntax of the code is checked. In case of errors a message is written into the system log, containing (somewhat obscure) the cause of the error and its location as ''(line:column)'' within your ''.mls'' file.