What a library is#

A library defines a cue template; a referencing cue ref creates its use. It is not a Lua function. Required parameters have no default; the user supplies param without a params wrapper.

Complete independent example#

XML
<mdscript name="WikiLibraryDemo">
  <cues>
    <library name="DescribeAmount">
      <params>
        <param name="Amount" />
        <param name="Offset" default="1" />
      </params>
      <actions>
        <set_value name="$Result" exact="$Amount + $Offset" />
        <debug_text text="$Result" />
      </actions>
    </library>
    <cue name="Small" ref="DescribeAmount">
      <param name="Amount" value="4" />
    </cue>
    <cue name="Large" ref="DescribeAmount">
      <param name="Amount" value="10" />
      <param name="Offset" value="2" />
    </cue>
  </cues>
</mdscript>

What happens#

With fresh script state, Small calculates 5 and Large calculates 12. debug_text sends these values to the diagnostic log with script output enabled. Their message order is unspecified. This example has not been executed in game.

Exercise: change only Small's Amount. Its expected result should change without editing the template or Large's inputs.

Scope#

Parameters become $Amount and $Offset when the cue is enabled. Use qualified ref="md.ScriptName.LibraryName" for another script. Behavior attributes on a referencing cue do not override the template: except for its name, behavior comes from the library.

Updating an enabled cue requires save/load checks. Egosoft's shared guide describes XR/X4 MD structure; verify the actual action set against X4. Continue with cues and variables.