Can mairlist scripts include other scripts?

Hi,

I have code that I would like to use in more than one mls script.

Can I import code like this (functions & procedures) into the mls scripts where I need to use it
or do I need to cut and paste the same code into every mls script I write?

An example is this function that generates a somewhat random id.

function generate_ext_id(i: integer): string;

// generate a good enough random external playlist id
var s: string;
    j: integer;
begin
  s := '#E';
  for j := 1 to 5 do
      s := s + chr(65 + random(25));
  s := s + '-' + inttostr(i);
  result := s;
end;

Inclusion works using a “special” comment syntax:

{$Include path\to\somescript.mls}

You can also defend against multiple inclusion using a preprocessor constant. If, for example, you put the following inside somescript.mls:

{$Define SOME_SCRIPT_LOADED}

You can then put this in any script that needs the functions and procedures defined in somescript.mls:

{$Ifndef SOME_SCRIPT_LOADED}
	{$Include path\to\somescript.mls}
{$Endif}

Cameron

1 Like

Interesting information; never relalized the defines and ifdef/ifndefs worked in scripts. (The scripting engine is not my work but a 3rd party library.)