Changes for page Mission Director Guide
Last modified by Klaus Meyer on 2025/03/31 16:39
From version 31068.1
edited by Daniel Turner
on 2023/04/14 16:47
on 2023/04/14 16:47
Change comment:
Created page with "{{Info |body = Please note that this is officially-maintained documentation. To ensure that you can rely on the information having been checked by Egosoft, you will not be able to edit this page. }} <span style="color: rgb(0,0,0);text-decoration: none;"><br /> </span> <span style="color: rgb(0,0,0);text-decoration: none;">The Mission Director (MD) is a subsystem of the game and interprets mission scripts, which are written in an XML-based language. The Mission D..."
To version 32976.1
edited by Heinrich Unrau
on 2024/10/17 13:50
on 2024/10/17 13:50
Change comment:
There is no comment for this version
Summary
-
Page properties (5 modified, 0 added, 0 removed)
-
Attachments (0 modified, 1 added, 0 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 - X4:X4 Documentation/X4 Game Design/0 General/Mission Director Guide1 +Mission Director Guide - Parent
-
... ... @@ -1,0 +1,1 @@ 1 +X Rebirth Wiki.Modding support.WebHome - Author
-
... ... @@ -1,1 +1,1 @@ 1 -xwiki:XWiki. Daniel1 +xwiki:XWiki.Heinrich - Tags
-
... ... @@ -1,1 +1,1 @@ 1 -Broken_macro/anchor 1 +Broken_macro/anchor|Broken macro/anchor - Content
-
... ... @@ -1,1233 +1,1249 @@ 1 - {{info body="Pleasenotethatthis isofficially-maintained documentation.1 +The Mission Director (MD) is a subsystem of the game and interprets mission scripts, which are written in an XML-based language. The Mission Director in X Rebirth and X4 is based on the MD in X3: Terran Conflict, with some major changes based on feedback from MD users. 2 2 3 - Toensurethatyoucanrelyon theinformation having beencheckedbyEgosoft,youwillnot be abletoeditthispage."/}}3 +An introduction to the original MD can be found in the [[Egosoft forums>>url:http://forum.egosoft.com/viewtopic.php?t=196971]]. There is also a PDF guide for the X3 Mission Director, which is partially used as a template for this document. 4 4 5 +This document is primarily supposed to be a guide for MD users (people who use the MD to develop missions or write other MD scripts), not for MD programmers (people who work on the MD engine in C++). 5 5 7 +{{info}} 8 +The general MD scripting system is the same in XR and X4, so this guide applies to both games. However, each game has its own set of supported script features (i.e. actions, conditions and properties), so in general scripts from different games are not compatible. 9 +{{/info}} 6 6 7 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 8 8 9 - 10 -(% style="color: rgb(0,0,0);text-decoration: none;" %)The Mission Director (MD) is a subsystem of the game and interprets mission scripts, which are written in an XML-based language. The Mission Director in X Rebirth and X4 is based on the MD in X3: Terran Conflict, with some major changes based on feedback from MD users. 11 - 12 - 13 -(% style="color: rgb(0,0,0);text-decoration: none;" %)An introduction to the original MD can be found in the(%%)[[(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á(% style="color: rgb(0,0,153);text-decoration: underline;" %)Egosoft forums>>url:http://forum.egosoft.com/viewtopic.php?t=196971]](% style="color: rgb(0,0,0);text-decoration: none;" %). There is also a PDF guide for the X3 Mission Director, which is partially used as a template for this document. 14 - 15 -(% style="color: rgb(0,0,0);text-decoration: none;" %)This document is primarily supposed to be a guide for MD users (people who use the MD to develop missions or write other MD scripts), not for MD programmers (people who work on the MD engine in C++). 16 - 17 -(% style="color: rgb(0,0,0);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %)The general MD scripting system is the same in XR and X4, so this guide applies to both games. However, each game has its own set of supported script features (i.e. actions, conditions and properties), so in general scripts from different games are not compatible. 18 - 19 - 20 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 21 - 22 - 23 -(% id="table-of-contents" %) 24 - 25 -= (% style="color: rgb(0,0,0);text-decoration: none;" %)Table of Contents(%%) = 26 - 27 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 28 - 29 29 {{toc/}} 30 30 31 - (%style="color: rgb(0,0,0);text-decoration:none;" %)14 += MD scripts = 32 32 16 +MD scripts are not necessarily missions. An MD file can contain a part of a mission, multiple missions, or no mission at all, as the MD is used for more than just missions. 33 33 34 - (%id="md-scripts"%)18 +MD files are XML files located in the game folder **md**. All XML files in that folder are loaded at game start. The file names are irrelevant, since the internally used script names are read from the XML root nodes. However, it's recommended to keep file name and internal script name identical to avoid having to look up the names. 35 35 36 - =(%style="color:rgb(0,0,0);text-decoration:none;"%)MD scripts(%%)=20 +To edit MD scripts, an XML editing tool is needed. Microsoft Visual Studio (if available) or [[Microsoft Visual Web Developer>>url:http://www.microsoft.com/express/vwd/]] (for free) are highly recommended because they have pretty good support for XML schemas (XSD). The provided Mission Director schema files help you create the XML file by displaying all available tags and attributes as you edit the XML. 37 37 38 - (%style="color:rgb(0,0,0);text-decoration:none;" %)MDscriptsare notnecessarilymissions.AnMDfilecancontainapartof amission,multiplemissions,ornomissionat all,astheMD isusedformore thanjustmissions.22 +This functionality is only available if the schema files **md.xsd** and **common.xsd** are in the correct folder. If you are editing the XML in the game folder directly, all is well and the files are loaded from the libraries folder. However, if you are editing in a separate folder, copy those XSD files from the libraries folder directly into the folder where your XML files are located. 39 39 40 -(% style="color: rgb(0,0,0);text-decoration: none;" %)MD files are XML files located in the game folder {{code}}md{{/code}}. All XML files in that folder are loaded at game start. The file names are irrelevant, since the internally used script names are read from the XML root nodes. However, itΓÇÖs recommended to keep file name and internal script name identical to avoid having to look up the names. 24 +{{info}} 25 +Even if your script is free of XSD errors, that does not mean that the script syntax is correct. For example, there are XML elements that require at least one of multiple attributes, but this requirement cannot be reflected in a schema (apart from documentation text). Please notice the XSD documentation of the elements and attributes, e.g. displayed via tooltips in Visual Studio / Visual Web Developer. Please also note additional requirements for MD cue attributes in this guide (see [[Conditions>>doc:||anchor="HConditions" style="outline-width: 0px !important; user-select: auto !important;"]]). 41 41 42 -(% style="color: rgb(0,0,0);text-decoration: none;" %)To edit MD scripts, an XML editing tool is needed. Microsoft Visual Studio (if available) or (%%)[[(% style="color: rgb(0,0,153);text-decoration: underline;" %)Microsoft Visual Web Developer>>url:http://www.microsoft.com/express/vwd/]](% style="color: rgb(0,0,0);text-decoration: none;" %) (for free) are highly recommended because they have pretty good support for XML schemas (XSD). The provided Mission Director schema files help you create the XML file by displaying all available tags and attributes as you edit the XML. 27 +To check for errors, please pay attention to in-game error messages that are produced while your script is imported, and run-time errors while the script runs. The XSD files can help you a lot, but you should not rely on the absence of XSD errors." 28 +{{/info}} 43 43 44 - (% style="color: rgb(0,0,0);text-decoration: none;" %)This functionality is only available if the schema files (%%)**(% style="color:rgb(0,0,0);text-decoration: none;" %)md.xsd(%%)**(% style="color:rgb(0,0,0);text-decoration: none;" %) and (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)common.xsd(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) are in the correct folder. If youare editingthe XML in the game folder directly, all is well and the files are loaded from the libraries folder. However, if youare editing in a separate folder, copy those XSD files from the libraries folder directly into the folder where your XML files are located.30 +== Script debug output == 45 45 46 - {{notebody="Evenif yourscriptis free of XSD errors,that doesnot meanthat thescript syntaxis correct. For example,thereare XML elementsthat requiretleastoneofmultiplettributes,but this requirementcannotbereflectedinschema(apartfromdocumentation text).Please noticetheXSD documentationof theelementsand attributes,e.g.displayedviatooltips inVisual Studio/ Visual WebDeveloper. Please also note additionalrequirementsfor MD cue attributes inthis guide (see [[NULL|Conditions]]).32 +The game can print error messages and, when enabled, also general messages. Error messages can originate from the scripting system, but also from other game sub-systems. They can be viewed in the in-game [[DebugLog>>url:https://forum.egosoft.com/viewtopic.php?t=366654]]. 47 47 48 -To c heck for errors, please pay attentionto in-gameerrormessagesthatareproduced whileyourscriptis imported,and run-timeerrorswhilethescriptruns. TheXSDfiles can help youalot, but youshouldnot rely on the absenceof XSDerrors."/}}34 +To collect all messages in a file, start the game with the following parameters on the command line: 49 49 36 +{{code language="xml"}} 37 +-logfile debuglog.txt 38 +{{/code}} 50 50 40 +All messages, including enabled non-error messages, will be written into the log file. You can find it in your personal folder, where your save folder is located. To enable scripting-specific debug messages, add the following to the command line: 51 51 52 -(% id="categorybroken_macroanchorscript-debug-output" %) 42 +{{code language="xml"}} 43 +-debug scripts 44 +{{/code}} 53 53 54 - ==(%style="color:rgb(0,0,0);text-decoration:none;"%)Scriptdebugoutput(%%)==46 +Other debug filters other than "scripts" can be enabled by repeating the -debug command for each filter name, but that is rarely needed for scripting. 55 55 56 - (%style="color: rgb(0,0,0);text-decoration:none;" %)Thegame canprinterrormessages and,when enabled, alsogeneralmessages.Errormessagescan originatefromthe scripting system, but also from other game sub-systems. They can be viewedinthe (% style="color: rgb(0,0,0);text-decoration:none;" %)in-game[[DebugLog>>url:https://forum.egosoft.com/viewtopic.php?t=366654]].48 +The script action <debug_text> can be used to print debug messages from within a script. 57 57 58 - (% style="color:rgb(0,0,0);text-decoration:none;" %)(%style="color: rgb(0,0,0);text-decoration: none;" %)To collectall messages(%%) in a file, startthe game with the following parameterson the command line:50 += MD script structure = 59 59 60 - (%style="color:rgb(0,0,0);text-decoration:none;"%)(%style="color:rgb(0,0,0);text-decoration:none;"%){{code}}-logfile debuglog.txt{{/code}}52 +In this section we will look at how to start the whole process by creating a new MD mission file and the basic steps in producing mission content with XML code. There will be a description of the key elements of the mission file. 61 61 62 - (% style="color:rgb(0,0,0);text-decoration:none;" %)All messages, includingenablednon-errormessages, will be writtenintothe logfile.You can find it in your personalfolder, where your save folder islocated.To enablescripting-specificdebug messages, addthe following tothe commandline:54 +The XML root node of an MD file is called "mdscript" and looks like this: 63 63 64 -(% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}-debug scripts{{/code}} 56 +{{code language="xml"}} 57 +<?xml version="1.0" encoding="utf-8"?> 58 +<mdscript name="ScriptName" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd"> 59 +{{/code}} 65 65 66 - (% style="color: rgb(0,0,0);text-decoration:none;"%)(%style="color:rgb(0,0,0);text-decoration:none;"%)Otherdebugfiltersotherthan"scripts"canbeenabledby repeatingthe-debugcommandfor eachfiltername,but that israrelyneededfor scripting.61 +"ScriptName" is the name used for this script regardless of the file name. It **has to start with an upper case letter and must be unique** among all MD script names. It also should not contain spaces, so other MD scripts can use it as an identifier to access this script's contents easily. 67 67 63 +The only allowed sub-node of <mdscript> is <cues>, which can only contain <cue> sub-nodes: 68 68 69 -(% style="color: rgb(0,0,0);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %)The script action <debug_text> can be used to print debug messages from within a script. 65 +{{code language="xml"}} 66 +<?xml version="1.0" encoding="utf-8"?> 67 +<mdscript name="ScriptName" ...> 68 + <cues> 69 + <cue name="RootCue1"> [...] 70 + </cue> 71 + <cue name="RootCue2"> [...] 72 + </cue> 73 + </cues> 74 +</mdscript> 75 +{{/code}} 70 70 77 +== Cues == 71 71 72 - (%style="color:rgb(0,0,0);text-decoration:none;"%)79 +Cues are the main ingredient of an MD script. A cue consists of a set of **conditions** and a set of **actions**. When the conditions are met, the cue is activated and the actions are performed. A cue can have child cues, or **sub-cues**: A sub-cue exists only when its parent cue has become active, so the activation of the parent cue initiates the condition checks of its child cues. 73 73 81 +A cue can have the following states: 74 74 75 -(% id="md-script-structure" %) 83 +* **Disabled**: The parent cue has not become active yet, so this cue is basically non-existing. 84 +* **Waiting**: Either this is a root cue, or the parent has become active. The cue is checking its conditions and will become active when they are met. 85 +* **Active**: The cue is about to perform the actions. Child cues have entered the waiting state. 76 76 77 -= (% style="color: rgb(0,0,0);text-decoration: none;" %)MD script structure(%%) = 87 +* **Complete**: The cue has finished performing its actions. 88 +* **Cancelled**: The cue has been cancelled. This state cannot normally be reached but only if a cue actively cancels itself or another cue. No condition checks or actions are performed in this cue or any sub-(sub-)cue. 78 78 79 -(% style="color: rgb(0,0,0);text-decoration: none;" %)In this section we will look at how to start the whole process by creating a new MD mission file and the basic steps in producing mission content with XML code. There will be a description of the key elements of the mission file. 90 +{{info}} 91 +There can be a delay between the activation and performing the actions if the <delay> tag is used. In this case, sub-cues will be enter the waiting state before the parent's actions are performed. 92 +{{/info}} 80 80 81 - (%style="color:rgb(0,0,0);text-decoration:none;" %)The XML rootnode ofanMD file iscalledΓÇ£mdscriptΓÇ¥ and looks likethis:94 +This is how a cue node looks like: 82 82 83 -{{code}}<?xml┬áversion="1.0"┬áencoding="utf-8"?><mdscript┬áname="ScriptName"┬áxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"┬áxsi:noNamespaceSchemaLocation="md.xsd">{{/code}} 96 +{{code language="xml"}} 97 +<cue name="CueName"> 98 + <conditions> [...] 99 + </conditions> 100 + <delay exact="5s" /> 101 + <actions> [...] 102 + </actions> 103 + <cues> [...] 104 + </cues> 105 +</cue> 106 +{{/code}} 84 84 85 - (% style="color:rgb(0,0,0);text-decoration:none;" %)ΓÇ£ScriptNameΓÇ¥is thenameusedforthisscriptregardlessof thefilename.It (%%)**(%style="color: rgb(0,0,0);text-decoration: none;" %)hasto startwith an upper case letter andmust be unique(%%)**(%style="color:rgb(0,0,0);text-decoration:none;"%) amongall MD scriptnames.Itsoshouldnotcontainspaces,so otherMDscripts canuseitasanidentifierto accessthisscriptΓÇÖs contentseasily.108 +The rules for naming cues is the same for MD script names: The name **starts with an upper case letter**, and has to be **unique within this file**. So it is actually possible to use the same cue name in different scripts, which is different from the MD in X3. 86 86 87 - (% style="color:rgb(0,0,0);text-decoration: none;" %)The only allowedsub-node of <mdscript>is <cues>, which canonly contain <cue>sub-nodes:110 +== Conditions == 88 88 89 - {{code}}<?xml┬áversion="1.0"┬áencoding="utf-8"?><mdscript┬áname="ScriptName"...>┬á<cues>┬á┬á┬á<cue┬áname="RootCue1">[...]┬á┬á┬á</cue>┬á┬á┬á <cue┬áname="RootCue2">[...]┬á┬á┬á</cue>┬á</cues></mdscript>{{/code}}112 +The <conditions> node can contain one or multiple conditions, all of which must be met to activate the cue. If the node is missing, the cue will become active unconditionally. The conditions are checked in sequence, and if a check fails, the following conditions are ignored. There are two types of conditions: Events and non-event conditions. 90 90 91 - (%style="color:rgb(0,0,0);text-decoration:none;"%)┬á114 +**Non-event conditions** are checked either once or repeatedly in a fixed interval. They may be based on simple values or ranges, such as a particular in-game time having been reached or the player having a certain amount of money. They may also be based on more complex player information, such as what ships they own, whether the player is in a particular area or near a particular object. 92 92 93 - (%id="categorybroken_macroanchorcues"%)116 +**Event conditions** are triggered when the corresponding event happens, such as the event that a particular object has been targeted, attacked or destroyed. All event nodes have the prefix "event_" so you can easily determine a condition type. After an event condition you can specify one or more non-event conditions, which will be checked additionally whenever the event happens. If a condition uses an event, it must be in the first sub-node of the <conditions> node. It is even possible to define multiple alternative events that should activate the cue. The first sub-node should be <check_any> in this case, so only one of its sub-conditions has to be met. 94 94 95 - == (% style="color:rgb(0,0,0);text-decoration:none;" %)Cues(%%) ==118 +Example for an event condition: 96 96 97 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Cues are the main ingredient of an MD script. A cue consists of a set of (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)conditions(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) and a set of (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)actions(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %). When the conditions are met, the cue is activated and the actions are performed. A cue can have child cues, or (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)sub-cues(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): A sub-cue exists only when its parent cue has become active, so the activation of the parent cue initiates the condition checks of its child cues. 120 +{{code language="xml"}} 121 +<conditions> 122 + <event_object_destroyed object="$target"/> 123 +</conditions> 124 +{{/code}} 98 98 99 - (% style="color:rgb(0,0,0);text-decoration:none;"%)A cue canhavethe following states:126 +Example for an event condition with an additional (non-event) check: 100 100 101 - * **(% style="color: rgb(0,0,0);text-decoration:none;" %)Disabled(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): The parent cue has not become active yet, so this cue is basically non-existing.102 - * **(% style="color: rgb(0,0,0);text-decoration: none;" %)Waiting(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): Either this is a root cue, or the parent hasbecome active. The cue is checking its conditions and will become active when they are met.103 - ***(%style="color: rgb(0,0,0);text-decoration: none;" %)Active(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): The cue is about to perform the actions. Child cues have entered the waiting state.104 - \\105 - * **(% style="color: rgb(0,0,0);text-decoration: none;" %)Complete(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): The cue has finished performing its actions.106 - * **(% style="color: rgb(0,0,0);text-decoration: none;" %)Cancelled(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): The cue has been cancelled. This state cannot normally be reached but only if a cue actively cancels itself or another cue. No condition checks or actions are performed in this cue or any sub-(sub-)cue.128 +{{code language="xml"}} 129 +<conditions> 130 + <event_player_killed_object/> 131 + <check_value value="event.param.isclass.turret"/> 132 +</conditions> 133 +{{/code}} 107 107 108 - (% style="color:rgb(0,0,0);text-decoration:none;" %)135 +Example for an event condition with two alternative events and a common additional check: 109 109 137 +{{code language="xml"}} 138 +<conditions> 139 + <check_any> 140 + <event_cue_completed cue="Cue1"/> 141 + <check_all> 142 + <event_player_killed_object/> 143 + <check_value value="event.param.isclass.turret"/> 144 + </check_all> 145 + </check_any> 146 + <check_age min="$starttime"/> 147 +</conditions> 148 +{{/code}} 110 110 111 -{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">There can be a delay between the activation and performing the actions if the <delay> tag is used. In this case, sub-cues will be enter the waiting state before the parent's actions are performed.<br /> 112 -</span>"/}} 150 +For more information about expressions and event parameters, see below. 113 113 152 +**<check_all>** and **<check_any>** can be used with non-event conditions as well, but if <check_any> is the first node of an event condition, all its sub-nodes have to define events. In case of <check_all>, only its first node must be an event (or yet another <check_any>), to make sure that exactly one event is required to activate the cue. 114 114 154 +If a cue has a <conditions> node without any event, it must have one of the attributes //**onfail**// or //**checkinterval**//. 115 115 116 - (%style="color:rgb(0,0,0);text-decoration:none;"%)156 +* Use //onfail// if the conditions should be checked only once. The possible attribute values are "//cancel//" and "//complete//". If the conditions are met, the cue will activate and perform the cue actions. Otherwise it's a failure and the cue will be cancelled or completed, based on the onfail attribute. Typically //onfail="cancel"// is used to prevent any further action. //onfail="complete"// can be used to continue with the sub-cues even in case of failure (but skipping the current cue actions). 117 117 158 +* With //checkinterval//, you can specify a constant time interval between condition checks. The conditions will be checked regularly forever until they are met, unless the cue's state is changed explicitly by an external event. 118 118 119 - (%style="color:rgb(0,0,0);text-decoration:none;" %)This ishowa cue nodelooks like:160 +Additionally, you can use the attribute **checktime** to set the time of the first condition check (also possible in combination with //onfail//). The //checktime// can be an expression with variables and is evaluated when the cue is enabled (when the condition checks would normally start - for root cues that happens at game start, otherwise after the parent cue becomes active). 120 120 121 - {{code}}<cue┬áname="CueName">┬á <conditions> [...]┬á </conditions>┬á <delay┬áexact="5s" />┬á <actions> [...]┬á </actions>┬á <cues> [...]┬á </cues></cue>{{/code}}162 +Examples: 122 122 123 - (% style="color:rgb(0,0,0);text-decoration: none;" %)The rules for naming cues isthe same for MD scriptnames:Thename**startswithan upper caseletter**, andhas tobe (%%)**(%style="color: rgb(0,0,0);text-decoration:none;" %)unique within this file(%%)**(% style="color: rgb(0,0,0);text-decoration:none;" %). So it is actuallypossibletosethesamecue name in differentscripts, which is differentfrom the MD in X3.164 +Check conditions every 5 seconds, but start checking only 1 hour after game start. 124 124 125 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 166 +{{code language="xml"}} 167 +<cue name="Foo" checktime="1h" checkinterval="5s"> 168 + <conditions> 169 + [...] 170 +</cue> 171 +{{/code}} 126 126 173 +Check conditions 3 seconds after the cue is enabled, and cancel the cue in case of failure. 127 127 128 -(% id="categorybroken_macroanchorconditions" %) 175 +{{code language="xml"}} 176 +<cue name="Foo" checktime="player.age + 3s" onfail="cancel"> 177 + <conditions> 178 + [...] 179 +</cue> 180 +{{/code}} 129 129 130 - ==(% style="color: rgb(0,0,0);text-decoration:none;"%)Conditions(%%) ==182 +The attributes //onfail//, //checkinterval//, //checktime// are not allowed for cues with event conditions. 131 131 132 -(% style="color: rgb(0,0,0);text-decoration: none;" %)The <conditions> node can contain one or multiple conditions, all of which must be met to activate the cue. If the node is missing, the cue will become active unconditionally. The conditions are checked in sequence, and if a check fails, the following conditions are ignored. There are two types of conditions: Events and non-event conditions. 184 +{{info}} 185 +**Reminder** 186 +When using an XSD-capable editor, it's a great help, but you cannot rely on that alone to verify correctness. Please also check the documentation and look for errors in the game debug output. Concretely, the schema cannot tell whether the above cue attributes are used correctly. 187 +{{/info}} 133 133 134 - **(% style="color: rgb(0,0,0);text-decoration: none;" %)Non-event conditions(%%)**(% style="color:rgb(0,0,0);text-decoration: none;" %) are checked either once or repeatedly in a fixed interval. They may be basedon simple values or ranges, such as a particular in-game time having been reached or the player having a certain amount of money. They may also be based on more complex player information, such as what ships they own, whether the player is in a particular area or near a particular object.189 +== Actions == 135 135 136 - **(% style="color:rgb(0,0,0);text-decoration:none;"%)Eventconditions(%%)**(%style="color:rgb(0,0,0);text-decoration:none;"%)aretriggered when the correspondingevent happens,suchastheevent that a particularobjectas been targeted,attackedor destroyed.All eventnodes havethe prefix ΓÇ£event_ΓÇ¥soyou can easily determine acondition type.After an eventconditionyou can specifyone or more non-eventconditions, which will be checkedadditionallywhenever the event happens. If aconditionusesanvent,it must beinthefirst sub-node of the<conditions> node.It is even possible to define multiple alternative events thatshould activatethe cue. Thefirst sub-nodeshould be <check_any> in thiscase, so only one of its sub-conditionshas to be met.191 +The <actions> node contains the actions that are performed one after another, without any delay inbetween. You can enforce a delay after activation of the cue and actual action performance, using a <delay> node right before the <actions>: 137 137 138 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Example for an event condition: 193 +{{code language="xml"}} 194 +<delay min="10s" max="30s"/> 195 +{{/code}} 139 139 140 - {{code}}<conditions>┬á<event_object_destroyed┬áobject="$target"/></conditions>{{/code}}197 +Note that during the delay the cue is already in the active state, and the sub-cues have been enabled! If you want to make sure that a sub-cue only becomes active after this cue is complete, there is a useful event condition for that: 141 141 142 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Example for an event condition with an additional (non-event) check: 199 +{{code language="xml"}} 200 +<event_cue_completed cue="parent"/> 201 +{{/code}} 143 143 144 - {{code}}<conditions>┬á <event_player_killed_object/>┬á<check_value┬ávalue="event.param.isclass.turret"/></conditions>{{/code}}203 +<actions> is optional. Leaving it out may be useful if you only want to enable sub-cues after the cue's condition check. The state transition from active to complete will still take the <delay> node into account. 145 145 146 - (%style="color:rgb(0,0,0);text-decoration:none;"%)Example foraneventconditionwithtwo alternative events and a commonitionalcheck:205 +Note that the MD script language is not designed as a programming language. The actions are performed in sequence, although they can be nested to form more complex structures. Loops and conditionals exist to some extent, but not necessarily in the sense that a programmer might expect. Analogously to <check_all> and <check_any>, you can use **<do_all>** to perform all the contained sub-node actions, and **<do_any>** to perform only one of them. <do_all> is particularly useful when nested in a <do_any>. 147 147 148 - {{code}}<conditions>┬á <check_any>┬á ┬á <event_cue_completed┬ácue="Cue1"/>┬á┬á <check_all>┬á┬á┬á┬á <event_player_killed_object/>┬á┬á┬á┬á <check_value┬ávalue="event.param.isclass.turret"/>┬á┬á </check_all>┬á</check_any>┬á<check_age┬ámin="$starttime"/></conditions>{{/code}}207 +Example, which selects one of the three texts randomly: 149 149 150 -(% style="color: rgb(0,0,0);text-decoration: none;" %)For more information about expressions and event parameters, see below. 209 +{{code language="xml"}} 210 +<actions> 211 + <do_any> 212 + <debug_text text="'Hello world'"/> 213 + <debug_text text="'Welcome to the MD'"/> 214 + <debug_text text="'And now for something completely different'"/> 215 + </do_any> 216 +<actions> 217 +{{/code}} 151 151 152 -**(% style="color: rgb(0,0,0);text-decoration: none;" %)<check_all>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) and (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)<check_any>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) can be used with non-event conditions as well, but if <check_any> is the first node of an event condition, all its sub-nodes have to define events. In case of <check_all>, only its first node must be an event (or yet another <check_any>), to make sure that exactly one event is required to activate the cue. 219 +{{info}} 220 +Messages printed with <debug_text> are usually only visible when the "scripts" debug filter is enabled, see [[Script debug output>>doc:||anchor="HScriptdebugoutput"]] 221 +{{/info}} 153 153 154 - (% style="color: rgb(0,0,0);text-decoration: none;" %)If a cue has a <conditions>nodewithout any event, it must have one of the attributes (%%)//**(% style="color: rgb(0,0,0);text-decoration:none;" %)onfail(%%)**//(% style="color: rgb(0,0,0);text-decoration: none;" %) or (%%)//**(% style="color: rgb(0,0,0);text-decoration: none;" %)checkinterval(%%)**//(% style="color: rgb(0,0,0);text-decoration: none;" %).223 +Script debug output 155 155 156 -* Use //onfail// if the conditions should be checked only once. The possible attribute values are (% style="color: rgb(0,0,0);text-decoration: none;" %)ΓÇ£(%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)cancel//ΓÇ¥ and ΓÇ£(%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)complete//ΓÇ¥. If the conditions are met, the cue will activate and perform the cue actions. Otherwise it's a failure and the cue will be cancelled or completed, based on the onfail attribute. Typically //onfail="cancel"// is used to prevent any further action. //onfail="complete"// can be used to continue with the sub-cues even in case of failure (but skipping the current cue actions). 157 -\\ 158 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)With (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)checkinterval//, you can specify a constant time interval between condition checks. The conditions will be checked regularly forever until they are met, unless the cueΓÇÖs state is changed explicitly by an external event. 225 +Each child action in a <do_any> node can have a //**weight**// attribute, which can be used to control the random selection of an action node. The default weight of a child node is 1. 159 159 160 - (%style="color: rgb(0,0,0);text-decoration:none;"%)Additionally,youcan usethe attribute(%%)**(% style="color:rgb(0,0,0);text-decoration:none;"%)checktime(%%)**(% style="color:rgb(0,0,0);text-decoration:none;"%)to setthe timeoftheirstcondition check(alsopossiblein combinationwith(%%)//(% style="color:rgb(0,0,0);text-decoration:none;"%)onfail//). The(%%)//(% style="color: rgb(0,0,0);text-decoration:none;" %)checktime//can bean expression with variables and isevaluatedwhenthecueisenabled(whentheconditionchecks wouldnormallystart ΓÇôforroot cuesthat happensat game start,otherwiseaftertheparent cue becomes active).227 +Also available is **<do_if>**, which completes the enclosed action(s) only if one provided value is non-null or matches another. Directly after a <do_if> node, you can add one or more **<do_elseif>** nodes to perform additional checks only in case the previous conditions were not met. The node **<do_else>** can be used directly after a <do_if> or a <do_elseif>. It is executed only if none of the conditions are met. 161 161 162 - (% style="color:rgb(0,0,0);text-decoration:none;"%)Examples:229 +**<do_while>** also exists, but should be used carefully, since it is the only action that could cause an infinite loop, which freezes the game without any chance of recovery. 163 163 164 - (% style="color:rgb(0,0,0);text-decoration:none;"%)Checkconditionsevery5seconds,butstart checkingonly1 houraftergame start.231 +Every action can have a //**chance**// attribute, if you only want it to be performed with that chance, given as percentage. Otherwise it will simply be skipped. If chance is used on a conditional action such as <do_if>, the script will behave as if the condition check failed. 165 165 166 - {{code}}<cue┬áname="Foo"┬áchecktime="1h"┬ácheckinterval="5s">┬á <conditions>┬á[...]</cue>{{/code}}233 += Libraries = 167 167 168 - (%style="color:rgb(0,0,0);text-decoration: none;"%)Checkconditions3seconds after the cue isenabled,andcancelthe cue incaseofailure.235 +Libraries are cues which are not created directly but only serve as templates for other cues. This allows for modularisation, so you can re-use library cues in many different missions. 169 169 170 -{{code}}<cue┬áname="Foo"┬áchecktime="player.age + 3s"┬áonfail="cancel">┬á <conditions>┬á [...]</cue>{{/code}} 237 +{{info}} 238 +The syntax of libraries is considerably different from the syntax in the MD of X3TC. 239 +{{/info}} 171 171 172 -(% style="color: rgb(0,0,0);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %)The attributes //onfail//, //checkinterval//, //checktime// are not allowed for cues with event conditions. 173 173 174 - \\242 +Library cues are written like normal cues, they are also defined in a <cues> node, just with the difference that the XML tag is called library instead of cue: 175 175 244 +{{code language="xml"}} 245 +<library name="LibFoo" checktime="1h" checkinterval="5s"> 246 + <conditions> 247 + [...] 248 +</library> 249 +{{/code}} 176 176 251 +Although it is called library, it's basically just a cue that doesn't do anything. You can mix cues and libraries as you want, as root cues or sub-cues - the location within the file is unimportant. All that counts is the library name, which has to be unique within the MD script, like all other cue names. 177 177 178 - {{notebody="Reminder: Whenusing an XSD-capableeditor, it'sagreat help,but you cannotrely on that alone to verifycorrectness. Please also check the documentation and look for errorsin thegame debug output. Concretely, theschemacannotell whetherthe above cue attributesareused correctly."/}}253 +To use a library, use the attribute ref: 179 179 255 +{{code language="xml"}} 256 +<cue name="Foo" ref="LibFoo"/> 257 +{{/code}} 180 180 259 +This will create a cue with the name Foo that behaves just like the library cue LibFoo. In this example, LibFoo has to be a library in the same MD script file. To use a library LibFoo from another script, you have to qualify it with the script name, using the **md** prefix: 181 181 182 -\\ 261 +{{code language="xml"}} 262 +<cue name="Foo" ref="md.ScriptName.LibFoo"/> 263 +{{/code}} 183 183 184 -( %id="actions"%)265 +When the ref attribute is provided, all other attributes (except for name) will be ignored and taken from the library cue instead. (By default a library creates its own namespace, as if namespace="static" were specified. See the section about namespaces.) 185 185 186 - ==(%style="color:rgb(0,0,0);text-decoration:none;"%)Actions(%%)==267 +Also all sub-cues of the library will be created as sub-cues of the cue that uses it. They are defined in the library as <cue>, not as <library>. (Although you can define a library as a sub-cue of another library, the location in the file does not matter, as already stated above.) It is even possible to reference other libraries in sub-cues of a library! 187 187 188 - (%style="color:rgb(0,0,0);text-decoration:none;"%)The <actions>nodecontains the actions that areperformedoneafteranother,withoutanydelay inbetween.Youcan enforceadelayafteractivation ofthecue and actualactionperformance, usinga<delay>node rightbeforethe<actions>:269 +In contrast to X3TC, a cue that references a library also has its own name (Foo in the example above), so other cues can access it in expressions by that name. Sub-cues of Foo cannot be accessed by their name though. Within the library itself, expressions can use all names of cues that belong to the library (the <library> and all sub-cues). They will be translated properly when the library is referenced. Examples: 189 189 190 -{{code}}<delay┬ámin="10s"┬ámax="30s"/>{{/code}} 271 +{{code language="xml"}} 272 +<cue name="Foo" ref="LibFoo"/> 273 +<cue name="Bar" ref="LibFoo"/> 191 191 192 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Note that during the delay the cue is already in the active state, and the sub-cues have been enabled! If you want to make sure that a sub-cue only becomes active after this cue is complete, there is a useful event condition for that: 275 +<library name="LibFoo"> 276 + <actions> 277 + <cancel_cue cue="this"/> 278 + <cancel_cue cue="LibFoo"/> 279 + <cancel_cue cue="Foo"/> 280 + <cancel_cue cue="Baz"/> 281 + <cancel_cue cue="md.Script.Foo"/> 282 + <cancel_cue cue="md.Script.LibFoo"/> 283 + <cancel_cue cue="md.Script.Baz"/> 284 + </actions> 285 + <cues> 286 + <cue name="Baz"> [...] 287 + </cues> 288 +</library> 289 +{{/code}} 193 193 194 -{{code}}<event_cue_completed┬ácue="parent"/>{{/code}} 291 +{{warning}} 292 +These examples are definitely **__not__ **examples of good scripting style. 293 +{{/warning}} 195 195 196 - (%style="color:rgb(0,0,0);text-decoration:none;"%)<actions>isoptional. Leavingitoutmay beusefulifyouonlywantto enable sub-cues afterthecueΓÇÖsconditioncheck.Thestatetransitionfromactivetocomplete willstilltake the<delay>node intoaccount.295 +So when writing the library, you don't have to worry about name confusion, just use the names of cues in your library and it will work as expected when the library is used. Names of cues that do not belong to the library will not be available in expressions (see Foo in the example above), however, names of other libraries in the file are available when referencing them in the ref attribute. 197 197 198 - (% style="color: rgb(0,0,0);text-decoration: none;" %)Notethat the MDscript language is not designed as a programming language. The actions are performed in sequence, although they can be nested to form more complex structures. Loops and conditionals exist to some extent, but not necessarily in the sense that a programmer might expect. Analogously to <check_all> and <check_any>, you can use (%%)**(% style="color:rgb(0,0,0);text-decoration: none;" %)<do_all>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) to perform all the contained sub-node actions, and (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)<do_any>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) to perform only one of them. <do_all> is particularly useful when nested in a <do_any>.297 +Notes: 199 199 200 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Example, which selects one of the three texts randomly: 299 +* It is //not// possible to directly call a cue which is 'inside' the library from 'outside' of the library, but it is possible to signal the library ref itself (possibly with parameters) and have a sub-cue inside the library listen to the signal on the library ref (possibly checking the parameters). 300 +* You //can// access variables in the library root but generally this should be avoided in favor of parameterizing the library! 301 +** there are some cases where you do want to access these variables directly, for example for maintaining savegame compatibility when patching. 201 201 202 - {{code}}<actions>┬á<do_any>┬á┬á <debug_text┬átext="'Hello world'"/>┬á┬á <debug_text┬átext="'Welcometo the MD'"/>┬á┬á <debug_text┬átext="'And now forsomething completely different'"/>┬á</do_any><actions>{{/code}}303 +== Library Parameters == 203 203 204 - {{notebody="<spanstyle=~"color:rgb(0,0,0);text-decoration:none;~">Messagesprintedwith<debug_text>areusuallyonlyvisiblewhentheΓÇ£scriptsΓÇ¥debugfilteris enabled,see[[NULL|Script debug output]].</span>"/}}305 +A library can be parametrised, so that it can be adapted to the needs of a missions that uses it. You can define required and/or optional parameters for a library, and it will be validated at load time that the user of the library has provided all required parameters. 205 205 307 +Parameters are defined like this: 206 206 309 +{{code language="xml"}} 310 +<library name="Lib" onfail="cancel"> 311 + <params> 312 + <param name="foo"/> 313 + <param name="bar" default="42"/> 314 + <param name="baz" default="player.age"/> 315 + </params> 316 + [...] 317 +</library> 318 +{{/code}} 207 207 208 - (%style="color:rgb(0,0,0);text-decoration:none;" %)Each childactionin a <do_any>node canhave a(%%)//**(% style="color: rgb(0,0,0);text-decoration:none;" %)weight(%%)**//(%style="color:rgb(0,0,0);text-decoration:none;" %) attribute,whichcan besedto controlthe randomselectionofanaction node.The defaultweightofachildnodeis 1.320 +If a default value is supplied, the parameter is regarded as optional, otherwise it's required. When providing the actual parameters in a referencing cue, note that there is no <params> node: 209 209 210 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Also available is (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)<do_if>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %), which completes the enclosed action(s) only if one provided value is non-null or matches another. Directly after a <do_if> node, you can add one or more (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)<do_elseif>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) nodes to perform additional checks only in case the previous conditions were not met. The node (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)<do_else>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) can be used directly after a <do_if> or a <do_elseif>. It is executed only if none of the conditions are met. 322 +{{code language="xml"}} 323 +<cue name="Foo" ref="Lib"> 324 + <param name="foo" value="race.argon"/> 325 + <param name="bar" value="0"/> 326 +</cue> 327 +{{/code}} 211 211 212 - **(%style="color: rgb(0,0,0);text-decoration:none;" %)<do_while>(%%)**(%style="color:rgb(0,0,0);text-decoration:none;"%) alsoexists,butshouldbe usedcarefully,since itis the only actionthat couldcauseaninfiniteloop,whichfreezesthegamewithoutanychanceofrecovery.329 +The values (including default values) can be variable expressions and will be evaluated when the cue is enabled, i.e. when it starts checking the conditions. They will be available to the cue as variables, using the parameter name with a '$' prefix. In the example above, the variables $foo, $bar, and $baz would be created. 213 213 214 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Every action can have a (%%)//**(% style="color: rgb(0,0,0);text-decoration: none;" %)chance(%%)**//(% style="color: rgb(0,0,0);text-decoration: none;" %) attribute, if you only want it to be performed with that chance, given as percentage. Otherwise it will simply be skipped. If chance is used on a conditional action such as <do_if>, the script will behave as if the condition check failed. 331 +{{code language="xml"}} 332 +<library name="Lib"> 333 + <params> 334 + <param name="foo"/> 335 + </params> 336 + <actions> 337 + <debug_text text="$foo"/> 338 + </actions> 339 +</library> 340 +{{/code}} 215 215 216 - (%style="color:rgb(0,0,0);text-decoration:none;"%)342 +If your library is supposed to provide a result to the library user, it is recommended to store a predefined variable in the library cue with a standardised name, e.g. $result. The user will be able to read it via CueName.$result. This variable does not have to be defined as a parameter but should be documented in the library. 217 217 344 += Instantiation = 218 218 219 -(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á 346 +One of the possible cue attributes is //**instantiate**//. If you set it to true, this changes what happens when a cue's conditions are met. Normally, if a cue is not instantiated, the cue's actions are run (taking a delay node into account) and the cue is marked as completed. But with **instantiate'//, a// **copy of the cue** (and all its sub-cues) is made when the conditions are met, and it is this copy in which the actions are performed and it is the copy whose status is set to complete when they are finished - this means that the original cue (the so-called **static cue**) remains in the //waiting// state, and if the conditions are met again then the whole thing happens all over again.** 347 +\\An instantiating cue should only be used with conditions that are only going to be met once (or a fairly limited number of times), or with conditions that include an event condition. Instantiation should not be used in a cue which, say, just depends on the game time being greater than a specific value as this will result in a copy of the cue being made after each check interval, which could increase memory usage a lot. The most common use of an instantiated cue is in responding to events such as the player ship changing sector, to react every time that event happens. 348 +\\Instances that are created via //instantiate// are called **instantiated cues**. But sub-cues of instances are also instances (**sub-instances**) - they are created when they enter the waiting state. An instance is removed again (thereby freeing its memory) when it is complete or cancelled, and when all its instance sub-cues have been removed before. The simplest case is an instantiating cue with no sub-cues: The instance is created, the actions are performed, and the instance is removed immediately on completion. A pitfall could be an instance with a sub-cue that is forever in the waiting state (e.g. waiting for an event from an already destroyed object). It can never be removed, so you should clean up such a cue yourself, e.g. by cancelling it explicitly. 220 220 221 - (% id="libraries"%)350 +== Cleaning up instances explicitly == 222 222 223 - =(%style="color:rgb(0,0,0);text-decoration:none;"%)Libraries(%%)=352 +Cancelling a cue with **<cancel_cue>** also cancels all its sub-cues, and cancelling a static cue stops it from instantiating more cues - but it does not cancel its instances. Resetting a cue with **<reset_cue>** resets both sub-cues and instantiated cues, but has the (desired) side effect that condition checks will start again if the parent cue's state allows it. Even a sub-instance that has been reset can return to the //waiting// state. Resetting an instantiated cue will stop it forever, because it is not supposed to be in the //waiting// state (only its static cue is). Resetting will also induce the clean-up reliably, but keep in mind that this is not the case for instance sub-cues. 224 224 225 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Libraries are cues which are not created directly but only serve as templates for other cues. This allows for modularisation, so you can re-use library cues in many different missions. 354 +{{info}} 355 +<cancel_cue> and <reset_cue> only take effect after all remaining actions of the current cue are performed. So you can even safely cancel the cue that you are currently in (keyword "'''this'''") or any ancestor cue, and still perform more actions afterwards. 356 +{{/info}} 226 226 227 - {{note body="<span style=~"color:rgb(0,0,0);~">Theyntax of librariesis considerablydifferent from thesyntax intheMD of X3TC.</span>"/}}358 +== Access to instances == 228 228 360 +{{info}} 361 +This sub-section requires basic knowledge of script expressions. 362 +{{/info}} 229 229 364 +In case of instances with sub-instances, you will often want to access a related instance from the current one. Like in the non-instance case, you can simply write the cue name in an expression to reference that cue. However, you should be aware of the pitfalls that are accompanied by this. 230 230 231 - (%style="color:rgb(0,0,0);text-decoration:none;"%)Librarycuesarewrittenlikenormalcues,theyarealsodefinedina<cues>node, justwiththe differencethattheXMLtagiscalledlibraryinstead ofcue:366 +When you use a cue name from the same script in an expression, it will always be resolved to some cue - usually a static cue, even if it is still in the disabled state, but it can also be an instance, if it is "related" to the current one. 232 232 233 - {{code}}<library┬áname="LibFoo"┬áchecktime="1h"┬ácheckinterval="5s">┬á<conditions>┬á[...]</library>{{/code}}368 +Related means that this cue and the referenced cue have a common ancestor instance, and the referenced cue is a direct (non-instantiated) descendant of that common ancestor. 234 234 235 - (% style="color: rgb(0,0,0);text-decoration: none;" %)Although it is called library, itΓÇÖs basically just a cue that doesnΓÇÖt do anything. You canmix cues and libraries as you want, as root cues or sub-cues - the location within the file is unimportant. All that counts is thelibrary name, whichhas to be unique within the MD script, like all other cue names.370 +Example chart: 236 236 237 - (%style="color:rgb(0,0,0);text-decoration: none;" %)Tosea library,useheattribute ref:372 +[[~[~[image:Mission Director Guide - Instantiation.png~|~|width="800px"~]~]>>attach:ARCHIVE_XRWIKI_Modding_support_Mission_Director_GuideMission_Director_Guide_-_Instantiation.png]] 238 238 239 - {{code}}<cue┬áname="Foo"┬áref="LibFoo"/>{{/code}}374 +This chart represents a script of 5 cues: Foo, Bar, SubBar, Baz and SubBaz. Continuous arrows denote parent-child relationship. Foo and Baz are instantiating cues (highlighted with red border). The static cues always exist, although static children of instantiating cues can never become active. Instances only exist as long as they are needed. 240 240 241 - (% style="color: rgb(0,0,0);text-decoration: none;" %)This will create a cue with the name Foo that behaves just like the library cue LibFoo. In this example,LibFoo hasto be a library inthe same MD script file. Tousealibrary LibFoo from another script, you have to qualify it with the scriptname, using the (%%)**(% style="color:rgb(0,0,0);text-decoration: none;" %)md(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) prefix:376 +Example situations: 242 242 243 -{{code}}<cue┬áname="Foo"┬áref="md.ScriptName.LibFoo"/>{{/code}} 378 +* In the static tree: Cue names in expressions are always resolved to the static cues. 379 +* In the inst-2 tree: "SubBar" in an expression will be resolved to SubBar (inst 2). 380 +* In the inst-1 tree: "SubBar" in an expression will be resolved to SubBar (static) (!) because the SubBar child of Bar (inst 1) does not exist yet, or not any more. 381 +* In the inst-2a tree: "SubBaz" in an expression will be resolved to SubBaz (inst 2a) 382 +* In the inst-2a tree: "Bar" in an expression will be resolved to Bar (inst 2) because Foo (inst 2) is a common ancestor. 383 +* In the inst-2 tree: "SubBaz" in an expression will be resolved to SubBaz (static) (!) because SubBaz (inst 2a) is **not** a direct descendant of the common ancestor Foo (inst 2), instead Baz (inst 2a) has been instantiated. 244 244 245 - (%style="color: rgb(0,0,0);text-decoration:none;"%)Whentheref attributeisprovided,allotherattributes(exceptforname)willbe ignoredandtakenfromthelibrarycueinstead.((%style="color:rgb(0,0,0);text-decoration:none;"%)Bydefaultalibrarycreates itsownnamespace, asifnamespace="static"werespecified.Seethesectionaboutnamespaces.(%%))385 +In expressions, you can use the cue property **static** to access the static cue that instantiated a cue. This does not work for sub-cues of other cues, and the result is not necessarily a real static cue! In the example above, it would only work for cues with a dotted arrow pointing at them, and is resolved to the source of the arrow. In other cases the result is null. 246 246 247 - (% style="color:rgb(0,0,0);text-decoration:none;" %)Also all sub-cues ofthelibrary willbe createdas sub-cuesof thecue thatusesit.Theyare definedin thelibrary as<cue>, notas<library>. (Althoughyoucan define a library asb-cueof anotherlibrary,the location in thefiledoesnot matter,as alreadystated above.) It is evenpossible toreferenceotherlibrariesin sub-cuesof alibrary!387 +To get the real static cue that always exists and serves as template for instances, use the property **staticbase**. This works for all cues, even for the static cues themselves. 248 248 249 - (%style="color: rgb(0,0,0);text-decoration: none;" %)In contrasttoX3TC,aue that referencesa library alsohas its ownname(Foo inthe example above),soothercues can access it in expressions bythatname. Sub-cuesofFoocannotbeaccessedbytheirnamethough. Within the library itself,expressionscanuseallnames of cuesthat belongto thelibrary(the <library> and all sub-cues).Theywill be translatedproperly whenhe library is referenced.Examples:389 +In general, to access ancestors of the current cue, you can also use the keyword **parent**, also recursively as properties of other cues (such as **parent.parent.parent).** 250 250 251 - {{code}}<cue┬áname="Foo"┬áref="LibFoo"/><cue┬áname="Bar"┬áref="LibFoo"/><library┬áname="LibFoo">┬á<actions>┬á┬á <cancel_cue┬ácue="this"/>┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á<!-- CancelsthecuereferencingLibFoo-->┬á┬á <cancel_cue┬ácue="LibFoo"/>┬á┬á┬á┬á┬á ┬á ┬á <!--Cancels thecue referencingLibFoo -->┬á ┬á <cancel_cue┬ácue="Foo"/>┬á┬á┬á┬á┬á┬á ┬á┬á ┬á┬á <!--Error, Foonotfoundin library-->┬á ┬á <cancel_cue┬ácue="Baz"/>┬á┬á┬á┬á┬á┬á ┬á┬á ┬á┬á <!--CancelsBaz inthe referencing cue -->┬á┬á <cancel_cue┬ácue="md.Script.Foo"/>┬á┬á┬á<!--CancelsFoo-->┬á ┬á <cancel_cue┬ácue="md.Script.LibFoo"/>┬á<!--Error, tryingto cancellibrary-->┬á ┬á <cancel_cue┬ácue="md.Script.Baz"/>┬á┬á┬á <!-- Error,tryingto cancellibrary sub-cue-->┬á </actions>┬á<cues>┬á┬á <cue┬áname="Baz">[...]┬á<!-- Sub-cue iscreatedinall cuesreferencingLibFoo -->┬á </cues></library>{{/code}}391 +You can store cue references in variables. But when storing an instance cue in a variable, and later accessing that variable, be aware that the instance may not exist any more. Use the property **exists** to check if an instance is still alive. (In contrast, non-instance cues always exist, but may be in the //disabled// or //cancelled// state.) 252 252 253 - {{warning body="Theseexamples are definitely <u>not</u> examplesof good scripting style."/}}393 +== Pitfalls == 254 254 395 +Some additional common pitfalls with respect to instantiation are listed here. There may be more. 255 255 397 +* **Conditions with results:** If the instantiating cue has conditions with results, those results are stored in variables - but in the variables of the static cue, not of the instance! So in the <actions> you have to access the variables via the **static **keyword: 256 256 257 -(% style="color: rgb(0,0,0);text-decoration: none;" %)So when writing the library, you donΓÇÖt have to worry about name confusion, just use the names of cues in your library and it will work as expected when the library is used. Names of cues that do not belong to the library will not be available in expressions (see Foo in the example above), however, names of other libraries in the file are available when referencing them in the ref attribute. 399 +{{code language="xml"}}<debug_text text="static.$foo"/>{{/code}} 400 +It may even be necessary to copy the variables over to the instance because the static variables can be overwritten by the next condition check: 401 +{{code language="xml"}}<set_value name="$foo" exact="static.$foo"/>{{/code}} 258 258 259 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Notes: 403 +* **Resetting completed/cancelled instances:** As explained above, sub-instances are only created when needed (when going to the //waiting// state) and are destroyed when they are not needed any more (when they are completed or cancelled, including all sub-cues). There are cases in which you want to access cues that don't exist any more - it simply doesn't work. In some cases you are safe: You can be sure that all your ancestors exist, and instantiating cues won't be removed until they are cancelled. In some other cases you simply don't know and have to check if the instance is already (or still) there. 404 +* **Lifetime of instances:** Do not make assumptions about when an instance is removed! Just looking at it in the Debug Manager keeps it alive for the time being. So, sometimes you could still have a completed instance that wouldn't exist under other circumstances. 260 260 261 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)It is //not// possible to directly call a cue which is 'inside' the library from 'outside' of the library, but it is possible to signal the library ref itself (possibly with parameters) and have a sub-cue inside the library listen to the signal on the library ref (possibly checking the parameters). 262 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)You //can// access variables in the library root but generally this should be avoided in favor of parameterizing the library! 263 -** (% style="color: rgb(0,0,0);text-decoration: none;" %)there are some cases where you do want to access these variables directly, for example for maintaining savegame compatibility when patching. 406 += Expressions = 264 264 265 - (%id="library-parameters"%)408 +Most of the attribute values in actions and conditions are interpreted as script expressions and parsed accordingly. An expression is a phrase that can be evaluated to a single value. The simplest expressions are actual numeric values and strings, so called **literals:** 266 266 267 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Library Parameters(%%) == 410 +* {{code language="xml"}}0{{/code}}(integer number) 411 +* {{code language="xml"}}0772{{/code}}(leading 0 means octal integer number) 412 +* {{code language="xml"}}3.14159{{/code}}(floating point number) 413 +* {{code language="xml"}}5e12{{/code}}(float in exponent notation, "times ten to the power of") 414 +* {{code language="xml"}}0xCAFE{{/code}}(hexadecimal integer number) 268 268 269 -(% style="color: rgb(0,0,0);text-decoration: none;" %)A library can be parametrised, so that it can be adapted to the needs of a missions that uses it. You can define required and/or optional parameters for a library, and it will be validated at load time that the user of the library has provided all required parameters. 416 +{{info}} 417 +Since octal numbers are hardly ever used (usually unknowingly), the parser is will produce a warning if an octal number is encountered." 418 +{{/info}} 270 270 271 - (%style="color:rgb(0,0,0);text-decoration:none;"%)Parametersare definedlike this:420 +You can write string literals by putting the string in single quotes: 272 272 273 -{{code}}<library┬áname="Lib" onfail="cancel">┬á <params>┬á┬á┬á <param┬áname="foo"/>┬á┬á┬á <param┬áname="bar"┬ádefault="42"/>┬á┬á┬á <param┬áname="baz"┬ádefault="player.age"/>┬á </params>┬á [...]</library>{{/code}} 422 +* {{code language="xml"}}'Hello world'{{/code}} 423 +* {{code language="xml"}}''{{/code}}(empty string) 424 +* {{code language="xml"}}'String with a line break\n'{{/code}} 274 274 275 -(% style="color: rgb(0,0,0);text-decoration: none;" %)If a default value is supplied, the parameter is regarded as optional, otherwise itΓÇÖs required. When providing the actual parameters in a referencing cue, note that there is no <params> node: 426 +{{info}} 427 +Since expressions are written in XML attribute values, you have to use the single quotes inside the double quotes for the actual attribute value. To write characters like '''< > " &''' in an expression string (or anywhere else in an XML attribute value), you'll have to escape them as '''< > " &''' respectively. The backslash '''\''' can be used in strings for escape characters like in C/C++. Most important are '''\'''' for a single quote as part of the string, and ''' 428 +''' for the backslash itself. 429 +{{/info}} 276 276 277 - {{code}}<cue┬áname="Foo"┬áref="Lib">┬á<param┬áname="foo"┬ávalue="race.argon"/>┬á<param┬áname="bar"┬ávalue="0"/></cue>{{/code}}431 +== Numeric data types and suffixes == 278 278 279 - (% style="color:rgb(0,0,0);text-decoration:none;" %)The values (including defaultvalues)canbe variable expressionsand will be evaluatedwhenthecueis enabled,i.e. whenit startscheckingtheconditions. They will be availabletothe cueas variables,using theparametername with aΓÇÿ$ΓÇÖ prefix. Inthe exampleabove,thevariables$foo, $bar,and$bazwould be created.433 +Numbers can have a suffix that determines their numeric type. There are also numerical data types like "money" or "time" which can only be expressed by using an appropriate unit suffix: 280 280 281 -{{code}}<library┬áname="Lib">┬á <params>┬á ┬á <param┬áname="foo"/>┬á </params>┬á <actions>┬á ┬á <debug_text┬átext="$foo"/>┬á </actions></library>{{/code}} 435 +* {{code language="xml"}}5000000000L{{/code}}(large integer) 436 +* {{code language="xml"}}1f{{/code}}(floating point number, same as 1.0, just 1 would be an integer) 437 +* {{code language="xml"}}1000Cr{{/code}}(Money in Credits, converted to 100000 cents automatically) 438 +* {{code language="xml"}}500m{{/code}}(Length in metres) 439 +* {{code language="xml"}}10s{{/code}}(Time in seconds) 440 +* {{code language="xml"}}1h{{/code}}(Time in hours, which is converted to 3600s automatically) 282 282 283 - (%style="color: rgb(0,0,0);text-decoration: none;" %)If your library is supposed to providearesultto the library user, itis recommendedto store a predefined variablein the librarycue withastandardisedname, e.g. $result. The user willbe able to readit via CueName.$result.This variable does not have to be defined as a parameter but should be documentedin the library.442 +A space between number and suffix is allowed. 284 284 285 - (%style="color:rgb(0,0,0);text-decoration:none;"%)444 +Here is the complete list of numeric data types and corresponding unit suffixes: 286 286 287 - 288 -(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á 289 - 290 -(% id="instantiation" %) 291 - 292 -= (% style="color: rgb(0,0,0);text-decoration: none;" %)Instantiation(%%) = 293 - 294 -(% style="color: rgb(0,0,0);text-decoration: none;" %)One of the possible cue attributes is (%%)//**(% style="color: rgb(0,0,0);text-decoration: none;" %)instantiate(%%)**//(% style="color: rgb(0,0,0);text-decoration: none;" %). If you set it to true, this changes what happens when a cue's conditions are met. Normally, if a cue is (% style="color: rgb(0,0,0);text-decoration: underline;" %)not(% style="color: rgb(0,0,0);text-decoration: none;" %) instantiated, the cue's actions are run (taking a delay node into account) and the cue is marked as completed. But with (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)instantiate////, a// (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)copy of the cue(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) (and all its sub-cues) is made when the conditions are met, and it is this copy in which the actions are performed and it is the copy whose status is set to complete when they are finished - this means that the original cue (the so-called (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)static cue(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)) remains in the (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)waiting// state, and if the conditions are met again then the whole thing happens all over again. 295 - 296 -(% style="color: rgb(0,0,0);text-decoration: none;" %)An instantiating cue should only be used with conditions that are only going to be met once (or a fairly limited number of times), or with conditions that include an event condition. Instantiation should (% style="color: rgb(0,0,0);text-decoration: underline;" %)not(% style="color: rgb(0,0,0);text-decoration: none;" %) be used in a cue which, say, just depends on the game time being greater than a specific value as this will result in a copy of the cue being made after each check interval, which could increase memory usage a lot. The most common use of an instantiated cue is in responding to events such as the player ship changing sector, to react every time that event happens. 297 - 298 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Instances that are created via (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)instantiate// are called **instantiated cues**. But sub-cues of instances are also instances ((%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)sub-instances(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)) - they are created when they enter the waiting state. An instance is removed again (thereby freeing its memory) when it is complete or cancelled, and when all its instance sub-cues have been removed before. The simplest case is an instantiating cue with no sub-cues: The instance is created, the actions are performed, and the instance is removed immediately on completion. A pitfall could be an instance with a sub-cue that is forever in the waiting state (e.g. waiting for an event from an already destroyed object). It can never be removed, so you should clean up such a cue yourself, e.g. by cancelling it explicitly. 299 - 300 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 301 - 302 - 303 -(% id="cleaning-up-instances-explicitly" %) 304 - 305 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Cleaning up instances explicitly(%%) == 306 - 307 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Cancelling a cue with (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)<cancel_cue>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) also cancels all its sub-cues, and cancelling a static cue stops it from instantiating more cues - but it does not cancel its instances. Resetting a cue with (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)<reset_cue>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) resets both sub-cues and instantiated cues, but has the (desired) side effect that condition checks will start again if the parent cueΓÇÖs state allows it. Even a sub-instance that has been reset can return to the (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)waiting// state. Resetting an instantiated cue will stop it forever, because it is not supposed to be in the (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)waiting// state (only its static cue is). Resetting will also induce the clean-up reliably, but keep in mind that this is not the case for instance sub-cues. 308 - 309 -{{info body="<span style=~"color: rgb(0,0,0);text-decoration: none;~"><cancel_cue> and <reset_cue> only take effect after all remaining actions of the current cue are performed. So you can even safely cancel the cue that you are currently in (keyword ΓÇ£</span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~">this</span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~">ΓÇ¥) or any ancestor cue, and still perform more actions afterwards.</span>"/}} 310 - 311 - 312 - 313 -(% id="access-to-instances" %) 314 - 315 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Access to instances(%%) == 316 - 317 - 318 - 319 -{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">This sub-section requires basic knowledge of [[NULL|script expressions]].</span>"/}} 320 - 321 - 322 - 323 -(% style="color: rgb(0,0,0);text-decoration: none;" %)In case of instances with sub-instances, you will often want to access a related instance from the current one. Like in the non-instance case, you can simply write the cue name in an expression to reference that cue. However, you should be aware of the pitfalls that are accompanied by this. 324 - 325 -(% style="color: rgb(0,0,0);text-decoration: none;" %)When you use a cue name from the same script in an expression, it will always be resolved to some cue - usually a static cue, even if it is still in the disabled state, but it can also be an instance, if it is ΓÇ£relatedΓÇ¥ to the current one. 326 - 327 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Related means that this cue and the referenced cue have a common ancestor instance, and the referenced cue is a direct (non-instantiated) descendant of that common ancestor. 328 - 329 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Example chart: 330 - 331 -(% style="color: rgb(0,0,0);text-decoration: none;" %)[[~[~[image:ARCHIVE_XRWIKI_Modding_support_Mission_Director_GuideMission_Director_Guide_-_Instantiation.png~|~|width="800px"~]~]>>attach:ARCHIVE_XRWIKI_Modding_support_Mission_Director_GuideMission_Director_Guide_-_Instantiation.png]] 332 - 333 - 334 -(% style="color: rgb(0,0,0);text-decoration: none;" %)This chart represents a script of 5 cues: Foo, Bar, SubBar, Baz and SubBaz. Continuous arrows denote parent-child relationship. Foo and Baz are instantiating cues (highlighted with red border). The static cues always exist, although static children of instantiating cues can never become active. Instances only exist as long as they are needed. 335 - 336 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Example situations: 337 - 338 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)In the static tree: Cue names in expressions are always resolved to the static cues. 339 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)In the inst-2 tree: ΓÇ£SubBarΓÇ¥ in an expression will be resolved to SubBar (inst 2). 340 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)In the inst-1 tree: ΓÇ£SubBarΓÇ¥ in an expression will be resolved to SubBar (static) (!) because the SubBar child of Bar (inst 1) does not exist yet, or not any more. 341 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)In the inst-2a tree: ΓÇ£SubBazΓÇ¥ in an expression will be resolved to SubBaz (inst 2a) 342 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)In the inst-2a tree: ΓÇ£BarΓÇ¥ in an expression will be resolved to Bar (inst 2) because Foo (inst 2) is a common ancestor. 343 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)In the inst-2 tree: ΓÇ£SubBazΓÇ¥ in an expression will be resolved to SubBaz (static) (!) because SubBaz (inst 2a) is (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)not(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) a direct descendant of the common ancestor Foo (inst 2), instead Baz (inst 2a) has been instantiated. 344 - 345 -(% style="color: rgb(0,0,0);text-decoration: none;" %)In expressions, you can use the cue property (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)static(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) to access the static cue that instantiated a cue. This does not work for sub-cues of other cues, and the result is not necessarily a real static cue! In the example above, it would only work for cues with a dotted arrow pointing at them, and is resolved to the source of the arrow. In other cases the result is null. 346 - 347 -(% style="color: rgb(0,0,0);text-decoration: none;" %)To get the real static cue that always exists and serves as template for instances, use the property (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)staticbase(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %). This works for all cues, even for the static cues themselves. 348 - 349 -(% style="color: rgb(0,0,0);text-decoration: none;" %)In general, to access ancestors of the current cue, you can also use the keyword (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)parent(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %), also recursively as properties of other cues (such as (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)parent.parent.parent).(%%)** 350 - 351 -(% style="color: rgb(0,0,0);text-decoration: none;" %)You can store cue references in variables. But when storing an instance cue in a variable, and later accessing that variable, be aware that the instance may not exist any more. Use the property (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)exists(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) to check if an instance is still alive. (In contrast, non-instance cues always exist, but may be in the (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)disabled// or (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)cancelled// state.) 352 - 353 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 354 - 355 - 356 -(% id="pitfalls" %) 357 - 358 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Pitfalls(%%) == 359 - 360 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Some additional common pitfalls with respect to instantiation are listed here. There may be more. 361 - 362 -* **(% style="color: rgb(0,0,0);text-decoration: none;" %)Conditions with results:(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) If the instantiating cue has conditions with results, those results are stored in variables - but in the variables of the static cue, not of the instance! So in the <actions> you have to access the variables via the (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)static (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)keyword: 363 -\\{{code}}<debug_text┬átext="static.$foo"/>{{/code}}(% style="color: rgb(0,0,255);text-decoration: none;" %) 364 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)It may even be necessary to copy the variables over to the instance because the static variables can be overwritten by the next condition check: 365 -\\{{code}}<set_value┬áname="$foo"┬áexact="static.$foo"/>{{/code}} 366 -* **(% style="color: rgb(0,0,0);text-decoration: none;" %)Resetting completed/cancelled instances:(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) As explained above, sub-instances are only created when needed (when going to the (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)waiting// state) and are destroyed when they are not needed any more (when they are completed or cancelled, including all sub-cues). There are cases in which you want to access cues that donΓÇÖt exist any more - it simply doesnΓÇÖt work. In some cases you are safe: You can be sure that all your ancestors exist, and instantiating cues wonΓÇÖt be removed until they are cancelled. In some other cases you simply donΓÇÖt know and have to check if the instance is already (or still) there. 367 -* **(% style="color: rgb(0,0,0);text-decoration: none;" %)Lifetime of instances:(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) Do not make assumptions about when an instance is removed! Just looking at it in the Debug Manager keeps it alive for the time being. So, sometimes you could still have a completed instance that wouldnΓÇÖt exist under other circumstances. 368 - 369 -(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á 370 - 371 -(% id="categorybroken_macroanchorexpressions" %) 372 - 373 -= (% style="color: rgb(0,0,0);text-decoration: none;" %)Expressions(%%) = 374 - 375 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Most of the attribute values in actions and conditions are interpreted as script expressions and parsed accordingly. An expression is a phrase that can be evaluated to a single value. The simplest expressions are actual numeric values and strings, so called (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)literals:(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) 376 - 377 - 378 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}0{{/code}} (integer number) 379 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}0772{{/code}} (leading 0 means octal integer number) 380 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}3.14159{{/code}} (floating point number) 381 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}5e12{{/code}} (float in exponent notation, ΓÇ£times ten to the power ofΓÇ¥) 382 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}0xCAFE{{/code}} (hexadecimal integer number) 383 - 384 - 385 - 386 -{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">Since octal numbers are hardly ever used (usually unknowingly), the parser is will produce a warning if an octal number is encountered.</span>"/}} 387 - 388 - 389 - 390 -(% style="color: rgb(0,0,0);text-decoration: none;" %)You can write string literals by putting the string in single quotes: 391 - 392 -* {{code}}'Hello world'{{/code}} 393 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}''{{/code}} (empty string) 394 -* {{code}}'String with a line break\n'{{/code}} 395 - 396 - 397 - 398 -{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">Since expressions are written in XML attribute values, you have to use the single quotes inside the double quotes for the actual attribute value. To write characters like </span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~">< > " &</span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~"> in an expression string (or anywhere else in an XML attribute value), youΓÇÖll have to escape them as </span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~">&lt; &gt; &quot; &amp;</span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~"> respectively. The backslash '''\''' can be used in strings for escape characters like in C/C++. Most important are </span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~">\'</span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~"> for a single quote as part of the string, and </span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~">\\</span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~"> for the backslash itself.</span>"/}} 399 - 400 - 401 - 402 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 403 - 404 - 405 -(% id="numeric-data-types-and-suffixes" %) 406 - 407 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Numeric data types and suffixes(%%) == 408 - 409 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Numbers can have a suffix that determines their numeric type. There are also numerical data types like ΓÇ£moneyΓÇ¥ or ΓÇ£timeΓÇ¥ which can only be expressed by using an appropriate unit suffix: 410 - 411 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}5000000000L{{/code}} (large integer) 412 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}1f{{/code}} (floating point number, same as 1.0, just 1 would be an integer) 413 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}1000Cr{{/code}} (Money in Credits, converted to 100000 cents automatically) 414 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}500m{{/code}} (Length in metres) 415 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}10s{{/code}} (Time in seconds) 416 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}1h{{/code}} (Time in hours, which is converted to 3600s automatically) 417 - 418 -(% style="color: rgb(0,0,0);text-decoration: none;" %)A space between number and suffix is allowed. 419 - 420 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Here is the complete list of numeric data types and corresponding unit suffixes: 421 - 422 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 423 - 424 - 425 425 (% style="margin-left: 0.0px;" %) 426 426 ((( 427 -\\ 428 - 429 - 430 - 431 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Data type|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Suffix|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Examples|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Description 432 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)null|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)(none)|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)null|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Converted to non-null data type of value 0 when needed. 433 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)integer|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)i|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)42|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)32-bit signed integer. Default for integer literals, so the suffix is not required for them. 434 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)largeint|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)L|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)0x1ffffffffL|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Large 64-bit signed integer. 435 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)float|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)f| 436 -(% style="color: rgb(0,0,0);text-decoration: none;" %)3.14(%%) 437 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)0x100f|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)32-bit float (single precision). Default for floating point literals, so the suffix is not required for them. 438 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)largefloat|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)LF|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)1.5e300 LF|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Large 64-bit floating point number (double precision). 439 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)money|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)ct (default) 440 -\\Cr|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)200Cr 441 -\\50ct|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Money in Credits or cents, always stored in cents. Do not forget to write Cr when working with Credits. 442 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)length| 443 -(% style="color: rgb(0,0,0);text-decoration: none;" %)m (default)(%%) 444 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)km| 445 -(% style="color: rgb(0,0,0);text-decoration: none;" %)500m(%%) 446 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)2.3km|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Length in metres or kilometres, respectively. A length value is always stored in metres. 447 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)angle| 448 -(% style="color: rgb(0,0,0);text-decoration: none;" %)rad (default)(%%) 449 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)deg| 450 -(% style="color: rgb(0,0,0);text-decoration: none;" %)90deg(%%) 451 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)3.14159rad|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Angle in radians or degrees, respectively. An angle value is always stored in radians. 452 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)hitpoints|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)hp|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)100hp|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Hit points 453 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)time| 454 -(% style="color: rgb(0,0,0);text-decoration: none;" %)ms(%%) 455 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)s (default)(%%) 456 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)min(%%) 457 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)h| 458 -(% style="color: rgb(0,0,0);text-decoration: none;" %)800ms(%%) 459 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)1.5s(%%) 460 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)10min(%%) 461 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)24h|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Time in milliseconds, seconds, minutes, or hours, respectively. A time value is always stored in seconds. 448 +|Data type|Suffix|Examples|Description 449 +|null|(none)|null|Converted to non-null data type of value 0 when needed. 450 +|integer|i|42|32-bit signed integer. Default for integer literals, so the suffix is not required for them. 451 +|largeint|L|0x1ffffffffL|Large 64-bit signed integer. 452 +|float|f| 453 +3.14 454 +\\0x100f|32-bit float (single precision). Default for floating point literals, so the suffix is not required for them. 455 +|largefloat|LF|1.5e300 LF|Large 64-bit floating point number (double precision). 456 +|money|ct (default) 457 +\\Cr|200Cr 458 +\\50ct|Money in Credits or cents, always stored in cents. Do not forget to write Cr when working with Credits. 459 +|length| 460 +m (default) 461 +\\km| 462 +500m 463 +\\2.3km|Length in metres or kilometres, respectively. A length value is always stored in metres. 464 +|angle| 465 +rad (default) 466 +\\deg| 467 +90deg 468 +\\3.14159rad|Angle in radians or degrees, respectively. An angle value is always stored in radians. 469 +|hitpoints|hp|100hp|Hit points 470 +|time| 471 +ms 472 +\\s (default) 473 +\\min 474 +\\h| 475 +800ms 476 +\\1.5s 477 +\\10min 478 +\\24h|Time in milliseconds, seconds, minutes, or hours, respectively. A time value is always stored in seconds. 462 462 ))) 463 463 464 -{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">All unit data types are floating point types, except for money, which is an integer data type.</span>"/}} 481 +{{info}} 482 +All unit data types are floating point types, except for money, which is an integer data type. 483 +{{/info}} 465 465 466 - \\485 +== Operators == 467 467 487 +You can build expressions by combining sub-expressions with operators. For Boolean operations, expressions are considered "false" if they are equal to zero, "true" otherwise. The following operators, delimiters, and constants are supported 468 468 469 - 470 -(% id="categorybroken_macroanchoroperators" %) 471 - 472 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Operators(%%) == 473 - 474 -(% style="color: rgb(0,0,0);text-decoration: none;" %)You can build expressions by combining sub-expressions with operators. For Boolean operations, expressions are considered ΓÇ£falseΓÇ¥ if they are equal to zero, ΓÇ£trueΓÇ¥ otherwise. The following operators, delimiters, and constants are supported: 475 - 476 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 477 - 478 - 479 479 (% style="margin-left: 0.0px;" %) 480 480 ((( 481 -\\ 491 +|Operator / Delimiter / Constant|Type|Example|Result of example|Description 492 +|null|constant|{{code language="xml"}}null + 1{{/code}}|{{code language="xml"}}1{{/code}}|Null value, see above 493 +|false|constant|{{code language="xml"}}1 == 0{{/code}}|{{code language="xml"}}false{{/code}}|Integer value 0, useful in Boolean expressions 494 +|true|constant|{{code language="xml"}}null == 0{{/code}}|{{code language="xml"}}true{{/code}}|Integer value 1, useful in Boolean expressions 495 +|pi|constant|{{code language="xml"}}2 * pi{{/code}}|{{code language="xml"}}6.2831853rad{{/code}}|╧Ç as an angle (same as 180deg) 496 +|()|delimiter|{{code language="xml"}}(2 + 4) * (6 + 1){{/code}}|{{code language="xml"}}42{{/code}}|Parentheses for arithmetic grouping 497 +|[]|delimiter|{{code language="xml"}}[1, 2, 2+1, 'string']{{/code}}|{{code language="xml"}}[1, 2, 3, 'string']{{/code}}|[[List>>doc:||anchor="HLists" style="outline-width: 0px !important; user-select: auto !important;"]] of values 498 +|table[]|delimiter|{{code language="xml"}}table[$foo='bar', {1+1}=40+2]{{/code}}|{{code language="xml"}}table[$foo='bar', {2}=42]{{/code}}|[[Table>>doc:||anchor="HTables" style="outline-width: 0px !important; user-select: auto !important;"]] of values 499 +|{}|delimiter|{{code language="xml"}}{101, 3}{{/code}}|{{code language="xml"}}'Some text'{{/code}}|Text lookup (page ID and text ID) from TextDB 500 +\\(Note: Braces are also used for [[property lookups>>doc:||anchor="HValueproperties" style="outline-width: 0px !important; user-select: auto !important;"]]) 501 +|+|unary|{{code language="xml"}}+21 * (+2){{/code}}|{{code language="xml"}}42{{/code}}|Denotes positive number (no effect) 502 +|-|unary|{{code language="xml"}}-(21 * -2){{/code}}|{{code language="xml"}}42{{/code}}|Negates the following number 503 +|not|unary|{{code language="xml"}}not (21 == 42){{/code}}|{{code language="xml"}}true{{/code}}|Yields true if the following expression is false (equal to zero), false otherwise 504 +|typeof|unary| 505 +{{code language="xml"}}typeof null{{/code}} 506 +\\{{code language="xml"}}typeof 0{{/code}} 507 +\\{{code language="xml"}}typeof 'Hello world'{{/code}}| 508 +{{code language="xml"}}datatype.null{{/code}} 509 +\\{{code language="xml"}}datatype.integer{{/code}} 510 +\\{{code language="xml"}}datatype.string{{/code}}|Yields the [[data type of the following sub-expression>>||anchor="typeof" style="outline-width: 0px !important; user-select: auto !important;"]] 511 +|sin|unary| 512 +{{code language="xml"}}sin(30deg){{/code}} 513 +\\{{code language="xml"}}sin(pi){{/code}}| 514 +{{code language="xml"}}0.5{{/code}} 515 +\\{{code language="xml"}}1.0{{/code}}|Sine (function-style, parentheses required) 516 +|cos|unary| 517 +{{code language="xml"}}cos(60deg){{/code}} 518 +\\{{code language="xml"}}cos(pi){{/code}}| 519 +{{code language="xml"}}0.5{{/code}} 520 +\\{{code language="xml"}}-1.0{{/code}}|Cosine (function-style, parentheses required) 521 +|tan|unary| 522 +{{code language="xml"}}tan(-45deg){{/code}} 523 +\\{{code language="xml"}}tan(45deg){{/code}}| 524 +{{code language="xml"}}-1.0{{/code}} 525 +\\{{code language="xml"}}1.0{{/code}}|((( 526 +Tangent (function-style, parentheses required) 482 482 528 +Available from X4 v7.0 529 +))) 530 +|asin|unary| 531 +{{code language="xml"}}asin(-0.5f){{/code}} 532 +\\{{code language="xml"}}asin(1){{/code}}| 533 +{{code language="xml"}}-0.523599rad{{/code}} 534 +\\{{code language="xml"}}1.5708rad{{/code}}|((( 535 +Inverse sine (function-style, parentheses required) 483 483 537 +Available from X4 v7.0 538 +))) 539 +|acos|unary| 540 +{{code language="xml"}}acos(-0.5f){{/code}} 541 +\\{{code language="xml"}}acos(1.0f){{/code}}| 542 +{{code language="xml"}}2.0944rad{{/code}} 543 +\\{{code language="xml"}}0rad{{/code}}|((( 544 +Inverse cosine (function-style, parentheses required) 484 484 485 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Operator / Delimiter / Constant|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Type|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Example|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Result of example|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Description 486 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)null|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)constant|{{code}}null + 1{{/code}}|{{code}}1{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Null value, see above 487 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)false|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)constant|{{code}}1 == 0{{/code}}|{{code}}false{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Integer value 0, useful in Boolean expressions 488 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)true|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)constant|{{code}}null == 0{{/code}}|{{code}}true{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Integer value 1, useful in Boolean expressions 489 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)pi|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)constant|{{code}}2 * pi{{/code}}|{{code}}6.2831853rad{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)╧Ç as an angle (same as 180deg) 490 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)()|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)delimiter|{{code}}(2 + 4) * (6 + 1){{/code}}|{{code}}42{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Parentheses for arithmetic grouping 491 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)[]|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)delimiter|{{code}}[1, 2, 2+1, 'string']{{/code}}|{{code}}[1, 2, 3, 'string']{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)[[List>>MediaWiki.NULL]] of values 492 -|table[]|delimiter|{{code}}table[$foo='bar', {1+1}=40+2]{{/code}}|{{code}}table[$foo='bar', {2}=42]{{/code}}|[[Table>>MediaWiki.NULL]] of values 493 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %){}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)delimiter|{{code}}{101, 3}{{/code}}|{{code}}'Some text'{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Text lookup (page ID and text ID) from TextDB 494 -\\(Note: Braces are also used for [[property lookups>>MediaWiki.NULL]]) 495 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)+|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary|{{code}}+21 * (+2){{/code}}|{{code}}42{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Denotes positive number (no effect) 496 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)-|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary|{{code}}-(21 * -2){{/code}}|{{code}}42{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Negates the following number 497 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)not|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary|{{code}}not (21 == 42){{/code}}|{{code}}true{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Yields true if the following expression is false (equal to zero), false otherwise 498 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)typeof|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary| 499 -{{code}}typeof null{{/code}} 500 -\\{{code}}typeof 0{{/code}} 501 -\\{{code}}typeof 'Hello world'{{/code}}| 502 -{{code}}datatype.null{{/code}} 503 -\\{{code}}datatype.integer{{/code}} 504 -\\{{code}}datatype.string{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Yields the [[data type of the following sub-expression>>MediaWiki.NULL]] 505 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)sin|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary| 506 -{{code}}sin(30deg){{/code}} 507 -\\{{code}}sin(pi){{/code}}| 508 -{{code}}0.5{{/code}} 509 -\\{{code}}1.0{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Sine (function-style, parentheses required) 510 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)cos|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary| 511 -{{code}}cos(60deg){{/code}} 512 -\\{{code}}cos(pi){{/code}}| 513 -{{code}}0.5{{/code}} 514 -\\{{code}}0.0{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Cosine (function-style, parentheses required) 515 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)sqrt|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary|{{code}}sqrt(2){{/code}}|{{code}}1.414213LF{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Square root (function-style, parentheses required) 516 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)exp|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary|{{code}}exp(1){{/code}}|{{code}}2.71828LF{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Exponential function (function-style, parentheses required) 517 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)log|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary|{{code}}log(8) / log(2){{/code}}|{{code}}3.0LF{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Natural logarithm (function-style, parentheses required) 518 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)^|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|{{code}}10 ^ 3{{/code}}|{{code}}1000.0LF{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Power 519 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)*|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|{{code}}21 * 2{{/code}}|{{code}}42{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Multiplication 520 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)/|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|{{code}}42 / 1042.0 / 10.0{{/code}}|{{code}}44.2{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Division 521 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)%|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|{{code}}42 % 10{{/code}}|{{code}}2{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Modulus (remainder of integer division) 522 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)+|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary| 523 -{{code}}1 + 1{{/code}} 524 -\\{{code}}'Hello' + ' world'{{/code}}| 525 -{{code}}2{{/code}} 526 -\\{{code}}'Hello world'{{/code}}| 527 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Addition(%%) 528 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)String concatenation 529 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)-|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|{{code}}1 - 1{{/code}}|{{code}}0{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Subtraction 546 +Available from X4 v7.0 547 +))) 548 +|atan|unary| 549 +{{code language="xml"}}atan(1.0f){{/code}}| 550 +{{code language="xml"}}0.785398rad{{/code}}|((( 551 +Inverse tangent (function-style, parentheses required) 552 + 553 +Available from X4 v7.0 554 +))) 555 +|sqrt|unary|{{code language="xml"}}sqrt(2){{/code}}|{{code language="xml"}}1.414213LF{{/code}}|Square root (function-style, parentheses required) 556 +|exp|unary|{{code language="xml"}}exp(1){{/code}}|{{code language="xml"}}2.71828LF{{/code}}|Exponential function (function-style, parentheses required) 557 +|log|unary|{{code language="xml"}}log(8) / log(2){{/code}}|{{code language="xml"}}3.0LF{{/code}}|Natural logarithm (function-style, parentheses required) 558 +|^|binary|{{code language="xml"}}10 ^ 3{{/code}}|{{code language="xml"}}1000.0LF{{/code}}|Power 559 +|*|binary|{{code language="xml"}}21 * 2{{/code}}|{{code language="xml"}}42{{/code}}|Multiplication 560 +|/|binary|{{code language="xml"}}42 / 1042.0 / 10.0{{/code}}|{{code language="xml"}}44.2{{/code}}|Division 561 +|%|binary|{{code language="xml"}}42 % 10{{/code}}|{{code language="xml"}}2{{/code}}|Modulus (remainder of integer division) 562 +|+|binary| 563 +{{code language="xml"}}1 + 1{{/code}} 564 +\\{{code language="xml"}}'Hello' + ' world'{{/code}}| 565 +{{code language="xml"}}2{{/code}} 566 +\\{{code language="xml"}}'Hello world'{{/code}}| 567 +Addition 568 +\\String concatenation 569 +|-|binary|{{code language="xml"}}1 - 1{{/code}}|{{code language="xml"}}0{{/code}}|Subtraction 530 530 | 531 - (% style="color: rgb(0,0,0);text-decoration: none;" %)lt(%%)532 -\\ (%style="color: rgb(0,0,0);text-decoration: none;" %)< (<)|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|533 -{{code}}1 lt 3{{/code}} 534 -\\{{code }}1&lt;3{{/code}}|{{code}}true{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Less than571 +lt 572 +\\< (<)|binary| 573 +{{code language="xml"}}1 lt 3{{/code}} 574 +\\{{code language="xml"}}1 < 3{{/code}}|{{code language="xml"}}true{{/code}}|Less than 535 535 | 536 - (% style="color: rgb(0,0,0);text-decoration: none;" %)le(%%)537 -\\ (% style="color: rgb(0,0,0);text-decoration: none;" %)<=|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|538 -{{code}}1 le 3{{/code}} 539 -\\{{code }}1&lt;= 3{{/code}}|{{code}}true{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Less than or equal to576 +le 577 +\\<=|binary| 578 +{{code language="xml"}}1 le 3{{/code}} 579 +\\{{code language="xml"}}1 <= 3{{/code}}|{{code language="xml"}}true{{/code}}|Less than or equal to 540 540 | 541 - (% style="color: rgb(0,0,0);text-decoration: none;" %)gt(%%)542 -\\ (%style="color: rgb(0,0,0);text-decoration: none;" %)> (>)|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|543 -{{code}}1 gt 3{{/code}} 544 -\\{{code}}1 &gt;3{{/code}}|{{code}}false{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Greater than581 +gt 582 +\\> (>)|binary| 583 +{{code language="xml"}}1 gt 3{{/code}} 584 +\\{{code language="xml"}}1 > 3{{/code}}|{{code language="xml"}}false{{/code}}|Greater than 545 545 | 546 -(% style="color: rgb(0,0,0);text-decoration: none;" %)ge(%%) 547 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)>=|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary| 548 -{{code}}1 ge 3{{/code}} 549 -\\{{code}}1 &gt;= 3{{/code}}|{{code}}false{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Greater than or equal to 550 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)==|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|{{code}}1 + 1 == 2.0{{/code}}|{{code}}true{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Equal to 551 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)~!=|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|{{code}}1 + 1 != 2.0{{/code}}|{{code}}false{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Not equal to 552 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)and|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|{{code}}true and false{{/code}}|{{code}}false{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Logical AND (short-circuit semantics) 553 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)or|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary|{{code}}true or false{{/code}}|{{code}}true{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Logical OR (short-circuit semantics) 586 +ge 587 +\\>=|binary| 588 +{{code language="xml"}}1 ge 3{{/code}} 589 +\\{{code language="xml"}}1 >= 3{{/code}}|{{code language="xml"}}false{{/code}}|Greater than or equal to 590 +|((( 591 + 592 +)))|binary|{{code language="xml"}}1 + 1 == 2.0{{/code}}|{{code language="xml"}}true{{/code}}|Equal to 593 +|~!=|binary|{{code language="xml"}}1 + 1 != 2.0{{/code}}|{{code language="xml"}}false{{/code}}|Not equal to 594 +|and|binary|{{code language="xml"}}true and false{{/code}}|{{code language="xml"}}false{{/code}}|Logical AND (short-circuit semantics) 595 +|or|binary|{{code language="xml"}}true or false{{/code}}|{{code language="xml"}}true{{/code}}|Logical OR (short-circuit semantics) 554 554 | 555 555 if ... then ... 556 556 \\if ... then ... else ...|ternary| 557 -{{code}}if 1 == 2 then 'F'{{/code}} 558 -\\{{code}}if 1 == 2 then 'F' else 'T'{{/code}}| 559 -{{code}}null{{/code}} 560 -\\{{code}}'T'{{/code}}|Conditional operator ("inline if") 561 - 562 - 563 -\\ 564 - 565 - 599 +{{code language="xml"}}if 1 == 2 then 'F'{{/code}} 600 +\\{{code language="xml"}}if 1 == 2 then 'F' else 'T'{{/code}}| 601 +{{code language="xml"}}null{{/code}} 602 +\\{{code language="xml"}}'T'{{/code}}|Conditional operator ("inline if") 566 566 ))) 567 567 568 - (% id="operator-precedence-rules"%)605 +=== Operator precedence rules === 569 569 570 - ===(%style="color:rgb(0,0,0);text-decoration:none;"%)Operator precedence rules(%%)===607 +You can group sub-expressions using parentheses, but if you don't, the following order of operations is applied, so that 5-1+2*3 == 10 as you would expect. The order is the same as in the table above, but there are operators with the same precedence - these are applied from left to right. 571 571 572 -(% style="color: rgb(0,0,0);text-decoration: none;" %)You can group sub-expressions using parentheses, but if you donΓÇÖt, the following order of operations is applied, so that 5-1+2*3 == 10 as you would expect. The order is the same as in the table above, but there are operators with the same precedence - these are applied from left to right. 609 +* Unary operators: +, -, not, typeof, function-style operators (highest precedence) 610 +* Power operator: ^ 611 +* Multiplicative: *, /, % 612 +* Additive: +, - 613 +* Comparison: lt, le, gt, ge 614 +* Equality: ==, != 615 +* and 616 +* or 617 +* if/then/else (lowest precedence) 573 573 619 +=== Type conversion === 574 574 575 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Unary operators: +, -, not, typeof, function-style operators (highest precedence) 576 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Power operator: ^ 577 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Multiplicative: *, /, % 578 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Additive: +, - 579 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Comparison: lt, le, gt, ge 580 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Equality: ==, != 581 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)and 582 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)or 583 -* if/then/else(% style="color: rgb(0,0,0);text-decoration: none;" %) (lowest precedence) 621 +When a binary arithmetic operator is used on numbers of different types, they will be converted to a suitable output type. The resulting type depends on whether a unit data type is involved (types that are not plain integers or floats). The following cases may occur: 584 584 585 -(% id="type-conversion" %) 623 +* Null and something else: The null value will be interpreted as "0" of the other type. 624 +* Two non-unit integers: The result will be an integer of the largest involved type. 625 +* Two non-unit numbers, not all integers: The result will be the largest involved float type. 626 +* Non-unit and unit: The result will be the unit type. 627 +* Two different units: The types are incompatible. This is an error, the result is undefined. 586 586 587 - ===(%style="color:rgb(0,0,0);text-decoration:none;"%)Type conversion(%%)===629 +For multiplication and division, this may not be intuitive in all cases: Dividing a length by another length results in a length - so if you want to have a simple float as a result, you will have to convert it manually. 588 588 589 - (% style="color: rgb(0,0,0);text-decoration:none;" %)Whenabinaryarithmeticoperatorisused onnumbersofdifferent types,they will be converted toasuitableoutputtype.The resulting type depends onwhether aunitdatatypeis involved(types that areotplain integersor floats). Thefollowing cases may occur:631 +There is a way to convert a number into a different type manually: You append the corresponding suffix to a sub-expression in parentheses, like this: 590 590 591 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Null and something else: The null value will be interpreted as ΓÇ£0ΓÇ¥ of the other type. 592 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Two non-unit integers: The result will be an integer of the largest involved type. 593 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Two non-unit numbers, not all integers: The result will be the largest involved float type. 594 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Non-unit and unit: The result will be the unit type. 595 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Two different units: The types are incompatible. This is an error, the result is undefined. 633 +* {{code language="xml"}}(1 + 1)f{{/code}}⟹ {{code language="xml"}}2f{{/code}} ⟹ {{code language="xml"}}2.0{{/code}} 634 +* {{code language="xml"}}(1h) m / (180deg) i{{/code}}⟹ {{code language="xml"}}(3600s) m / (3.14rad) i{{/code}} ⟹ {{code language="xml"}}3600m / 3{{/code}} ⟹ {{code language="xml"}}1200m{{/code}} 596 596 597 - (% style="color:rgb(0,0,0);text-decoration:none;" %)For multiplicationand division, this may notbeintuitive inall cases:Dividinga lengthby anotherlength resultsinalength- so ifyouwantohaveaimplefloatasaresult,you willhavetoconvert itmanually.636 +When converting to a non-default unit type, this means you interpret the number as in the given units: "{{code language="xml"}}(1km + 500m)h{{/code}}" means that you interpret 1500m as 1500 hours, so the resulting value will be 1500x3600 seconds. (As stated above, the default unit for a length is metres.) 598 598 599 - (%style="color:rgb(0,0,0);text-decoration:none;" %)Thereisawaytoconverta numberintoadifferenttypemanually:You appendthecorrespondingsuffixto a sub-expressioninparentheses,likethis:638 +The division operation will be an integer division (rounding towards zero) if both operands are integers (see the example in the table above). So if you want to get a floating point result, you have to make sure that at least one of the operands is a floating point type. 600 600 601 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}(1 + 1)f{{/code}} Γƒ╣ {{code}}2f{{/code}} Γƒ╣ {{code}}2.0{{/code}} 602 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}(1h) m / (180deg) i{{/code}} Γƒ╣ {{code}}(3600s) m / (3.14rad) i{{/code}} Γƒ╣ {{code}}3600m / 3{{/code}} Γƒ╣ {{code}}1200m{{/code}} 640 +Every data type can be combined with a string with the + operator, and will be converted to a string representation. That way you can also concatenate strings and numbers: 603 603 604 -(% style="color: rgb(0,0,0);text-decoration: none;" %)When converting to a non-default unit type, this means you interpret the number as in the given units: ΓÇ£{{code}}(1km + 500m)h{{/code}}ΓÇ¥ means that you interpret 1500m as 1500 hours, so the resulting value will be 1500x3600 seconds. (As stated above, the default unit for a length is metres.) 642 +* {{code language="xml"}}'One plus one is equal to ' + (1+1) + '.'{{/code}}⟹ {{code language="xml"}}'One plus one is equal to 2.'{{/code}} 643 +* {{code language="xml"}}'One plus one is not equal to ' + 1 + 1 + '.'{{/code}}⟹ {{code language="xml"}}'One plus one is not equal to 11.'{{/code}} 605 605 606 - (%style="color:rgb(0,0,0);text-decoration:none;" %)Thedivision operation will be an integerdivision(rounding towards zero) ifbothoperandsareintegers (seethexamplein thetableabove).So if you want to getafloatingpoint result, youhavetoakesure that atleast one ofheoperandsis a floatingpointtype.645 +As you can see, operators of the same precedence (+ in this case) are always evaluated from left to right. 607 607 608 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Every data type can be combined with a string with the + operator, and will be converted to a string representation. That way you can also concatenate strings and numbers: 609 609 610 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}'One plus one is equal to ' + (1+1) + '.'{{/code}} Γƒ╣ {{code}}'One plus one is equal to 2.'{{/code}} 611 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}'One plus one is not equal to ' + 1 + 1 + '.'{{/code}} Γƒ╣ {{code}}'One plus one is not equal to 11.'{{/code}} 648 +=== Boolean operators === 612 612 613 - (% style="color: rgb(0,0,0);text-decoration:none;" %)Asyoucansee,operatorsof thesame precedence (+ in thiscase)are always evaluatedfromleft toright.650 +Some additional notes on Boolean operators (such as and, or, not, ==): 614 614 615 -(% id="boolean-operators" %) 652 +* Of course a Boolean operation always results in true or false (integer 1 or 0). 653 +* Values of any type can be used as Boolean operands, e.g. for "and". They will be interpreted as "true" if they are **non-zero** or **non-numeric**. 654 +* != and == can be used with any data types, even non-numeric ones. When comparing two numeric values, they are converted using the rules above. Values of non-numeric types are never equal to null, or to any other numbers. 655 +* "and" and "or" use short-circuit semantics: The right side of the operation can be skipped if the left side already determines the outcome of the operation 656 +** Example:{{code language="xml"}} false and $foo{{/code}} ⟹ {{code language="xml"}}false{{/code}} (the value of $foo is not checked at all) 657 +* Unlike != and ==, the comparison operators <, <=, >, >= are only supported **for numeric values**, **difficulty levels**, and **attention levels**. Comparing other non-numeric values will result in an error and an undefined result. 658 +* <, <=, >, >= cannot be used in XML directly, so lt, le, gt, ge are provided as alternatives. In some cases you won't have to use them, though - using [[range checks>>doc:||anchor="HValuecomparisons"]] with additional XML attributes can be more readable. 616 616 617 -== =(%style="color:rgb(0,0,0);text-decoration: none;" %)Boolean operators(%%) ===660 +== (% id="categorybroken_macroanchorstrings-and-formatting" %)Strings and formatting(%%) == 618 618 619 - (%style="color:rgb(0,0,0);text-decoration:none;"%)Somedditionalnotes onBooleanoperators(such as and,or,not,==):662 +You can concatenate string literals using the + operator, but there is also a printf-like formatting syntax, which is easier to use than concatenating lots of small pieces: 620 620 664 +* {{code language="xml"}}'The %1 %2 %3 jumps over the %5 %4'.['quick', 'brown', 'fox', 'dog', 'lazy']{{/code}} 665 +* {{code language="xml"}}'%1 + %2 = %3'.[$a, $b, $a + $b]{{/code}} 621 621 622 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Of course a Boolean operation always results in true or false (integer 1 or 0). 623 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Values of any type can be used as Boolean operands, e.g. for ΓÇ£andΓÇ¥. They will be interpreted as ΓÇ£trueΓÇ¥ if they are (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)non-zero(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) or (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)non-numeric(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %). 624 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)!= and == can be used with any data types, even non-numeric ones. When comparing two numeric values, they are converted using the rules above. Values of non-numeric types are never equal to null, or to any other numbers. 625 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)ΓÇ£andΓÇ¥ and ΓÇ£orΓÇ¥ use short-circuit semantics: The right side of the operation can be skipped if the left side already determines the outcome of the operation 626 -** Example:(% style="color: rgb(0,0,0);text-decoration: none;" %){{code}} false and $foo{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) {{code}}false{{/code}} (the value of $foo is not checked at all) 627 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Unlike != and ==, the comparison operators <, <=, >, >= are only supported (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)for numeric values(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %), (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)difficulty levels(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %), and (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)attention levels(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %). Comparing other non-numeric values will result in an error and an undefined result. 628 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)<, <=, >, >= cannot be used in XML directly, so lt, le, gt, ge are provided as alternatives. In some cases you wonΓÇÖt have to use them, though - using [[range checks>>MediaWiki.NULL]] with additional XML attributes can be more readable. 667 +See also the section about [[value properties>>doc:||anchor="HValueproperties" style="outline-width: 0px !important; user-select: auto !important;"]]. 629 629 630 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 669 +Instead of '%1 %2 %3', you can also use '%s %s %s', which is also compatible with Lua string formatting in the UI system. However, this should only be used if you are sure that the order is the same in all supported languages. If you want to make translators aware that they can change the order of parameters, you should prefer '%1 %2 %3'. 670 +\\To get a percent character in the result string, use '%%' in the format string. 671 +\\\\\\If you need a more sophisticated method for text substitution, try **<substitute_text>**. See the XML schema documentation for this script action. 672 +\\**[New as of X Rebirth 4.0]** 673 +\\ With the formatting syntax above, it is even possible to control how the parameter is formatted, using modifiers between "%" and the parameter specifier ("s" or the parameter number): 631 631 675 +* {{code language="xml"}}'%,s'.[12345678]{{/code}}⟹ {{code language="xml"}}'12,345,678'{{/code}} (the "," modifier shows a number with thousands separators, correctly localised) 676 +* {{code language="xml"}}'%.3s'.[123.4]{{/code}}⟹ {{code language="xml"}}'123.400'{{/code}} (show 3 fractional digits, rounding half away from zero - decimal point correctly localised) 677 +* {{code language="xml"}}'%,.1s'.[12345.67]'{{/code}}⟹ {{code language="xml"}}'12,345.7'{{/code}} (combination of the above) 632 632 633 -(% id="categorybroken_macroanchorstrings-and-formatting" %)(%%) 634 -~== (% style="color: rgb(0,0,0);text-decoration: none;" %)Strings and formatting 635 -\\(%%) == 636 - 637 -(% style="color: rgb(0,0,0);text-decoration: none;" %)You can concatenate string literals using the + operator, but there is also a printf-like formatting syntax, which is easier to use than concatenating lots of small pieces: 638 - 639 -* {{code}}'The %1 %2 %3 jumps over the %5 %4'.['quick', 'brown', 'fox', 'dog', 'lazy']{{/code}} 640 -* {{code}}'%1 + %2 = %3'.[$a, $b, $a + $b]{{/code}} 641 - 642 -(% style="color: rgb(0,0,0);text-decoration: none;" %)See also the section about [[value properties>>MediaWiki.NULL]]. 643 - 644 -Instead of ΓÇÿ%1 %2 %3ΓÇÖ, you can also use ΓÇÿ%s %s %sΓÇÖ, which is also compatible with Lua string formatting in the UI system. However, this should only be used if you are sure that the order is the same in all supported languages. If you want to make translators aware that they can change the order of parameters, you should prefer '%1 %2 %3'. 645 - 646 -To get a percent character in the result string, use '%%' in the format string. 647 - 648 - 649 -(% style="color: rgb(0,0,0);text-decoration: none;" %)If you need a more sophisticated method for text substitution, try (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)<substitute_text>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %). See the XML schema documentation for this script action. 650 - 651 -**[New as of X Rebirth 4.0]** 652 - 653 -With the formatting syntax above, it is even possible to control how the parameter is formatted, using modifiers between "%" and the parameter specifier ("s" or the parameter number): 654 - 655 -* {{code}}'%,s'.[12345678]{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) {{code}}'12,345,678'{{/code}} (the "," modifier shows a number with thousands separators, correctly localised) 656 -* {{code}}'%.3s'.[123.4]{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) {{code}}'123.400'{{/code}} (show 3 fractional digits, rounding half away from zero - decimal point correctly localised) 657 -* {{code}}'%,.1s'.[12345.67]'{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) {{code}}'12,345.7'{{/code}} (combination of the above) 658 - 659 659 Additional remarks: 660 660 661 661 * The "," and "." formatting modifiers only apply to numbers. They are ignored if used on values of other types. 662 -* ┬áIf "," is used without "." then any fractional digits are discarded.682 +* If "," is used without "." then any fractional digits are discarded. 663 663 * "." must be followed by a single digit (0-9). In case of ".0" any fractional digits are discarded (rounding towards zero, not half away from zero). 664 664 685 +{{info}} 686 +There are also special methods to [[format money values and time values>>doc:||anchor="HMoneyandtimeformatting" style="outline-width: 0px !important; user-select: auto !important;"]] using the "formatted" property. 687 +{{/info}} 665 665 689 +== Lists == 666 666 667 - {{infobody="<spanstyle=~"color:rgb(0,0,0);text-decoration:none;~">There are also specialmethods to [[NULL|format moneyvaluesdtimeues]]usingthe"formatted"property.</span>"/}}691 +Another example for a non-numeric value is a list: It is an ordered collection of other arbitrary values (called array or vector in other languages). It can be constructed within an expression using the [[~[~] syntax>>doc:||anchor="HOperators"]]. It may also be generated by special actions and conditions, and there are actions that can [[insert or remove values>>doc:||anchor="HCreatingandremovingvariables" style="outline-width: 0px !important; user-select: auto !important;"]]. 668 668 693 +A list can contain values of arbitrary data types, even mixed in the same list - so a list can actually contain other lists. However, some of the things that you can do with lists require that all contained elements are of a certain type. The contents of a list can be accessed via properties, see the section about [[value properties>>doc:||anchor="HValueproperties"]]. Lists can be empty, these are written as "[ ]". 669 669 695 +{{info}} 696 +When accessing a list's elements, the numbering is '''1-based''', so the first element has number 1. This is intuitive but different from 0-based numbering in most programming languages." 697 +{{/info}} 670 670 671 - (%style="color: rgb(0,0,0);text-decoration:none;"%)699 +Lists are stored in variables as references, so multiple variables can refer to the same **shared list**: If you change a shared list through a variable, e.g. by changing the value of an element, you change it as well for all other variables. However, the operators == and != can also be used on two distinct lists to compare their elements. 672 672 701 +{{info}} 702 +When using <remove_from_list/>, be aware that all elements are checked and potentially removed during the action. Do not provide this action with a index lookup of that list as it may become out of bounds. 673 673 674 - (% id="categorybroken_macroanchorlists"%)704 +Bad usage attempting to remove the last element of the list: <remove_from_list name="$List" exact="$List.{$List.count}"/> 675 675 676 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Lists(%%) == 706 +If you know the index, simply use <remove_value/> e.g. <remove_value name="$List.{$List.count}"/> 707 +{{/info}} 677 677 678 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Another example for a non-numeric value is a list: It is an ordered collection of other arbitrary values (called array or vector in other languages). It can be constructed within an expression using the [[~[~] syntax>>MediaWiki.NULL]]. It may also be generated by special actions and conditions, and there are actions that can [[insert or remove values>>MediaWiki.NULL]]. 679 - 680 -(% style="color: rgb(0,0,0);text-decoration: none;" %)A list can contain values of arbitrary data types, even mixed in the same list - so a list can actually contain other lists. However, some of the things that you can do with lists require that all contained elements are of a certain type. The contents of a list can be accessed via properties, see the section about [[value properties>>MediaWiki.NULL]]. Lists can be empty, these are written as ΓÇ£[ ]ΓÇ¥. 681 - 682 -{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">When accessing a listΓÇÖs elements, the numbering is </span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~">1-based</span>'''<span style=~"color: rgb(0,0,0);text-decoration: none;~">, so the first element has number 1. This is intuitive but different from 0-based numbering in most programming languages.</span>"/}} 683 - 684 - 685 - 686 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Lists are stored in variables as references, so multiple variables can refer to the same (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)shared list(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): If you change a shared list through a variable, e.g. by changing the value of an element, you change it as well for all other variables. However, the operators == and != can also be used on two distinct lists to compare their elements. 687 - 688 -{{note body="When using <remove_from_list/>, be aware that all elements are checked and potentially removed during the action. Do not provide this action with a index lookup of that list as it may become out of bounds. 689 - 690 -Bad usage attempting to remove the last element of the list: <remove_from_list name="$List" exact="$List.{$List.count}"/> 691 - 692 -If you know the index, simply use <remove_value/> e.g. <remove_value name="$List.{$List.count}"/>"/}} 693 - 694 - 695 - 696 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 697 - 698 - 699 699 (% id="categorybroken_macroanchortables" %) 710 +== Tables == 700 700 701 - ==(%style="color:rgb(0,0,0);text-decoration: none;"%)Tables(%%)==712 +Tables are associative arrays - they are like lists, but you can assign values to (almost) arbitrary keys, not just to index numbers. A table is constructed within an expression using the [[table~[~] syntax>>doc:||anchor="HOperators" style="outline-width: 0px !important; user-select: auto !important;"]]. See the section about [[value properties>>doc:||anchor="HValueproperties" style="outline-width: 0px !important; user-select: auto !important;"]] for how to access the contents of a table. [[Creating and removing entries>>doc:||anchor="HCreatingandremovingvariables" style="outline-width: 0px !important; user-select: auto !important;"]] works similarly to lists, but instead of inserting, you simply assign a value to a table key. If the key does not exist yet, it will be created. 702 702 703 - (% style="color: rgb(0,0,0);text-decoration: none;" %)Tablesare associativearrays - they arelikelists,but you can assignvaluesto (almost) arbitrary keys,not just to index numbers. A table is constructedwithinan expressionusingthe [[table~[~]syntax>>MediaWiki.NULL]]. See thesectionabout[[value properties>>MediaWiki.NULL]] forhow to access the contents of a table. [[Creatingandremovingentries>>MediaWiki.NULL]]workssimilarly to lists, but instead of inserting, you simply assigna value to a table key. If the key doesnot exist yet, it will be created.714 +Almost all values are allowed as table keys, but there are a few exceptions: 704 704 716 +* Strings must start with '$', like variables 717 +* null cannot be used as table key (but the number 0 is valid) 718 +* Lists, tables, groups and buildplans cannot be used as table keys 705 705 706 - (%style="color:rgb(0,0,0);text-decoration:none;" %)Almostallvaluesare allowedas tablekeys,but therearea few exceptions:720 +These restrictions only apply to the keys, there are no restrictions for values that you assign to them. For example: 707 707 708 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Strings must start with '$', like variables 709 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)null cannot be used as table key (but the number 0 is valid) 710 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Lists, tables, groups and buildplans cannot be used as table keys 711 -\\ 722 +* {{code language="xml"}}table[]{{/code}}⟹ creates an empty table 723 +* {{code language="xml"}}table[{0} = null]{{/code}}⟹ creates a table that maps the number 0 to null 712 712 713 -(% style="color: rgb(0,0,0);text-decoration: none;" %)These restrictions only apply to the keys, there are no restrictions for values that you assign to them. For example: 725 +* {{code language="xml"}}table[{'$foo'} = 'bar']{{/code}}⟹ a table that maps the string '$foo' to the string 'bar' 726 +* {{code language="xml"}}table[$foo = 'bar']{{/code}}⟹ exactly the same, just a shorter notation for string keys 727 +* {{code language="xml"}}table[foo = 'bar']{{/code}}⟹ error, 'foo' does not start with a '$' 728 +* {{code language="xml"}}table[{1} = [], {2} = table[]] {{/code}}⟹ a table that maps 1 to an empty list and 2 to an empty table 714 714 715 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[]{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) creates an empty table 716 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[{0} = null]{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) creates a table that maps the number 0 to null 730 +Just like lists, tables are stored as references, so it's possible that multiple variables reference the same table (see above). 717 717 732 +== Value properties == 718 718 734 +Properties are a crucial concept in script expressions. In the previous sections you have seen mostly constant expressions, which are already evaluated when they are parsed at game start. For reading and writing variables and evaluating the game's state, properties are used. 719 719 736 +Numbers don't have any properties. Lists, for example, have quite a few of them: You can access the number of elements; and each element is also a property of the list. A ship can have properties like its name, the ship class, its position etc. 720 720 721 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[{'$foo'} = 'bar']{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) a table that maps the string '$foo' to the string 'bar' 722 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[$foo = 'bar']{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) exactly the same, just a shorter notation(%%) for string keys 723 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[foo = 'bar']{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) error, 'foo' does not start with a '$' 724 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[{1} = [], {2} = table[]] {{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) a table that maps 1 to an empty list and 2 to an empty table 738 +You can imagine properties as key/value pairs in an associative mapping: You pass the key, and you get the value as result. For example, the list [42, null, 'text'] has the following mapping: 725 725 740 +* 1 ⟹ 42 741 +* 2 ⟹ null 742 +* 3 ⟹ 'text' 743 +* 'count' ⟹ 3 726 726 727 - (%style="color:rgb(0,0,0);text-decoration:none;"%)Justlikelists, tablesarestoredasreferences,so it's possiblethatmultiplevariables referencethesametable(seeabove).745 +As you can see, a property key can be a number or a string. Actually there is no restriction regarding the data type of the key. 728 728 747 +You can look up a property by appending a dot and the key in curly braces: 729 729 730 -(% style="color: rgb(0,0,0);text-decoration: none;" %) 749 +* {{code language="xml"}}[100, 200, 300, 400].{1}{{/code}}⟹ 100 (reading the first element) 750 +* {{code language="xml"}}[100, 200, ['Hello ', 'world']] .{3}.{2}{{/code}}⟹ 'world' (second element of the inner list, which is the third element of the outer list) 751 +* {{code language="xml"}}[].{'count'}{{/code}}⟹ 0 752 +* {{code language="xml"}}table[{21} = 42].{21}{{/code}}⟹ 42 731 731 754 +In most cases the property key is a fixed string, like "name" or "class". You can write this like above: 732 732 733 -(% id="categorybroken_macroanchorvalue-properties" %) 756 +* {{code language="xml"}}[42].{'count'}{{/code}} 757 +* {{code language="xml"}}$ship.{'name'}{{/code}} 758 +* {{code language="xml"}}$ship.{'class'}{{/code}} 759 +* {{code language="xml"}}table[$foo='bar'].{'$foo'}{{/code}} 734 734 735 - ==(%style="color:rgb(0,0,0);text-decoration: none;"%)Value properties(%%)==761 +But it is easier just to write the property key without braces, which is equivalent: 736 736 737 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Properties are a crucial concept in script expressions. In the previous sections you have seen mostly constant expressions, which are already evaluated when they are parsed at game start. For reading and writing variables and evaluating the gameΓÇÖs state, properties are used. 763 +* {{code language="xml"}}[0].count{{/code}} 764 +* {{code language="xml"}}$ship.name{{/code}} 765 +* {{code language="xml"}}$ship.class{{/code}} 766 +* {{code language="xml"}}table[$foo='bar'].$foo{{/code}} 738 738 739 -( %style="color:rgb(0,0,0);text-decoration: none;"%)NumbersdonΓÇÖthaveany properties.Lists,forexample,havequiteafewofthem:Youcanaccessthenumberof elements; andeach elementis also a property of thelist. A ship can havepropertieslike its name, the ship class, its position etc.768 +(In this case, $ship is a variable. All variables start with a "$", so they cannot be confused with keywords.) 740 740 741 - (%style="color: rgb(0,0,0);text-decoration: none;" %)You can imagine properties askey/valuepairs inan associativemapping: Youpass thekey, and you get the value asresult. For example, the list [42, null, 'text'] hasthe following mapping:770 +A list has even more properties: 742 742 743 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)1 Γƒ╣ 42 744 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)2 Γƒ╣ null 745 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)3 Γƒ╣ 'text' 746 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)'count' Γƒ╣ 3 772 +**random'** returns a randomly chosen element (which requires that the list is non-empty) 747 747 748 - (% style="color: rgb(0,0,0);text-decoration:none;" %)As you cansee,aproperty key canbeanumberor astring. Actuallythereis no restrictionregardingthedata type ofthekey.774 +**min'** and '**max'** return the minimum or maximum (all elements have to be numeric) 749 749 750 - (%style="color: rgb(0,0,0);text-decoration:none;" %)You canlookupapropertybyappending a dot andthekey in curly braces:776 +* {{code language="xml"}}[1, 6, 8].min{{/code}}⟹ 1 751 751 752 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[100, 200, 300, 400].{1}{{/code}} Γƒ╣ 100 (reading the first element) 753 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[100, 200, ['Hello ', 'world']] .{3}.{2}{{/code}} Γƒ╣ 'world' (second element of the inner list, which is the third element of the outer list) 754 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[].{'count'}{{/code}} Γƒ╣ 0 755 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[{21} = 42].{21}{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) 42 778 +**average'** returns the average (but all element types have to be compatible) 756 756 780 +* {{code language="xml"}}[1, 6, 8].average{{/code}}⟹ 5 757 757 758 - (%style="color:rgb(0,0,0);text-decoration:none;"%)Inmostcasesthepropertykey isa fixedstring,likeΓÇ£nameΓÇ¥orΓÇ£classΓÇ¥.Youcanwritethislike above:782 +**indexof'** is followed by another property, and the index of the first occurence of that key in the list is returned, or 0 if it's not in the list 759 759 760 -* {{code}}[42].{'count'}{{/code}} 761 -* {{code}}$ship.{'name'}{{/code}} 762 -* {{code}}$ship.{'class'}┬á{{/code}} 763 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[$foo='bar'].{'$foo'}{{/code}} 764 -\\ 784 +* {{code language="xml"}}[1, 6, 8].indexof.{8}{{/code}}⟹ 3 765 765 766 - (% style="color:rgb(0,0,0);text-decoration:none;"%)Butit iseasierjust towrite thepropertykeywithoutbraces,whichisequivalent:786 +**clone'** creates a shallow copy of the list (i.e. lists that are contained as elements in the list are not copied, only the reference to them) 767 767 768 -* {{code}}[0].count{{/code}} 769 -* {{code}}$ship.name{{/code}} 770 -* {{code}}$ship.class{{/code}} 771 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[$foo='bar'].$foo{{/code}} 772 -\\ 788 +* {{code language="xml"}}[1, 6, 8].clone{{/code}}⟹ {{code language="xml"}}[1, 6, 8]{{/code}} 773 773 774 - (%style="color:rgb(0,0,0);text-decoration: none;" %)(In this case,$ship is a variable. All variables start with a ΓÇ£$ΓÇ¥, so they cannotbe confused with keywords.)790 +A table has different properties: 775 775 776 -(% style="color: rgb(0,0,0);text-decoration: none;" %)A list has even more properties: 792 +* '**clone'** creates a shallow copy of the table 793 +* '**keys'** allows you to access data about the table's keys 777 777 778 - (%style="color:rgb(0,0,0);text-decoration:none;"%)'(%%)**(%style="color: rgb(0,0,0);text-decoration:none;"%)random(%%)**(% style="color:rgb(0,0,0);text-decoration:none;" %)'returns a randomly chosenelement(whichrequiresthatthe list is non-empty)795 +However, 'keys' alone will not give you a result. 'keys' must be followed by another keyword to retrieve the desired information, for example: 779 779 780 -(% style="color: rgb(0,0,0);text-decoration: none;" %)'(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)min(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)' and '(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)max(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)' return the minimum or maximum (all elements have to be numeric) 781 781 782 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[1, 6, 8].min{{/code}} Γƒ╣ 1 783 783 784 - (%style="color: rgb(0,0,0);text-decoration: none;" %)'(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)average(%%)**(% style="color:rgb(0,0,0);text-decoration:none;"%)'returns the average(butall element typeshaveto be compatible)799 +* {{code language="xml"}}$table.keys.list{{/code}}: Yields a list of all keys in the table (reliably sorted by key if all keys are numeric) 785 785 786 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[1, 6, 8].average{{/code}} Γƒ╣ 5 801 +* {{code language="xml"}}$table.keys.sorted{{/code}}: Yields a list of all keys in the table, sorted by their associated values (which requires that all values are numeric) 802 +* {{code language="xml"}}$table.keys.random{{/code}}: A randomly chosen key (which requires that the table is non-empty) 787 787 788 -(% style="color: rgb(0,0,0);text-decoration: none;" %)'(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)indexof(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)' is followed by another property, and the index of the first occurence of that key in the list is returned, or 0 if itΓÇÖs not in the list 804 +{{info}} 805 +The string formatting syntax that you have seen [[above>>doc:||anchor="HStringsandformatting" style="outline-width: 0px !important; user-select: auto !important;"]] is also based on the property system. You basically pass a list as property key to a string. Braces around the brackets are not required, so 'foo'.[...] is just a convenient alternative notation for 'foo'.{[...]}. 806 +{{/info}} 789 789 790 - *(%style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[1,6,8].indexof.{8}{{/code}}Γƒ╣ 3808 +=== (% id="lookup-tests-and-suppressing-errors" %)Lookup tests and suppressing errors(%%) === 791 791 792 - (%style="color:rgb(0,0,0);text-decoration:none;"%)'(%%)**(%style="color: rgb(0,0,0);text-decoration:none;"%)clone(%%)**(%style="color:rgb(0,0,0);text-decoration:none;"%)' createsashallowcopyofthelist(i.e.liststhatarecontained aselementsthe listarenotcopied,only the referencetothem)810 +If you look up a property that does not exist, there will be an error, and the result will be null. To test whether a property exists, you can append a question mark "?" to the lookup, which yields true or false: 793 793 794 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[1, 6, 8].clone{{/code}} Γƒ╣ {{code}}[1, 6, 8]{{/code}} 812 +* {{code language="xml"}}$list.{5}{{/code}}⟹ The fifth element of a list - however, if $list has less than 5 elements (and if it's also not a table with the key 5), there will be an error 813 +* {{code language="xml"}}$list.{5}?{{/code}}⟹ true if $list exists and has the property 5, false otherwise 814 +* {{code language="xml"}}$table.$key?{{/code}}⟹ Analogously, true if $table exists and has the string property '$key' 795 795 796 - (%style="color:rgb(0,0,0);text-decoration:none;"%)A tablehas differentproperties:816 +The question mark can even be applied to variables: 797 797 798 -* (%style="color: rgb(0,0,0);text-decoration:none;"%)'**clone'**createsashallowcopyof thetable799 -* (% style="color: rgb(0,0,0);text-decoration: none;"%)'**keys'** allowsyouto accessdata aboutthetable'skeys818 +* {{code language="xml"}}$list{{/code}}⟹ The value stored under the name $list, or an error if there is no such variable 819 +* {{code language="xml"}}$list?{{/code}}⟹ true if the variable exists, false otherwise 800 800 801 - (%style="color:rgb(0,0,0);text-decoration:none;" %)However, 'keys'alonewillnotgive you aresult. 'keys' must befollowed by anotherkeywordto retrievethedesired information, for example:821 +To look up the value of a property although it may not exist, you can use the at-sign "@" as prefix: 802 802 823 +* {{code language="xml"}}@$list.{5}{{/code}}⟹ The result of the $list lookup if $list exists and has the property 5, otherwise null (without error message) 824 +* {{code language="xml"}}@$list{{/code}}⟹ The list if this variable exists, null otherwise 825 +* {{code language="xml"}}@$list.{5}.{1}{{/code}}⟹ The first element of the fifth element of $list, if it exists, null otherwise 803 803 804 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$table.keys.list{{/code}}: Yields a list of all keys in the table (reliably sorted by key if all keys are numeric) 805 -\\ 806 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$table.keys.sorted{{/code}}: Yields a list of all keys in the table, sorted by their associated values (which requires that all values are numeric) 807 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$table.keys.random{{/code}}: A randomly chosen key (which requires that the table is non-empty) 827 +As you can see, an error is already prevented if any link in the property chain does not exist. But use the @ prefix with care, since error messages are really helpful for detecting problems in your scripts. The @ prefix only suppresses property-related error messages and does not change any in-game behaviour. 808 808 829 +=== Static lookups === 809 809 831 +There are a few data types which are basically enumerations: They only consist of a set of named values, e.g. the "class" data type, which is used for the component classes that exist in the game. For all these static enumeration classes there is a lookup value of the same name, from which you can get the named values as properties by their name. So for the type "class", there is a value "class" that can be used to access the classes. 810 810 811 - {{notebody="<span style=~"color: rgb(0,0,0);text-decoration:none;~">Thestring formatting syntax that you have seen[[NULL|above]] is also based on the property system. You basically passa list as property key to astring.Braces aroundthe brackets are notrequired,so'foo'.[...] is just a convenientalternativenotation for 'foo'.{[...]}.</span>"/}}833 +Here are a few enumeration classes and corresponding example lookup values: 812 812 813 - 814 - 815 -(% id="lookup-tests-and-suppressing-errors" %)(%%) 816 -~=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Lookup tests and suppressing errors 817 -\\(%%) === 818 - 819 -(% style="color: rgb(0,0,0);text-decoration: none;" %)If you look up a property that does not exist, there will be an error, and the result will be null. To test whether a property exists, you can append a question mark ΓÇ£?ΓÇ¥ to the lookup, which yields true or false: 820 - 821 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$list.{5}{{/code}} Γƒ╣ The fifth element of a list - however, if $list has less than 5 elements (and if it's also not a table with the key 5), there will be an error 822 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$list.{5}?{{/code}} Γƒ╣ true if $list exists and has the property 5, false otherwise 823 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$table.$key?{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣ Analogously, (%%)true if $table exists and has the string property '$key' 824 - 825 - 826 -(% style="color: rgb(0,0,0);text-decoration: none;" %)The question mark can even be applied to variables: 827 - 828 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$list{{/code}} Γƒ╣ The value stored under the name $list, or an error if there is no such variable 829 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$list?{{/code}} Γƒ╣ true if the variable exists, false otherwise 830 - 831 -(% style="color: rgb(0,0,0);text-decoration: none;" %)To look up the value of a property although it may not exist, you can use the at-sign ΓÇ£@ΓÇ¥ as prefix: 832 - 833 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}@$list.{5}{{/code}} Γƒ╣ The result of the $list lookup if $list exists and has the property 5, otherwise null (without error message) 834 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}@$list{{/code}} Γƒ╣ The list if this variable exists, null otherwise 835 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}@$list.{5}.{1}{{/code}} Γƒ╣ The first element of the fifth element of $list, if it exists, null otherwise 836 - 837 -(% style="color: rgb(0,0,0);text-decoration: none;" %)As you can see, an error is already prevented if any link in the property chain does not exist. But use the @ prefix with care, since error messages are really helpful for detecting problems in your scripts. The @ prefix only suppresses property-related error messages and does not change any in-game behaviour. 838 - 839 -\\ 840 - 841 -(% id="static-lookups" %) 842 - 843 -=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Static lookups(%%) === 844 - 845 -(% style="color: rgb(0,0,0);text-decoration: none;" %)There are a few data types which are basically enumerations: They only consist of a set of named values, e.g. the ΓÇ£classΓÇ¥ data type, which is used for the component classes that exist in the game. For all these static enumeration classes there is a lookup value of the same name, from which you can get the named values as properties by their name. So for the type ΓÇ£classΓÇ¥, there is a value ΓÇ£classΓÇ¥ that can be used to access the classes. 846 - 847 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Here are a few enumeration classes and corresponding example lookup values: 848 - 849 849 (% style="margin-left: 0.0px;" %) 850 850 ((( 851 -\\ 852 - 853 - 854 - 855 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Data type (= value name)|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Examples|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Description 856 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)class| 857 -(% style="color: rgb(0,0,0);text-decoration: none;" %)class.ship(%%) 858 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)class.ship_xl(%%) 859 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)class.space(%%) 860 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)class.weapon|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Component classes 861 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)purpose| 862 -(% style="color: rgb(0,0,0);text-decoration: none;" %)purpose.combat(%%) 863 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)purpose.transportation|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Purposes 864 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)killmethod| 865 -(% style="color: rgb(0,0,0);text-decoration: none;" %)killmethod.hitbybullet(%%) 866 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)killmethod.hitbymissile|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Ways to die (already used before destruction) 867 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)datatype| 868 -(% style="color: rgb(0,0,0);text-decoration: none;" %)datatype.float(%%) 869 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)datatype.component(%%) 870 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)datatype.class(%%) 871 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)datatype.datatype|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Script value datatypes 872 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)profile| 873 -(% style="color: rgb(0,0,0);text-decoration: none;" %)profile.flat(%%) 874 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)profile.increasing(%%) 875 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)profile.bell|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Probability distribution profile (see [[random ranges>>MediaWiki.NULL]]) 876 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)cuestate| 877 -(% style="color: rgb(0,0,0);text-decoration: none;" %)cuestate.waiting(%%) 878 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)cuestate.active(%%) 879 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)cuestate.complete|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)[[Cue states>>MediaWiki.NULL]] 880 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)level| 881 -(% style="color: rgb(0,0,0);text-decoration: none;" %)level.easy(%%) 882 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)level.medium(%%) 883 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)level.veryhard|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Mission difficulty levels (comparable with each other using lt, gt, etc.) 884 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)attention| 885 -(% style="color: rgb(0,0,0);text-decoration: none;" %)attention.insector(%%) 886 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)attention.visible(%%) 887 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)attention.adjacentzone|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Attention levels (comparable with each other using lt, gt, etc.) 888 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)ware| 889 -(% style="color: rgb(0,0,0);text-decoration: none;" %)ware.ore(%%) 890 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)ware.silicon|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Wares 891 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)race| 892 -(% style="color: rgb(0,0,0);text-decoration: none;" %)race.argon(%%) 893 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)race.boron|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Races 894 -|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)faction| 895 -(% style="color: rgb(0,0,0);text-decoration: none;" %)faction.player(%%) 896 -\\(% style="color: rgb(0,0,0);text-decoration: none;" %)faction.argongovernment|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Factions 837 +|Data type (= value name)|Examples|Description 838 +|class| 839 +class.ship 840 +\\class.ship_xl 841 +\\class.space 842 +\\class.weapon|Component classes 843 +|purpose| 844 +purpose.combat 845 +\\purpose.transportation|Purposes 846 +|killmethod| 847 +killmethod.hitbybullet 848 +\\killmethod.hitbymissile|Ways to die (already used before destruction) 849 +|datatype| 850 +datatype.float 851 +\\datatype.component 852 +\\datatype.class 853 +\\datatype.datatype|Script value datatypes 854 +|profile| 855 +profile.flat 856 +\\profile.increasing 857 +\\profile.bell|Probability distribution profile (see [[random ranges>>doc:||anchor="HRandomranges" style="outline-width: 0px !important; user-select: auto !important;"]]) 858 +|cuestate| 859 +cuestate.waiting 860 +\\cuestate.active 861 +\\cuestate.complete|[[Cue states>>||anchor="HCues" style="outline-width: 0px !important; user-select: auto !important;"]] 862 +|level| 863 +level.easy 864 +\\level.medium 865 +\\level.veryhard|Mission difficulty levels (comparable with each other using lt, gt, etc.) 866 +|attention| 867 +attention.insector 868 +\\attention.visible 869 +\\attention.adjacentzone|Attention levels (comparable with each other using lt, gt, etc.) 870 +|ware| 871 +ware.ore 872 +\\ware.silicon|Wares 873 +|race| 874 +race.argon 875 +\\race.boron|Races 876 +|faction| 877 +faction.player 878 +\\faction.argongovernment|Factions 897 897 ))) 898 898 899 -{{ note body="[[Category:Broken_macro/anchor]]With the ''typeof'' operator you can get thedatatypeof any expressionand compareitwith whatyou expect, for example:881 +{{id name="typeof"/}} 900 900 883 +{{info}} 884 +With the ''typeof'' operator you can get the datatype of any expression and compare it with what you expect, for example: 885 + 901 901 <code>typeof $value == datatype.faction</code> 902 902 903 -However, you should not compare the type to datatype.string because there are strings that have different data types. To check for a string you should use the datatype's property "'''isstring'''"instead. For example, to check if the variable $value is a string, use the following term:888 +However, you should not compare the type to datatype.string because there are strings that have different data types. To check for a string you should use the datatype's property "'''isstring'''" instead. For example, to check if the variable $value is a string, use the following term: 904 904 905 -<code>(typeof $value).isstring</code>"/}} 890 +<code>(typeof $value).isstring</code>" 891 +{{/info}} 906 906 907 -{{info body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">There is also the datatype ΓÇ£tagΓÇ¥ with the lookup name ΓÇ£tagΓÇ¥ - however, this is not an enumeration type. Looking up a value by name never fails, you actually create a tag value for a given name if it does not exist. For example, if you have a typo, like ΓÇ£tag.misionΓÇ¥ instead of ΓÇ£tag.missionΓÇ¥, there wonΓÇÖt be an error because any name is valid for a tag, and the tag ΓÇ£misionΓÇ¥ is created on its first use.</span>"/}} 893 +{{info}} 894 +There is also the datatype "tag" with the lookup name "tag" - however, this is not an enumeration type. Looking up a value by name never fails, you actually create a tag value for a given name if it does not exist. For example, if you have a typo, like "tag.mision" instead of "tag.mission", there won't be an error because any name is valid for a tag, and the tag "mision" is created on its first use." 895 +{{/info}} 908 908 909 - (%style="color:rgb(0,0,0);text-decoration: none;"%)897 +=== Player properties === 910 910 899 +You can access many player-related game properties via the keyword "player": 911 911 912 -(% id="player-properties" %) 901 +* player.**name**: The player's name 902 +* player.**age**: The passed in-game time since game start 903 +* player.**money**: The money in the player's account 904 +* player.**ship**: The ship the player is currently on (not necessarily the player's ship), or null if the player is on a station 913 913 914 -=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Player properties(%%) === 906 +* player.**primaryship**: The player's own ship (but the player is not necessarily on board) 907 +* player.**entity**: The actual player object 915 915 916 -(% style="color: rgb(0,0,0);text-decoration: none;" %)You can access many player-related game properties via the keyword ΓÇ£playerΓÇ¥: 909 +* player.**zone**, player.**sector**, player.**cluster**, player.**galaxy**: Location of the player entity 910 +* player.**copilot**: The co-pilot NPC 917 917 918 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)player.(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)name(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): The playerΓÇÖs name 919 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)player.(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)age(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): The passed in-game time since game start 920 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)player.(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)money(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): The money in the playerΓÇÖs account 921 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)player.(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)ship(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): The ship the player is currently on (not necessarily the player's ship), or null if the player is on a station 922 -\\ 923 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)player.**primaryship**: The player's own ship (but the player is not necessarily on board) 924 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)player.**entity**: The actual player object 925 -\\ 926 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)player.(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)zone(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %), player.(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)sector(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %), player.(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)cluster(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %), player.(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)galaxy(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): Location of the player entity 927 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)player.(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)copilot(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): The co-pilot NPC 928 - 929 929 The game consists of objects of different classes (zones, ships, stations, NPCs). They have the common datatype "component", however, they have different properties, e.g. NPCs have the property "race", but ships don't. 930 930 931 - (% id="safe-properties"%)914 +=== Safe properties === 932 932 933 - === (%style="color:rgb(0,0,0);text-decoration:none;"%)Safeproperties(%%) ===916 +Most properties cause errors if you use them on non-existing objects, such as destroyed ships. There are a few exceptions: 934 934 935 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Most properties cause errors if you use them on non-existing objects, such as destroyed ships. There are a few exceptions: 918 +* exists 919 +* isoperational 920 +* iswreck 921 +* isconstruction 922 +* available 923 +* isclass.(...) 936 936 937 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)exists 938 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)isoperational 939 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)iswreck 940 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)isconstruction 941 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)available 942 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)isclass.(...) 925 +These properties will not cause errors when used on "null" or on a destroyed object (which may still be accessible from scripts in some cases), and produce null or false as results, respectively. (The keyword "available" is used for trades, not for objects. Trades can also become invalid.) However, when using such a property on a different data type like a number, there will still be an error. 943 943 944 -(% style="color: rgb(0,0,0);text-decoration: none;" %)These properties willnot cause errors whenusedon ΓÇ£nullΓÇ¥ ora destroyedobject(whichmay still beaccessiblefrom scripts in some cases), and produce null or false as results, respectively. (The keyword ΓÇ£availableΓÇ¥ is used for trades,notfor objects. Trades can also become invalid.)However, whenusing such a propertyonadifferentdatatype like a number,there will still be anerror.927 +=== (% id="categorybroken_macroanchormoney-and-time-formatting" %)Money and time formatting(%%) === 945 945 946 -(% id="categorybroken_macroanchormoney-and-time-formatting" %)(%%) 947 -~=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Money and time formatting 948 -\\(%%) === 929 +**[New as of X Rebirth 4.0]** 930 +\\Numbers don't have any properties, except for money and time: They have a "**formatted**" property, which allows you to get a custom string representation with more advanced options than the [[generic formatting method>>||anchor="HStringsandformatting" style="outline-width: 0px !important; user-select: auto !important;"]] for numbers. 949 949 950 -(% style="color: rgb(0,0,0);text-decoration: none;" %)**[New as of X Rebirth 4.0]** 932 +* {{code language="xml"}}$money.formatted.{'formatstring'}{{/code}} 933 +* {{code language="xml"}}$money.formatted.default{{/code}}(using default format string '%s') 951 951 952 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Numbers don't have any properties, except for money and time: They have a "**formatted**" property, which allows you to get a custom string representation with more advanced options than the [[generic formatting method>>MediaWiki.NULL]] for numbers. 935 +* {{code language="xml"}}$time.formatted.{'formatstring'}{{/code}} 936 +* {{code language="xml"}}$time.formatted.default{{/code}}(using default format string '%T') 953 953 954 -* {{code}}$money.formatted.{'formatstring'}┬á{{/code}} 955 -* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$money.formatted.default{{/code}} (using default format string '%s') 956 -\\ 957 -* {{code}}$time.formatted.{'formatstring'}{{/code}} 958 -* {{code}}$time.formatted.default{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á(%%) (using default format string '%T') 938 +In scripts, money is stored in cents, not Credits. The formatted representation always shows the value in Credits, including thousands separators. 959 959 960 - (% style="color:rgb(0,0,0);text-decoration:none;"%)In scripts, moneyis storedin cents,notCredits. The formattedrepresentation alwaysshows thevalueinCredits,includingthousandsseparators.940 +When formatting the money value, any specifier (such as '%s') in the format string is replaced by the money value, so usually the format string only consists of this one specifier. The following modifiers can be used between '%' and the specifier character, to enable formatting options: 961 961 962 -(% style="color: rgb(0,0,0);text-decoration: none;" %)When formatting the money value, any specifier (such as '%s') in the format string is replaced by the money value, so usually the format string only consists of this one specifier. The following modifiers can be used between '%' and the specifier character, to enable formatting options: 963 - 964 - 965 965 |1-9|Truncation|To enable truncation, specify the number of relevant digits that should be displayed. If the money string is too long, it can be truncated and a metric unit prefix (e.g. k = kilo) is appended. (All digits are shown unless truncation is enabled.) 966 966 |c|Colouring|If truncation is enabled, the metric unit prefixes (e.g. k, M, G) can be coloured when displayed on the screen, using the escape sequence '\033C'. 967 967 |.|Cents|Usually money values have no cent part, since cents are not used in accounts or trades. However, single ware prices can have a non-zero cent part. (Cents are not displayed if money is truncated) 968 968 |_|Spaces|An underscore adds trailing spaces to the result string for better right-aligned display in a tabular layout. 969 969 970 - (% style="color: rgb(0,0,0);text-decoration: none;" %)By default, these options are disabled.947 +By default, these options are disabled. 971 971 972 - (% style="color: rgb(0,0,0);text-decoration: none;" %)More available specifiers (in addition to %s):949 +More available specifiers (in addition to %s): 973 973 974 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)%k: Credits (truncated) in kilo format 975 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)%M: Credits (truncated) in Mega format 976 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)%G: Credits (truncated) in Giga format 977 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)%T: Credits (truncated) in Tera format 978 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)%Cr: Localised "Cr" string 979 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)%%: A % sign 980 -\\ 951 +* %k: Credits (truncated) in kilo format 952 +* %M: Credits (truncated) in Mega format 953 +* %G: Credits (truncated) in Giga format 954 +* %T: Credits (truncated) in Tera format 955 +* %Cr: Localised "Cr" string 956 +* %%: A % sign 981 981 982 - (% style="color: rgb(0,0,0);text-decoration: none;" %)Examples:958 +Examples: 983 983 960 +* {{code language="xml"}}(1234Cr).formatted.{'%s'}{{/code}}⟹{{code language="xml"}}'1,234'{{/code}} 961 +* {{code language="xml"}}(1234Cr).formatted.default{{/code}}⟹{{code language="xml"}}'1,234'{{/code}} (same as {'%s'}) 962 +* {{code language="xml"}}(1234Cr).formatted.{'%.s %Cr'}{{/code}}⟹{{code language="xml"}}'1,234.00 Cr'{{/code}} 963 +* {{code language="xml"}}(1234Cr).formatted.{'%1s'}{{/code}}⟹{{code language="xml"}}'1 k'{{/code}} (rounding towards zero) 964 +* {{code language="xml"}}(1234Cr).formatted.{'%cM'}{{/code}}⟹{{code language="xml"}}'0 M'{{/code}} 984 984 985 -* {{code}}(1234Cr).formatted.{'%s'}{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣{{code}}'1,234'{{/code}} 986 -* {{code}}(1234Cr).formatted.default{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣{{code}}'1,234'{{/code}}(%%) (same as {'%s'}) 987 -* {{code}}(1234Cr).formatted.{'%.s %Cr'}{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣{{code}}'1,234.00 Cr'{{/code}} 988 -* {{code}}(1234Cr).formatted.{'%1s'}{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣{{code}}'1 k'{{/code}}(%%) (rounding towards zero) 989 -* {{code}}(1234Cr).formatted.{'%cM'}{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣{{code}}'0 M'{{/code}} 966 +For documentation of time format strings, see the Lua function ConvertTimeString() in the [[Lua function overview>>doc:X Rebirth Wiki.Modding support.UI Modding support.Lua function overview.WebHome||style="outline-width: 0px !important; user-select: auto !important;"]]. 990 990 991 -For documentation of time format strings, see the Lua function ConvertTimeString() in the [[MediaWiki.ARCHIVE.XRWIKIModding_supportUI_Modding_supportLua_function_overview]]. 992 - 993 993 Examples: 994 994 995 -* {{code}}(151s).formatted.{'%T'}{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;"%)Γƒ╣(%%) {{code}}'00:02:31'{{/code}}996 -* {{code}}(151s).formatted.default{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;"%)Γƒ╣(%%) {{code}}'00:02:31'{{/code}} (same as {'%T'})997 -* {{code}}(151s).formatted.{'%.3T'}{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;"%)Γƒ╣(%%) {{code}}'00:02:31.000'{{/code}}998 -* {{code}}(151s).formatted.{'%h:%M'}{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;"%)Γƒ╣(%%) {{code}}'0:02'{{/code}}970 +* {{code language="xml"}}(151s).formatted.{'%T'}{{/code}}⟹ {{code language="xml"}}'00:02:31'{{/code}} 971 +* {{code language="xml"}}(151s).formatted.default{{/code}}⟹ {{code language="xml"}}'00:02:31'{{/code}} (same as {'%T'}) 972 +* {{code language="xml"}}(151s).formatted.{'%.3T'}{{/code}}⟹ {{code language="xml"}}'00:02:31.000'{{/code}} 973 +* {{code language="xml"}}(151s).formatted.{'%h:%M'}{{/code}}⟹ {{code language="xml"}}'0:02'{{/code}} 999 999 1000 - (% id="complete-property-documentation"%)975 +=== Complete property documentation === 1001 1001 1002 - ===(%style="color:b(0,0,0);text-decoration:none;"%)Completepropertydocumentation(%%)===977 +To access the script property documentation that is included in the game, you can extract the required files from the game's catalog files using the [[X Catalog Tool>>url:https://forum.egosoft.com/viewtopic.php?t=363625]]. Extract the HTML file __scriptproperties.html__ in the game's root folder, and all files in the "libraries" sub-folder. For resolving text references in the browser automatically, also extract 0001-L044.xml in the "t" sub-folder. 1003 1003 1004 - (% style="color: rgb(0,0,0);text-decoration: none;" %)To access thescriptpropertydocumentationthat isincluded in the game, youcan extract therequiredfiles from the game's catalog files usingthe [[X Catalog Tool>>url:https://forum.egosoft.com/viewtopic.php?t=363625]]. Extract the HTML file__scriptproperties.html__inthegame's root folder, andall filesinthe "libraries" sub-folder.For resolvingtext referencesnthe browserautomatically, alsoextract 0001-L044.xml inthe"t" sub-folder.979 +The raw documentation data is located in libraries/scriptproperties.xml, but it is recommended to open scriptproperties.html in a browser. 1005 1005 1006 -(% style="color: rgb(0,0,0);text-decoration: none;" %)The raw documentation data is located in libraries/scriptproperties.xml, but it is recommended to open scriptproperties.html in a browser. 981 +{{info}} 982 +scriptproperties.html has to load files from different folders, which modern browsers do not allow by default for security reasons. In order to open scriptproperties.html, the following is required: 1007 1007 984 +* Firefox: On the about:config page, the value of "security.fileuri.strict_origin_policy" has to be changed to "false". 985 +* Chrome: The Chrome launcher has to be started with the command-line parameter --~-~---allow-file-access-from-files 986 +{{/info}} 1008 1008 1009 - {{notebody="scriptproperties.htmlhasoloadfilesfrom differentfolders,which modernbrowsersdonot allow by defaultfor securityreasons.Inordertoopenscriptproperties.html,the following is required:988 +This provides you with a complete list of all supported "base keywords" and properties. To filter in this list, you can enter an expression in the text field: 1010 1010 1011 -* Firefox: On the about:config page, the value of "security.fileuri.strict_origin_policy" has to be changed to "false". 1012 -* Chrome: The Chrome launcher has to be started with the command-line parameter --allow-file-access-from-files"/}} 990 +* Enter the beginning of a base keyword 991 +* Enter $ followed by the data type you are looking for (e.g. "$ship"), as if it were a variable 992 +* To see the properties of a base keyword or data type, enter a dot (".") 993 +* After the dot, you can enter a property name 994 +* You can also enter a dot (".") as first character to search globally for a property 1013 1013 996 +{{info}} 997 +The documentation contains some data types that are no real script data types, but which are useful for documentation purposes. For example, ships and stations are both of datatype "component", but have different properties based on their component class. 998 +{{/info}} 1014 1014 1000 += MD refreshing and patching = 1015 1015 1016 - (%style="color:rgb(0,0,0);text-decoration:none;"%)Thisprovidesyouwith acompletelistofall supportedΓÇ£basekeywordsΓÇ¥andproperties.Tofilterinthislist,youcanteranexpressioninthetextfield:1002 +When a saved game is loaded, the saved MD state is restored, but also all MD files are reloaded and changes in them are applied to the MD state. This is called "refresh". It is also possible to refresh the MD at run-time using the command "refreshmd" on the in-game command line. This is a convenient way to update MD scripts while the game is already running. 1017 1017 1018 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Enter the beginning of a base keyword 1019 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Enter $ followed by the data type you are looking for (e.g. ΓÇ£$shipΓÇ¥), as if it were a variable 1020 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)To see the properties of a base keyword or data type, enter a dot (ΓÇ£.ΓÇ¥) 1021 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)After the dot, you can enter a property name 1022 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)You can also enter a dot (ΓÇ£.ΓÇ¥) as first character to search globally for a property 1004 +== Details and restrictions == 1023 1023 1024 - (%style="color:rgb(0,0,0);text-decoration:none;"%)1006 +Here are some noteworthy facts about refreshing scripts and cues, and the restrictions: 1025 1025 1008 +* MD scripts and cues are identified by their names. So a script can only be refreshed if it has the same script name as before (file name is irrelevant). 1009 +* If there are new script files or new cue nodes (i.e. scripts/cues with new names) they are created and added properly. If you remove script files or cue nodes, the corresponding scripts/cues are removed from the game, including instances. 1010 +** (!) Pitfall: For savegame compatibility, released cues should not be removed, but instead emptied out and marked as deprecated, to prevent future cues with the same name leading to errors (see example below). 1011 +* As a consequence, you CANNOT rename scripts or cues if you want to refresh them. Doing so would remove the old script or cue and add a new one with the new name. 1012 +* You CANNOT change a <cue> to a <library> or vice versa. 1013 +* You CANNOT add, remove, or change the "ref" attribute of a cue. But it is possible to remove the whole cue. (If all references to a library are removed you can also remove the library itself.) 1014 +* You CANNOT change the cue tree structure, i.e. if you move a cue out of its <cues> node, you also have to change its name (see above). Changing the order of cues within the same <cues> node is possible, however, the order of execution is not reliable anyway. 1015 +* You CAN change a library and change/add/remove its sub-cues. This automatically updates all cues that use the library. 1016 +* You CAN change library parameters (both in libraries and in referencing cues). However, this does not change the variables of a referencing cue if it is already enabled. 1017 +* You CAN change conditions without restrictions. You can even change between event and non-event conditions. If a cue has enabled condition checks, they are aborted and restarted (even if there is no change). 1018 +* Adding root cues enables their condition checks immediately (if the module attribute allows it). 1019 +* Adding sub-cues to active or complete cues enables their condition checks immediately. 1020 +* You CAN change/add/remove <actions>, <force>, <delay>, and all attributes without restrictions, except for the "ref" attribute (see above). You can even change the <delay> while the cue is already active and the timer is running. 1021 +* Changing instantiate="false" to "true" turns the cue into "waiting" state if it was active or complete before. 1022 +* Changing instantiate="true" to "false" removes all instantiated cues and their descendants. 1026 1026 1027 -{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">The documentation contains some data types that are no real script data types, but which are useful for documentation purposes. For example, ships and stations are both of datatype ΓÇ£componentΓÇ¥, but have different properties based on their component class.</span>"/}} 1024 +{{warning}} 1025 +Be aware that completed instances can be auto-deleted, and so added sub-cues will not become active in such a case. 1026 +{{/warning}} 1028 1028 1028 +{{warning}} 1029 +When adding a variable in a new MD script version and using that variable in multiple places, be aware that the variable doesn't exist yet in older savegames. You may have to check the existence of the variable before accessing it, or add some patch logic that initiailses the variable after loading the savegame, if necessary. 1030 +{{/warning}} 1029 1029 1032 +{{warning}} 1033 +(% id="cke_bm_221021S" style="display:none" %) (%%)Cue Removal Pitfall: 1034 +If you remove a cue and then later add another cue with the same name, old save files will not know that the cue has been removed inbetween. In the following example the first cue was created setting $val_1 and the game is saved. 1035 +{{code language="xml"}}<cue name="Deprecated_Test1"> 1036 + <actions> 1037 + <set_value name="$val_1" exact="'old value'"/> 1038 + <debug_text text="$val_1"/> 1039 + </actions> 1040 +</cue>{{/code}} 1041 +\\If the Cue is deleted and years later a new cue with the same name appears, the old save will consider the new cue as already completed without executing its actions. The Cue PrintValue will fail to find a variable set up in its parent. 1042 +{{code language="xml"}}<cue name="Deprecated_Test1"> 1043 + <actions> 1044 + <set_value name="$val_2" exact="'new value'"/> 1045 + <debug_text text="$val_2"/> 1046 + </actions> 1047 + <cues> 1048 + <cue name="PrintValue"> 1049 + <actions> 1050 + <debug_text text="$val_2"/> 1051 + </actions> 1052 + </cue> 1053 + </cues> 1054 +</cue>{{/code}} 1055 +\\To avoid this, do not delete any cues (once they are public for save game compatibility), but empty them out and mark them as deprecated. This will prevent new cues with the same name in the script. 1056 +{{code language="xml"}}<!-- Deprecated Cues, kept to not duplicate names in future cues --> 1057 +<cue name="Deprecated_Test1" comment="deprecated"></cue>{{/code}} 1058 +{{/warning}} 1030 1030 1031 - \\1060 +== Patching == 1032 1032 1033 - (%id="md-refreshing-and-patching"%)1062 +Cues can have **<patch>** elements with actions that will be performed when an old savegame is loaded. To control which savegames should be affected, you can add a //**version **//attribute to the <cue> node and a //**sinceversion**// attribute in the patch. When a cue is loaded from a savegame that has an older version than //sinceversion//, the <patch> actions will be performed immediately after loading. 1034 1034 1035 -= (% style="color: rgb(0,0,0);text-decoration: none;" %)MD refreshing and patching(%%) = 1064 +{{code language="xml"}} 1065 + <cue [...] version="42"> 1066 + <conditions> [...] </conditions> 1067 + <actions> [...] </actions> 1068 + <patch sinceversion="42"> 1069 + [patch actions] 1070 + </patch> 1071 + </cue> 1072 +{{/code}} 1036 1036 1037 - (% style="color:rgb(0,0,0);text-decoration:none;"%)Whena saved game isloaded,thesavedMDstateisrestored,but alsoall MD files arereloadedandchangesinthemare appliedtothe MD state.Thisis called ΓÇ£refreshΓÇ¥.It is alsopossible torefreshthe MDat run-time using thecommandΓÇ£refreshmdΓÇ¥on the in-gamecommand line. This is a convenientwaytoupdateMD scripts while thegameis already running.1074 +The patch actions are only performed if the cue is in a certain state, "complete" by default. Use the //**state**// attribute to change this requirement. For more information, see the XML schema documentation of the <patch> element. 1038 1038 1039 - \\1076 +A sequence of multiple <patch> elements is possible. They will be performed in order of appearance, checking the //sinceversion// and //state// attributes in each case. Patches are also applied to all users of a library and to instances. 1040 1040 1041 -(% id="details-and-restrictions" %) 1078 +{{info}} 1079 +The <patch> elements will be ignored when refreshing the MD at run-time. They only affect loaded savegames." 1080 +{{/info}} 1042 1042 1043 -= =(% style="color:rgb(0,0,0);text-decoration: none;"%)Details andrestrictions(%%)==1082 += Common attribute groups = 1044 1044 1045 - (%style="color:rgb(0,0,0);text-decoration:none;"%)Herearesomenoteworthyfactsaboutrefreshingscriptsandcues,andthestrictions:1084 +There are many commonly used actions and conditions which share groups of attributes. The most important ones are explained here. 1046 1046 1047 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)MD scripts and cues are identified by their names. So a script can only be refreshed if it has the same script name as before (file name is irrelevant). 1048 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)If there are new script files or new cue nodes (i.e. scripts/cues with new names) they are created and added properly. If you remove script files or cue nodes, the corresponding scripts/cues are removed from the game, including instances. 1049 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)As a consequence, you CANNOT rename scripts or cues if you want to refresh them. Doing so would remove the old script or cue and add a new one with the new name. 1050 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)You CANNOT change a <cue> to a <library> or vice versa. 1051 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)You CANNOT add, remove, or change the "ref" attribute of a cue. But it is possible to remove the whole cue. (If all references to a library are removed you can also remove the library itself.) 1052 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)You CANNOT change the cue tree structure, i.e. if you move a cue out of its <cues> node, you also have to change its name (see above). Changing the order of cues within the same <cues> node is possible, however, the order of execution is not reliable anyway. 1053 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)You CAN change a library and change/add/remove its sub-cues. This automatically updates all cues that use the library. 1054 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)You CAN change library parameters (both in libraries and in referencing cues). However, this does not change the variables of a referencing cue if it is already enabled. 1055 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)You CAN change conditions without restrictions. You can even change between event and non-event conditions. If a cue has enabled condition checks, they are aborted and restarted (even if there is no change). 1056 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Adding root cues enables their condition checks immediately (if the module attribute allows it). 1057 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Adding sub-cues to active or complete cues enables their condition checks immediately. 1058 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)You CAN change/add/remove <actions>, <force>, <delay>, and all attributes without restrictions, except for the "ref" attribute (see above). You can even change the <delay> while the cue is already active and the timer is running. 1059 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Changing instantiate="false" to "true" turns the cue into "waiting" state if it was active or complete before. 1060 -* (% style="color: rgb(0,0,0);text-decoration: none;" %)Changing instantiate="true" to "false" removes all instantiated cues and their descendants. 1086 +== Value comparisons == 1061 1061 1062 - (%style="color:rgb(0,0,0);text-decoration:none;" %)1088 +There are many conditions and conditional actions that require a value comparison, for example the condition <check_value>: 1063 1063 1090 +{{code language="xml"}} 1091 + <check_value value="$ware == ware.silicon and $amount != 0"/> 1092 +{{/code}} 1064 1064 1065 - {{warningbody="<spanstyle=~"color:rgb(0,0,0);text-decoration:none;~">Beaware thatcompletedinstancescanbe auto-deleted,and so addedsub-cueswillnotbecomeactive insuchacase.</span>"/}}1094 +In the value attribute you specify a boolean expression, and if it is true (that is, not equal to zero), the condition is met. This is a special case: This condition and all other nodes that support a value comparison allows you to specify an upper limit, a lower limit, a number range, or a list of allowed values. Examples: 1066 1066 1067 -{{warning body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">When adding a variable in a new MD script version and using that variable in multiple places, be aware that the variable doesn't exist yet in older savegames. You may have to check the existence of the variable before accessing it, or add some patch logic that initiailses the variable after loading the savegame, if necessary.</span>"/}} 1096 +{{code language="xml"}} 1097 + <check_value value="FooCue.state" exact="cuestate.complete"/> 1098 + <check_value value="$foo.count" min="5"/> 1099 + <check_value value="$foo" max="player.age + 1min"/> 1100 + <check_value value="player.money" min="300Cr" max="600Cr"/> 1101 + <check_value value="$method" list="[killmethod.hitbymissile, killmethod.collected]"/> 1102 + <check_value value="$attention" min="attention.visible"/> 1103 +{{/code}} 1068 1068 1105 +{{info}} 1106 +Values of most enumeration types cannot be compared via ''min'' or ''max'' (also not via lt, gt, etc.). The only data types that can be used with ''min'' and ''max'' are numbers and the enumeration types ''level'' and ''attention'' (see Boolean operators). The ''exact'' attribute can be used with any type, and is equivalent to using the == operator." 1107 +{{/info}} 1069 1069 1109 +== Random ranges == 1070 1070 1071 - \\1111 +If an action requires a value, e.g. when you set a variable to a value, you can have some randomisation. To specify an exact value, e.g. in <set_value>, you can write this: 1072 1072 1073 -(% id="patching" %) 1113 +{{code language="xml"}} 1114 + <set_value name="$race" exact="race.teladi"/> 1115 +{{/code}} 1074 1074 1075 - ==(%style="color:rgb(0,0,0);text-decoration:none;"%)Patching(%%)==1117 +To select a random element from a list, this syntax can be used: 1076 1076 1077 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Cues can have **<patch>** elements with actions that will be performed when an old savegame is loaded. To control which savegames should be affected, you can add a (%%)//**(% style="color: rgb(0,0,0);text-decoration: none;" %)version (%%)**//(% style="color: rgb(0,0,0);text-decoration: none;" %)attribute to the <cue> node and a (%%)//**(% style="color: rgb(0,0,0);text-decoration: none;" %)sinceversion(%%)**//(% style="color: rgb(0,0,0);text-decoration: none;" %) attribute in the patch. When a cue is loaded from a savegame that has an older version than (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)sinceversion//, the <patch> actions will be performed immediately after loading. 1119 +{{code language="xml"}} 1120 + <set_value name="$prime" list="[2, 3, 5, 7, 11]"/> 1121 +{{/code}} 1078 1078 1079 - {{code}}<cue┬á[...]version="42">┬á <conditions>[...] </conditions>┬á<actions>[...] </actions>┬á<patch┬ásinceversion="42">┬á┬á┬á[patchactions]┬á</patch></cue>{{/code}}1123 +To get a random number within a given range, you can use min/max: 1080 1080 1081 -(% style="color: rgb(0,0,0);text-decoration: none;" %)The patch actions are only performed if the cue is in a certain state, ΓÇ£completeΓÇ¥ by default. Use the (%%)//**(% style="color: rgb(0,0,0);text-decoration: none;" %)state(%%)**//(% style="color: rgb(0,0,0);text-decoration: none;" %) attribute to change this requirement. For more information, see the XML schema documentation of the <patch> element. 1125 +{{code language="xml"}} 1126 + <set_value name="$foo" min="-20" max="20"/> 1127 + <set_value name="$timeout" max="20s"/> 1128 +{{/code}} 1082 1082 1083 - (%style="color:rgb(0,0,0);text-decoration:none;"%)A sequenceofmultiple <patch> elementsis possible.They willbe performedinorderfappearance,checkingthe(%%)//(% style="color: rgb(0,0,0);text-decoration:none;"%)sinceversion//and(%%)//(% style="color: rgb(0,0,0);text-decoration:none;"%)state//attributes ineachcase.Patchesare alsoappliedtoallusersofalibraryandtoinstances.1130 +min and max have to be compatible number types. Enumeration types are not allowed, not even level and attention. The min attribute is optional and defaults to 0 (of the number type used in max). 1084 1084 1085 - {{notebody="<span style=~"color:rgb(0,0,0);text-decoration:none;~">The<patch>elementswillbe ignoredwhen refreshing theMDat run-time.Theyonlyaffectloadedsavegames.</span>"/}}1132 +You can select one of 5 different probability distribution profiles for the random range, "flat" being the default (all values in the range are equally likely). If you select another profile, e.g. "increasing" to make higher numbers more likely, you also have to specify a scale value (integer) that is greater or equal to 2. Higher scale values result in higher peaks in the distribution profiles (probable values become even more probable). 1086 1086 1134 +{{code language="xml"}} 1135 + <set_value name="$foo" min="-20" max="20" profile="profile.increasing" scale="4"/> 1136 +{{/code}} 1087 1087 1138 += Variables and namespaces = 1088 1088 1089 - \\1140 +As you have seen above, you can easily access variables by writing their name (including $ prefix) in an expression. Namespaces define in which cue the variables are actually stored (and from which cue they are read). 1090 1090 1091 - (%id="common-attribute-groups"%)1142 +== Creating and removing variables == 1092 1092 1093 - =(%style="color:rgb(0,0,0);text-decoration:none;" %)Common attributegroups(%%) =1144 +You can create variables with certain actions and conditions, such as the <set_value> action: 1094 1094 1095 -(% style="color: rgb(0,0,0);text-decoration: none;" %)There are many commonly used actions and conditions which share groups of attributes. The most important ones are explained here. 1146 +{{code language="xml"}} 1147 + <set_value name="$foo" exact="$bar + 1" /> 1148 +{{/code}} 1096 1096 1097 - \\1150 +<set_value> also exists as a "condition", which can be useful if you want to pass information about the conditions to the actions, that would otherwise be lost - like in a complex <check_any> event condition, where you want to create a variable only if you are in a certain check branch. (Other pseudo-conditions are <remove_value> and <debug_text>.) 1098 1098 1099 - (%id="categorybroken_macroanchorvalue-comparisons"%)1152 +The default operation of <set_value> is "**set**", but there are more: "**add**", "**subtract**", and "**insert**". //add// and //subtract// change the value of an existing variable, which is created as 0 if it didn't exist before. If neither //min//, //max// nor //exact// attribute is provided, an exact value of 1 is assumed. 1100 1100 1101 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Value comparisons(%%) == 1154 +{{code language="xml"}} 1155 + <set_value name="$foo" operation="add" /> 1156 +{{/code}} 1102 1102 1103 - (% style="color:rgb(0,0,0);text-decoration:none;"%)Therearemany conditionsand conditionalactionsthatrequireavaluecomparison,forexamplethecondition<check_value>:1158 +The trick is that <set_value> not only works on variables, but also on list elements and table keys: 1104 1104 1105 -{{code}}<check_value┬ávalue="$ware == ware.silicon and $amount != 0"/>{{/code}} 1160 +{{code language="xml"}} 1161 + <set_value name="$list.{1}" exact="42" /> 1162 + <set_value name="$table.$foo" exact="42" /> 1163 +{{/code}} 1106 1106 1107 - (% style="color:rgb(0,0,0);text-decoration:none;" %)Inthevalue attributeyouspecifyaboolean expression, and if itistrue(thatis, notequaltozero),thecondition is met.Thisisa special case:This conditionand allothernodesthatsupporta valuecomparison allowsyoutospecifyanupperlimit,a lowerlimit, a number range,or a listofallowedvalues.Examples:1165 +The operation //insert// is special, and it only works on lists. It inserts the value at the specified position (note that the position beyond the last element is also valid here): 1108 1108 1109 -{{code}}<check_value┬ávalue="FooCue.state"┬áexact="cuestate.complete"/><check_value┬ávalue="$foo.count"┬ámin="5"/><check_value┬ávalue="$foo"┬ámax="player.age + 1min"/><check_value┬ávalue="player.money"┬ámin="300Cr" max="600Cr"/><check_value┬ávalue="$method"┬álist="[killmethod.hitbymissile, killmethod.collected]"/><check_value┬ávalue="$attention"┬ámin="attention.visible"/>{{/code}} 1167 +{{code language="xml"}} 1168 + <set_value name="$list.{1}" exact="42" operation="insert" /> 1169 +{{/code}} 1110 1110 1111 - {{note body="<spanstyle=~"color: rgb(0,0,0);text-decoration: none;~">Values ofmostenumeration typescannotbecompared via </span>''<span style=~"color: rgb(0,0,0);text-decoration: none;~">min</span>''<spanstyle=~"color:rgb(0,0,0);text-decoration: none;~"> or </span>''<span style=~"color:rgb(0,0,0);text-decoration: none;~">max</span>''<span style=~"color: rgb(0,0,0);text-decoration:none;~"> (also not via lt, gt,etc.). Theonly data typesthat can beused with </span>''<spanstyle=~"color: rgb(0,0,0);text-decoration: none;~">min</span>''<span style=~"color:rgb(0,0,0);text-decoration: none;~">and</span>''<span style=~"color: rgb(0,0,0);text-decoration: none;~">max</span>''<span style=~"color: rgb(0,0,0);text-decoration:none;~">arenumbers and the enumeration types</span>''<span style=~"color: rgb(0,0,0);text-decoration:none;~">level</span>''<span style=~"color:rgb(0,0,0);text-decoration: none;~"> and </span>''<spanstyle=~"color:rgb(0,0,0);text-decoration:none;~">attention</span>''<span style=~"color: rgb(0,0,0);text-decoration: none;~"> (seeBooleanperators).The</span>''<span style=~"color:rgb(0,0,0);text-decoration:none;~">exact</span>''<span style=~"color:rgb(0,0,0);text-decoration: none;~"> attribute can be used with any type, and isequivalent to using the == operator.</span>"/}}1171 +This shifts the positions of all following elements up by one. If min/max/exact are missing, the default value is null for insertions, not 1 like in other cases. 1112 1112 1173 +Appending is easier than that. The following actions are equivalent: 1113 1113 1175 +{{code language="xml"}} 1176 + <set_value name="$list.{$list.count + 1}" exact="42" operation="insert" /> 1177 + <append_to_list name="$list" exact="42" /> 1178 +{{/code}} 1114 1114 1115 - \\1180 +Inserting at a position below 1 or above $list.count + 1 is not possible. 1116 1116 1117 - (% id="categorybroken_macroanchorrandom-ranges"%)1182 +To remove variables or list/table entries, use <remove_value>: 1118 1118 1119 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Random ranges(%%) == 1184 +{{code language="xml"}} 1185 + <remove_value name="$foo" /> 1186 + <remove_value name="$list.{1}" /> 1187 + <remove_value name="$table.$foo" /> 1188 +{{/code}} 1120 1120 1121 - (% style="color: rgb(0,0,0);text-decoration:none;"%)If anactionrequiresavalue,e.g.whenyouseta variabletoa value,you canhavesomerandomisation.Tospecifyan exactvalue,e.g. in<set_value>,you can writethis:1190 +Removing an entry from a list shifts all following elements down by one. If you want to clear an entry without removing it from the list, just use <set_value> instead. 1122 1122 1123 - {{code}}<set_value┬áname="$race"┬áexact="race.teladi"/>{{/code}}1192 +== Accessing remote variables == 1124 1124 1125 - (% style="color:rgb(0,0,0);text-decoration:none;"%)To selectarandomelementfromalist,thissyntaxcanbeused:1194 +You can also read and write variables in other cues by using the variable name as property key: 1126 1126 1127 -{{code}}<set_value┬áname="$prime"┬álist="[2, 3, 5, 7, 11]"/>{{/code}} 1196 +{{code language="xml"}} 1197 + <set_value name="OtherCue.$foo" min="0.0" max="1.0" /> 1198 + <set_value name="md.OtherScript.YetAnotherCue.$bar" exact="OtherCue.$foo" /> 1199 +{{/code}} 1128 1128 1129 - (%style="color:rgb(0,0,0);text-decoration:none;"%)Togetarandomnumberwithinagivenrange,youcanusemin/max:1201 +Instead of referencing a cue by name, you could also reference it via a keyword or another variable: 1130 1130 1131 -{{code}}<set_value┬áname="$foo"┬ámin="-20"┬ámax="20"/><set_value┬áname="$timeout"┬ámax="20s"/>{{/code}} 1203 +{{code language="xml"}} 1204 + <set_value name="static.$counter" operation="add" /> 1205 + <set_value name="parent.$foo" exact="42" /> 1206 + <set_value name="this.$bar" exact="parent" /> 1207 + <set_value name="$baz" exact="this.$bar.$foo" /> 1208 +{{/code}} 1132 1132 1133 - (% style="color:rgb(0,0,0);text-decoration: none;" %)min and max haveto be compatible number types. Enumeration typesarenot allowed, not even level and attention. The min attribute isoptional and defaults to 0 (of the number type used in max).1210 +== Namespaces == 1134 1134 1135 - (%style="color:rgb(0,0,0);text-decoration: none;" %)You can selectoneof5 different probabilitydistributionprofilesfor the randomrange,ΓÇ£flatΓÇ¥beingthedefault(all valuesinthe rangeare equallylikely). If you selectanotherprofile, e.g. ΓÇ£increasingΓÇ¥to makehighernumbersmore likely, youalsohaveto specify ascale value (integer)thatisgreateror equal to2.Higherscalevaluesresult inhigherpeaks inthe distributionprofiles(probable values becomeeven moreprobable).1212 +In the examples above, a variable was written to and read from the "this" cue. This can be necessary: the expression "$foo" may be different from the expression "this.$foo". The reason for that are namespaces. 1136 1136 1137 - {{code}}<set_value┬áname="$foo"┬ámin="-20"┬ámax="20" profile="profile.increasing"scale="4"/>{{/code}}1214 +Consider this case: 1138 1138 1139 -(% style="color: rgb(0,0,255);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á 1216 +{{code language="xml"}} 1217 +<cue name="Root"> 1218 + <actions> 1219 + <set_value name="$foo" /> 1220 + </actions> 1221 + <cues> 1222 + <cue name="SubCue"> [...] 1223 + </cue> 1224 + </cues> 1225 +</cue> 1226 +{{/code}} 1140 1140 1141 - (%id="variables-and-namespaces"%)1228 +When the root cue creates $foo, the variable is stored in the Root cue directly. But SubCue and its descendants will also need access to $foo. Of course they could write "parent.$foo" or "Root.$foo", but since it's very common to have a single location for most variables in the whole cue tree, the easy solution is to write just "$foo" - because variable names are looked up in the **namespace cue**, which is the root by default. Also newly created variables end up in the namespace, and not in "this" cue. 1142 1142 1143 - =(%style="color:rgb(0,0,0);text-decoration:none;"%)Variablesand namespaces(%%)=1230 +You can also use the keyword "**namespace**" in expressions to get the namespace cue. 1144 1144 1145 - (% style="color:rgb(0,0,0);text-decoration: none;" %)As you have seen above, you can easily access variables by writingtheir name(including $ prefix)inn expression. Namespacesdefine in which cue the variables are actually stored (and from which cue they are read).1232 +=== Defining a cue's namespace === 1146 1146 1147 - (% style="color:rgb(0,0,255);text-decoration:none;"%)(%style="color:rgb(0,0,0);text-decoration:none;"%)1234 +When writing a cue, you can specify what the namespace of the cue should be, by adding the //**namespace**// attribute. The following values are possible: 1148 1148 1236 +* **this**: Use "this" cue as namespace, even for instances: $foo == this.$foo 1237 +* **static**: Same as "this", but when instantiated, use the static cue: $foo == static.$foo 1238 +* **default**: The namespace is inherited from the parent cue. The default for root cues and for libraries is the same as "static". 1149 1149 1150 -(% id="categorybroken_macroanchorcreating-and-removing-variables" %) 1240 +{{warning}} 1241 +Although in general the expression "$foo == namespace.$foo" is true, there is one exception: When library parameters are evaluated in the referencing cue, variables are resolved using the parent's namespace. However, the referencing cue creates a new namespace, so the namespace keyword already points to the library, not to the parent's namespace. Example: 1151 1151 1152 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Creating and removing variables(%%) == 1153 - 1154 -(% style="color: rgb(0,0,0);text-decoration: none;" %)You can create variables with certain actions and conditions, such as the (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)<set_value>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) action: 1155 - 1156 -{{code}}┬á<set_value┬áname="$foo"┬áexact="$bar + 1" />{{/code}} 1157 - 1158 -(% style="color: rgb(0,0,0);text-decoration: none;" %)<set_value> also exists as a ΓÇ£conditionΓÇ¥, which can be useful if you want to pass information about the conditions to the actions, that would otherwise be lost - like in a complex <check_any> event condition, where you want to create a variable only if you are in a certain check branch. (Other pseudo-conditions are <remove_value> and <debug_text>.) 1159 - 1160 -(% style="color: rgb(0,0,0);text-decoration: none;" %)The default operation of <set_value> is ΓÇ£(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)set(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)ΓÇ¥, but there are more: ΓÇ£(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)add(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)ΓÇ¥, ΓÇ£(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)subtract(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)ΓÇ¥, and ΓÇ£(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)insert(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)ΓÇ¥. (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)add// and (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)subtract// change the value of an existing variable, which is created as 0 if it didnΓÇÖt exist before. If neither (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)min//, (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)max// nor (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)exact// attribute is provided, an exact value of 1 is assumed. 1161 - 1162 -{{code}}<set_value┬áname="$foo"┬áoperation="add" />{{/code}} 1163 - 1164 -(% style="color: rgb(0,0,0);text-decoration: none;" %)The trick is that <set_value> not only works on variables, but also on list elements and table keys: 1165 - 1166 -{{code}}<set_value┬áname="$list.{1}"┬áexact="42" /><set_value┬áname="$table.$foo"┬áexact="42" />{{/code}}\\ 1167 - 1168 -(% style="color: rgb(0,0,0);text-decoration: none;" %)The operation (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)insert// is special, and it only works on lists. It inserts the value at the specified position (note that the position beyond the last element is also valid here): 1169 - 1170 -{{code}}<set_value┬áname="$list.{1}"┬áexact="42"┬áoperation="insert" />{{/code}} 1171 - 1172 -(% style="color: rgb(0,0,0);text-decoration: none;" %)This shifts the positions of all following elements up by one. If min/max/exact are missing, the default value is null for insertions, not 1 like in other cases. 1173 - 1174 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Appending is easier than that. The following actions are equivalent: 1175 - 1176 -{{code}}<set_value┬áname="$list.{$list.count + 1}"┬áexact="42"┬áoperation="insert" /><append_to_list┬áname="$list"┬áexact="42" />{{/code}} 1177 - 1178 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Inserting at a position below 1 or above $list.count + 1 is not possible. 1179 - 1180 -(% style="color: rgb(0,0,0);text-decoration: none;" %)To remove variables or list/table entries, use <remove_value>: 1181 - 1182 -{{code}}<remove_value┬áname="$foo" /><remove_value┬áname="$list.{1}" /><remove_value┬áname="$table.$foo" />{{/code}}\\ 1183 - 1184 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Removing an entry from a list shifts all following elements down by one. If you want to clear an entry without removing it from the list, just use <set_value> instead. 1185 - 1186 -(% style="color: rgb(0,0,255);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %) 1187 - 1188 - 1189 -(% id="accessing-remote-variables" %) 1190 - 1191 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Accessing remote variables(%%) == 1192 - 1193 -(% style="color: rgb(0,0,0);text-decoration: none;" %)You can also read and write variables in other cues by using the variable name as property key: 1194 - 1195 -{{code}}<set_value┬áname="OtherCue.$foo"┬ámin="0.0"┬ámax="1.0" /><set_value┬áname="md.OtherScript.YetAnotherCue.$bar"┬áexact="OtherCue.$foo" />{{/code}} 1196 - 1197 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Instead of referencing a cue by name, you could also reference it via a keyword or another variable: 1198 - 1199 -{{code}}<set_value┬áname="static.$counter"┬áoperation="add" /><set_value┬áname="parent.$foo"┬áexact="42" /><set_value┬áname="this.$bar"┬áexact="parent" /><set_value┬áname="$baz"┬áexact="this.$bar.$foo" />{{/code}} 1200 - 1201 -(% style="color: rgb(0,0,255);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %) 1202 - 1203 - 1204 -(% id="namespaces" %) 1205 - 1206 -== (% style="color: rgb(0,0,0);text-decoration: none;" %)Namespaces(%%) == 1207 - 1208 -(% style="color: rgb(0,0,0);text-decoration: none;" %)In the examples above, a variable was written to and read from the ΓÇ£thisΓÇ¥ cue. This can be necessary: the expression ΓÇ£$fooΓÇ¥ may be different from the expression ΓÇ£this.$fooΓÇ¥. The reason for that are namespaces. 1209 - 1210 -(% style="color: rgb(0,0,0);text-decoration: none;" %)Consider this case: 1211 - 1212 -{{code}}<cue┬áname="Root">┬á <actions>┬á ┬á <set_value┬áname="$foo" />┬á </actions>┬á <cues>┬á ┬á <cue┬áname="SubCue"> [...]┬á ┬á </cue>┬á </cues></cue>{{/code}} 1213 - 1214 -(% style="color: rgb(0,0,0);text-decoration: none;" %)When the root cue creates $foo, the variable is stored in the Root cue directly. But SubCue and its descendants will also need access to $foo. Of course they could write ΓÇ£parent.$fooΓÇ¥ or ΓÇ£Root.$fooΓÇ¥, but since itΓÇÖs very common to have a single location for most variables in the whole cue tree, the easy solution is to write just ΓÇ£$fooΓÇ¥ - because variable names are looked up in the (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)namespace cue(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %), which is the root by default. Also newly created variables end up in the namespace, and not in ΓÇ£thisΓÇ¥ cue. 1215 - 1216 -(% style="color: rgb(0,0,0);text-decoration: none;" %)You can also use the keyword ΓÇ£(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)namespace(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)ΓÇ¥ in expressions to get the namespace cue. 1217 - 1218 -(% id="defining-a-cues-namespace" %) 1219 - 1220 -=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Defining a cueΓÇÖs namespace(%%) === 1221 - 1222 -(% style="color: rgb(0,0,0);text-decoration: none;" %)When writing a cue, you can specify what the namespace of the cue should be, by adding the (%%)//**(% style="color: rgb(0,0,0);text-decoration: none;" %)namespace(%%)**//(% style="color: rgb(0,0,0);text-decoration: none;" %) attribute. The following values are possible: 1223 - 1224 -* **(% style="color: rgb(0,0,0);text-decoration: none;" %)this(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): Use ΓÇ£thisΓÇ¥ cue as namespace, even for instances: $foo == this.$foo 1225 -* **(% style="color: rgb(0,0,0);text-decoration: none;" %)static(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): Same as ΓÇ£thisΓÇ¥, but when instantiated, use the static cue: $foo == static.$foo 1226 -* **(% style="color: rgb(0,0,0);text-decoration: none;" %)default(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %): The namespace is inherited from the parent cue. The default for root cues and for libraries is the same as ΓÇ£staticΓÇ¥. 1227 - 1228 -(% style="color: rgb(0,0,255);text-decoration: none;" %) 1229 - 1230 - 1231 -{{warning body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">Although in general the expression ΓÇ£$foo == namespace.$fooΓÇ¥ is true, there is one exception: When library parameters are evaluated in the referencing cue, variables are resolved using the parentΓÇÖs namespace. However, the referencing cue creates a new namespace, so the </span><span style=~"color: rgb(0,0,0);text-decoration: none;~">namespace</span><span style=~"color: rgb(0,0,0);text-decoration: none;~"> keyword already points to the library, not to the parentΓÇÖs namespace. Example:</span> 1232 - 1233 -<code><cue┬áname="LibRef"┬áref="Lib">┬á <param┬áname="Param1"┬ávalue="$foo" /> <!-- $foo from parent namespace -->┬á <param┬áname="Param2"┬ávalue="namespace.$foo" /> <!-- LibRef.$foo (error) --></cue></code>"/}} 1243 +{{code language="xml"}} 1244 +<cue name="LibRef" ref="Lib"> 1245 + <cke:param name="Param1" value="$foo" ></cke:param> <!-- $foo from parent namespace --> 1246 + <cke:param name="Param2" value="namespace.$foo" ></cke:param> <!-- LibRef.$foo (error) --> 1247 +</cue> 1248 +{{/code}} 1249 +{{/warning}}
- Mission Director Guide - Instantiation.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +xwiki:XWiki.Daniel - Size
-
... ... @@ -1,0 +1,1 @@ 1 +47.0 KB - Content