Changes for page Mission Director Guide
Last modified by Klaus Meyer on 2025/03/31 16:39
From version 32984.1
edited by Klaus Meyer
on 2025/03/31 16:39
on 2025/03/31 16:39
Change comment:
There is no comment for this version
To version 31073.1
edited by Daniel Turner
on 2023/04/14 17:10
on 2023/04/14 17:10
Change comment:
There is no comment for this version
Summary
-
Page properties (5 modified, 0 added, 0 removed)
-
Attachments (0 modified, 0 added, 1 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 -Mission Director Guide 1 +X4:X4 Documentation/X4 Game Design/0 General/Mission Director Guide - Parent
-
... ... @@ -1,1 +1,0 @@ 1 -X Rebirth Wiki.Modding support.WebHome - Author
-
... ... @@ -1,1 +1,1 @@ 1 -xwiki:XWiki. Klaus1 +xwiki:XWiki.Daniel - Tags
-
... ... @@ -1,1 +1,1 @@ 1 -Broken_macro/anchor |Broken macro/anchor1 +Broken_macro/anchor - Content
-
... ... @@ -1,66 +1,93 @@ 1 - The MissionDirector(MD) is a subsystemofthegame and interpretsmissionscripts,which are written inan XML-based language. The MissionDirectorinX Rebirth andX4 is basedn theMD inX3: Terran Conflict, with some major changes based on feedback from MD users.1 +{{info body="Please note that this is officially-maintained documentation. 2 2 3 - Anintroductionto theoriginalMDcanbefoundinthe[[Egosoft forums>>url:http://forum.egosoft.com/viewtopic.php?t=196971]].There isalso a PDF guidefor theX3Mission Director, which is partiallyusedas a templateforthisdocument.3 +To ensure that you can rely on the information having been checked by Egosoft, you will not be able to edit this page."/}} 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++). 6 6 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}} 10 10 7 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 11 11 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 + 12 12 {{toc/}} 13 13 14 - =MDscripts=31 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 15 15 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. 17 17 18 - MDfiles are XML files locatedin the game folder **md**. All XML filesin that folder are loaded at game start. The file names are irrelevant, since the internally used scriptnamesare 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.34 +(% id="md-scripts" %) 19 19 20 - ToeditMDscripts, an XML editing toolis needed. Microsoft VisualStudio(if available) or[[Microsoft Visual WebDeveloper>>url:http://www.microsoft.com/express/vwd/]] (forfree)are highly recommendedbecause they have pretty good support for XML schemas(XSD). The providedMissionDirectorschema files help you create the XML file by displaying all availabletagsand attributes as you edit the XML.36 += (% style="color: rgb(0,0,0);text-decoration: none;" %)MD scripts(%%) = 21 21 22 - Thisfunctionalityisonlyavailableiftheschemafiles **md.xsd** and**common.xsd**areinhecorrect folder. Ifyouare editingtheXMLin thegamefolder directly,alliswellandthefilesareloadedfromhelibrariesfolder.However,if you are editinginaseparatefolder,copythoseXSDfilesfrom thelibrariesfolderdirectlyinto thefolder where yourXML filesare located.38 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 23 23 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;"]]). 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. 26 26 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}} 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. 29 29 30 -== Script debug output==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 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. 31 31 32 - Thegamecanprint errormessages and,when enabled, alsogeneralmessages.Errormessages canginate fromthe scriptingsystem, butalsofrom othergameub-systems.Theycan be viewedin thein-game[[DebugLog>>url:https://forum.egosoft.com/viewtopic.php?t=366654]].46 +{{note body="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 [[NULL|Conditions]]). 33 33 34 -To col lect allmessagesinafile,start thegame with the followingparameters on thecommandline:48 +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."/}} 35 35 36 -{{code language="xml"}} 37 --logfile debuglog.txt 38 -{{/code}} 39 39 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: 41 41 42 -{{code language="xml"}} 43 --debug scripts 44 -{{/code}} 52 +(% id="categorybroken_macroanchorscript-debug-output" %) 45 45 46 - Otherdebugfiltersother than"scripts"can be enabled byrepeatinghebugcommandforeachfiltername,butthat is rarely needed for scripting.54 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Script debug output(%%) == 47 47 48 - Thescriptaction<debug_text>canbeusedtoprintdebug messages from within a script.56 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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 (% style="color: rgb(0,0,0);text-decoration: none;" %)in-game [[DebugLog>>url:https://forum.egosoft.com/viewtopic.php?t=366654]]. 49 49 50 -= MDscript structure=58 +(% style="color: rgb(0,0,0);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %)To collect all messages(%%) in a file, start the game with the following parameters on the command line: 51 51 52 - Inthissection we will lookat how to starthewhole process by creatinganew MD missionfileandthebasicsteps in producing missioncontentwith XMLcode. There will beadescription ofthe key elementsof themission file.60 +(% style="color: rgb(0,0,0);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}-logfile debuglog.txt{{/code}} 53 53 54 - TheXMLroot node ofanMDfileiscalled"mdscript" andlooks likethis:62 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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: 55 55 64 +(% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}-debug scripts{{/code}} 65 + 66 +(% style="color: rgb(0,0,0);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 67 + 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. 70 + 71 + 72 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 73 + 74 + 75 +(% id="md-script-structure" %) 76 + 77 += (% style="color: rgb(0,0,0);text-decoration: none;" %)MD script structure(%%) = 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. 80 + 81 +(% style="color: rgb(0,0,0);text-decoration: none;" %)The XML root node of an MD file is called ΓÇ£mdscriptΓÇ¥ and looks like this: 82 + 56 56 {{code language="xml"}} 57 57 <?xml version="1.0" encoding="utf-8"?> 58 58 <mdscript name="ScriptName" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd"> 59 59 {{/code}} 60 60 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.88 +(% style="color: rgb(0,0,0);text-decoration: none;" %)ΓÇ£ScriptNameΓÇ¥ is the name used for this script regardless of the file name. It (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)has to start with an upper case letter and must be unique(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) 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. 62 62 63 -The only allowed sub-node of <mdscript> is <cues>, which can only contain <cue> sub-nodes: 90 +(% style="color: rgb(0,0,0);text-decoration: none;" %)The only allowed sub-node of <mdscript> is <cues>, which can only contain <cue> sub-nodes: 64 64 65 65 {{code language="xml"}} 66 66 <?xml version="1.0" encoding="utf-8"?> ... ... @@ -74,25 +74,36 @@ 74 74 </mdscript> 75 75 {{/code}} 76 76 77 -= =Cues==104 +(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á 78 78 79 - Cuesare the main ingredient of an MD script. A cue consists ofasetof **conditions** and a setof **actions**. When the conditions are met, the cue is activated and the actions are performed. A cue canhavechild cues, or**sub-cues**: A sub-cue existsonly when its parentcuehas become active, so the activation of the parentcueinitiatesthe condition checks of its child cues.106 +(% id="categorybroken_macroanchorcues" %) 80 80 81 - Acuecan havethefollowingstates:108 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Cues(%%) == 82 82 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. 110 +(% 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. 86 86 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. 112 +(% style="color: rgb(0,0,0);text-decoration: none;" %)A cue can have the following states: 89 89 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}} 114 +* **(% 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. 115 +* **(% 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 has become active. The cue is checking its conditions and will become active when they are met. 116 +* **(% 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. 117 +\\ 118 +* **(% 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. 119 +* **(% 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. 93 93 94 - Thisishowa cuenodelookslike:121 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 95 95 123 + 124 +{{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 /> 125 +</span>"/}} 126 + 127 + 128 + 129 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 130 + 131 + 132 +(% style="color: rgb(0,0,0);text-decoration: none;" %)This is how a cue node looks like: 133 + 96 96 {{code language="xml"}} 97 97 <cue name="CueName"> 98 98 <conditions> [...] ... ... @@ -105,18 +105,23 @@ 105 105 </cue> 106 106 {{/code}} 107 107 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. 146 +(% style="color: rgb(0,0,0);text-decoration: none;" %)The rules for naming cues is the same for MD script names: The name **starts with an upper case letter**, and has to be (%%)**(% 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 actually possible to use the same cue name in different scripts, which is different from the MD in X3. 109 109 110 - ==Conditions==148 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 111 111 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. 113 113 114 - **Non-eventconditions** are checkedeither once or repeatedly in a fixed interval. Theymaybe basedonsimple values or ranges, such as a particular in-game time having been reachedorthe player having acertain amount of money. They may also be basedon more complex playerinformation,suchas what ships they own, whether the player is in a particular area or near a particular object.151 +(% id="categorybroken_macroanchorconditions" %) 115 115 116 - **Eventconditions**are triggered when the corresponding eventhappens, such as the event that a particular object has been targeted, attacked or destroyed. Allevent nodes have the prefix"event_" so youcan easily determine a condition type. Afteran event condition you can specify one ormore non-event conditions, which willbe checked additionally whenever the event happens. If a condition uses an event,itmust beinthe first sub-nodeof the <conditions> node. It is even possible to define multiple alternative events that should activate the cue. The first sub-nodeshould be <check_any> in this case, soonly one of its sub-conditionshas to be met.153 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Conditions(%%) == 117 117 118 - Example foran event condition:155 +(% 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. 119 119 157 +**(% 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 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. 158 + 159 +**(% style="color: rgb(0,0,0);text-decoration: none;" %)Event conditions(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) 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. 160 + 161 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Example for an event condition: 162 + 120 120 {{code language="xml"}} 121 121 <conditions> 122 122 <event_object_destroyed object="$target"/> ... ... @@ -123,7 +123,7 @@ 123 123 </conditions> 124 124 {{/code}} 125 125 126 -Example for an event condition with an additional (non-event) check: 169 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Example for an event condition with an additional (non-event) check: 127 127 128 128 {{code language="xml"}} 129 129 <conditions> ... ... @@ -132,7 +132,7 @@ 132 132 </conditions> 133 133 {{/code}} 134 134 135 -Example for an event condition with two alternative events and a common additional check: 178 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Example for an event condition with two alternative events and a common additional check: 136 136 137 137 {{code language="xml"}} 138 138 <conditions> ... ... @@ -147,1102 +147,1087 @@ 147 147 </conditions> 148 148 {{/code}} 149 149 150 -For more information about expressions and event parameters, see below. 193 +(% style="color: rgb(0,0,0);text-decoration: none;" %)For more information about expressions and event parameters, see below. 151 151 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. 195 +**(% 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. 153 153 154 -If a cue has a <conditions> node without any event, it must have one of the attributes //**onfail**// or //**checkinterval**//. 197 +(% style="color: rgb(0,0,0);text-decoration: none;" %)If a cue has a <conditions> node without 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;" %). 155 155 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). 199 +* 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). 200 +\\ 201 +* (% 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. 157 157 158 - *With //checkinterval//, you can specifya constant timeinterval between condition checks.The conditionswill becheckedregularlyforeveruntiltheyaremet,unless the cue'sstate ischangedexplicitlybyan externalevent.203 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Additionally, you can use the attribute (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)checktime(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) to set the time of the first condition check (also possible in combination with (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)onfail//). The (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)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). 159 159 160 - Additionally,you can usetheattribute **checktime** toset the timeof the firstcondition check (also possible in combination with //onfail//). The //checktime// can be an expression with variables andisevaluated when thecue is enabled (whenthe conditionchecks wouldnormally start - for root cues that happens at gamestart, otherwise after theparent cue becomesactive).205 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Examples: 161 161 162 - Examples:207 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Check conditions every 5 seconds, but start checking only 1 hour after game start. 163 163 164 - Check conditionsevery 5 seconds, butstartly 1 houraftergame start.209 +{{code}}<cue┬áname="Foo"┬áchecktime="1h"┬ácheckinterval="5s">┬á <conditions>┬á [...]</cue>{{/code}} 165 165 166 -{{code language="xml"}} 167 -<cue name="Foo" checktime="1h" checkinterval="5s"> 168 - <conditions> 169 - [...] 170 -</cue> 171 -{{/code}} 211 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Check conditions 3 seconds after the cue is enabled, and cancel the cue in case of failure. 172 172 173 - Check conditions 3 secondsaftertheisenabled, andcancelhecueincaseof failure.213 +{{code}}<cue┬áname="Foo"┬áchecktime="player.age + 3s"┬áonfail="cancel">┬á <conditions>┬á [...]</cue>{{/code}} 174 174 175 -{{code language="xml"}} 176 -<cue name="Foo" checktime="player.age + 3s" onfail="cancel"> 177 - <conditions> 178 - [...] 179 -</cue> 180 -{{/code}} 215 +(% 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. 181 181 182 - The attributes //onfail//, //checkinterval//, //checktime// are not allowed for cues with event conditions.217 +\\ 183 183 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}} 188 188 189 -== Actions == 190 190 191 - The <actions> nodecontainstheactionsthatareperformedoneafteranother,withoutanydelayinbetween.You can enforcea delayafteractivation of thecueandactual actionperformance,usinga <delay>noderightbeforethe<actions>:221 +{{note body="Reminder: 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."/}} 192 192 193 -{{code language="xml"}} 194 -<delay min="10s" max="30s"/> 195 -{{/code}} 196 196 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: 198 198 199 -{{code language="xml"}} 200 -<event_cue_completed cue="parent"/> 201 -{{/code}} 225 +\\ 202 202 203 - <actions>is optional. Leaving it out may be useful if you only want to enable sub-cues after the cue's conditioncheck. Thestatetransition from active to complete will still take the <delay> node into account.227 +(% id="actions" %) 204 204 205 - Notethatthe MDscriptanguageis not designed as a programminglanguage. The actions areperformed in sequence, although they canbe nested to form more complex structures. Loops and conditionals exist to some extent,butnot necessarily in the sense that a programmer might expect. Analogously to <check_all> and<check_any>, you can use **<do_all>** to performallthe contained sub-node actions,and **<do_any>** to performonly one of them. <do_all> is particularly useful when nestedin a <do_any>.229 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Actions(%%) == 206 206 207 - Example,whichselects one of the three textsrandomly:231 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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>: 208 208 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}} 233 +{{code}}<delay┬ámin="10s"┬ámax="30s"/>{{/code}} 218 218 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}} 235 +(% 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: 222 222 223 - Each child action in a <do_any> nodecan havea //**weight**// attribute, which can beused tocontrolherandom selection ofanaction node. The defaultweightof achild nodeis 1.237 +{{code}}<event_cue_completed┬ácue="parent"/>{{/code}} 224 224 225 - Alsoavailableis **<do_if>**, which completestheenclosedaction(s)onlyifoneprovided value isnon-nullormatchesanother.Directlyafter a <do_if>node,youcan addone or more **<do_elseif>**nodestoperform additional checksonly in case theprevious conditionswere not met. Thenode **<do_else>**canbe used directlyafter a<do_if>ora <do_elseif>. It is executedonlyifnone oftheconditions are met.239 +(% style="color: rgb(0,0,0);text-decoration: none;" %)<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. 226 226 227 - **<do_while>**alsoexists,but shouldbeusedcarefully,since it is the onlyaction that could cause aninfinite loop,whichfreezes the gamewithout any chance ofrecovery.241 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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 (%%)**(% 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>. 228 228 229 - Everyaction can havea //**chance**//attribute, if you only wantt tobe performedwith thatchance,givenas percentage.Otherwiseitwillsimplybe skipped.243 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Example, which selects one of the three texts randomly: 230 230 231 -* If chance is used on a conditional action such as <do_if>, the script will behave as if the condition check failed. 232 -* If chance is provided on an action within a <do_any>, it will have no effect on the random selection of the action. Only when the action gets selected, the chance will determine whether the action actually gets performed or skipped. 245 +{{code}}<actions>┬á<do_any>┬á┬á <debug_text┬átext="'Hello world'"/>┬á┬á <debug_text┬átext="'Welcome to the MD'"/>┬á┬á <debug_text┬átext="'And now for something completely different'"/>┬á</do_any><actions>{{/code}} 233 233 234 -= Libraries=247 +{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">Messages printed with <debug_text> are usually only visible when the ΓÇ£scriptsΓÇ¥ debug filter is enabled, see [[NULL|Script debug output]].</span>"/}} 235 235 236 -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. 237 237 238 -{{info}} 239 -The syntax of libraries is considerably different from the syntax in the MD of X3TC. 240 -{{/info}} 241 241 251 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Each child action in a <do_any> node can have a (%%)//**(% style="color: rgb(0,0,0);text-decoration: none;" %)weight(%%)**//(% style="color: rgb(0,0,0);text-decoration: none;" %) attribute, which can be used to control the random selection of an action node. The default weight of a child node is 1. 242 242 243 - Library cuesare written like normalcues,they are alsodefinedin a <cues>node,justwith the differencethat theXMLtagiscalledlibraryinstead of cue:253 +(% 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. 244 244 245 -{{code language="xml"}} 246 -<library name="LibFoo" checktime="1h" checkinterval="5s"> 247 - <conditions> 248 - [...] 249 -</library> 250 -{{/code}} 255 +**(% style="color: rgb(0,0,0);text-decoration: none;" %)<do_while>(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) 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. 251 251 252 - Althoughit iscalledlibrary,it's basicallyjust acuethatdoesn't donything.Youcanmixcues andlibrariesasyou want,as rootcuesorsub-cues- thelocationwithinthefileisunimportant.Allthat countsis thelibraryname,whichhastobeunique within theMDscript,like allothercuenames.257 +(% 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. 253 253 254 - Tousealibrary,usehetributeref:259 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 255 255 256 -{{code language="xml"}} 257 -<cue name="Foo" ref="LibFoo"/> 258 -{{/code}} 259 259 260 - Thiswill create a cue with the name Foo that behavesjustikethe librarycue LibFoo. In this example, LibFoo has to be a libraryinthesame MD scriptfile. Touse a library LibFoofrom another script, you have to qualify it with the scriptname,using the **md** prefix:262 +(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á 261 261 262 -{{code language="xml"}} 263 -<cue name="Foo" ref="md.ScriptName.LibFoo"/> 264 -{{/code}} 264 +(% id="libraries" %) 265 265 266 - Whentheref attributeis provided, allotherattributes(except for name)will be ignored andtaken fromthe library cue instead. (By default a librarycreatesitsown namespace, as ifnamespace="static"were specified. See the section about namespaces.)266 += (% style="color: rgb(0,0,0);text-decoration: none;" %)Libraries(%%) = 267 267 268 - Alsoallsub-cuesofthelibrary will becreatedas sub-cuesof thecue thatusesit.Theyare definedinthelibraryas<cue>,notas<library>.(Althoughyoucan definea library as aub-cueofanother library, the locationin the file doesnotmatter,asalreadystatedabove.) Itisevenpossible to reference otherlibrariesub-cues of a library!268 +(% 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. 269 269 270 - Incontrast to X3TC, a cuethat references a libraryalso has its ownname (Foo inthe exampleabove), soothercues can access it in expressionsby that name.Sub-cuesof Foo cannotbeaccessedby their name though.Within thelibraryitself, expressions canuselnames ofcues that belongtothe library(the<library> andallsub-cues). They will be translatedproperly whenthelibraryis referenced.Examples:270 +{{note body="<span style=~"color: rgb(0,0,0);~">The syntax of libraries is considerably different from the syntax in the MD of X3TC.</span>"/}} 271 271 272 -{{code language="xml"}} 273 -<cue name="Foo" ref="LibFoo"/> 274 -<cue name="Bar" ref="LibFoo"/> 275 275 276 -<library name="LibFoo"> 277 - <actions> 278 - <cancel_cue cue="this"/> 279 - <cancel_cue cue="LibFoo"/> 280 - <cancel_cue cue="Foo"/> 281 - <cancel_cue cue="Baz"/> 282 - <cancel_cue cue="md.Script.Foo"/> 283 - <cancel_cue cue="md.Script.LibFoo"/> 284 - <cancel_cue cue="md.Script.Baz"/> 285 - </actions> 286 - <cues> 287 - <cue name="Baz"> [...] 288 - </cues> 289 -</library> 290 -{{/code}} 291 291 292 -{{warning}} 293 -These examples are definitely **__not__ **examples of good scripting style. 294 -{{/warning}} 274 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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: 295 295 296 - Sowhen writing thelibrary, you don't havetoworry about name confusion, justuse thenames of cues in your library and itwill work as expected whenhelibrary isused. Namesof cuesthat donotbelongothelibrary will notbe available in expressions (see Foointhe example above), however,namesof otherlibraries inthe file are available whenreferencinghem in the ref attribute.276 +{{code}}<library┬áname="LibFoo"┬áchecktime="1h"┬ácheckinterval="5s">┬á <conditions>┬á [...]</library>{{/code}} 297 297 298 - Notes:278 +(% 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 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. 299 299 300 -* 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). 301 -* You //can// access variables in the library root but generally this should be avoided in favor of parameterizing the library! 302 -** there are some cases where you do want to access these variables directly, for example for maintaining savegame compatibility when patching. 280 +(% style="color: rgb(0,0,0);text-decoration: none;" %)To use a library, use the attribute ref: 303 303 304 -== rary Parameters ==282 +{{code}}<cue┬áname="Foo"┬áref="LibFoo"/>{{/code}} 305 305 306 - Alibrarycanbeparametrised,sothatitcan be adaptedtothe needsof a missionsthatusesit.You can definerequiredand/oroptionalparametersfora library,anditwillbevalidatedatloadtimethat theuserofthe libraryhas providedall requiredparameters.284 +(% 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 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 (%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %)md(%%)**(% style="color: rgb(0,0,0);text-decoration: none;" %) prefix: 307 307 308 - Parameters aredefinedlikethis:286 +{{code}}<cue┬áname="Foo"┬áref="md.ScriptName.LibFoo"/>{{/code}} 309 309 310 -{{code language="xml"}} 311 -<library name="Lib" onfail="cancel"> 312 - <params> 313 - <param name="foo"/> 314 - <param name="bar" default="42"/> 315 - <param name="baz" default="player.age"/> 316 - </params> 317 - [...] 318 -</library> 319 -{{/code}} 288 +(% style="color: rgb(0,0,0);text-decoration: none;" %)When the ref attribute is provided, all other attributes (except for name) will be ignored and taken from the library cue instead. ((% style="color: rgb(0,0,0);text-decoration: none;" %)By default a library creates its own namespace, as if namespace="static" were specified. See the section about namespaces.(%%)) 320 320 321 - Ifadefaultvalueis supplied,theparameter isregarded asoptional,otherwiseit'srequired.Whenprovidingthe actualparametersin a referencingcue,note that thereis no<params>node:290 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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! 322 322 323 -{{code language="xml"}} 324 -<cue name="Foo" ref="Lib"> 325 - <param name="foo" value="race.argon"/> 326 - <param name="bar" value="0"/> 327 -</cue> 328 -{{/code}} 292 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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: 329 329 330 - Thevalues (includingdefaultvalues)canbevariable expressionsand willbeevaluated when the cueisenabled,i.e.when itstartschecking thenditions.Theywillbeavailablehecueasvariables,using theparameternamewitha'$'prefix.In theexample above,thevariables$foo,$bar,and$bazwouldbe created.294 +{{code}}<cue┬áname="Foo"┬áref="LibFoo"/><cue┬áname="Bar"┬áref="LibFoo"/><library┬áname="LibFoo">┬á <actions>┬á ┬á <cancel_cue┬ácue="this"/>┬á┬á┬á ┬á┬á┬á┬á┬á┬á┬á┬á <!-- Cancels the cue referencing LibFoo -->┬á ┬á <cancel_cue┬ácue="LibFoo"/>┬á┬á┬á ┬á┬á ┬á ┬á <!-- Cancels the cue referencing LibFoo -->┬á ┬á <cancel_cue┬ácue="Foo"/>┬á┬á┬á ┬á┬á┬á ┬á┬á ┬á┬á <!-- Error, Foo not found in library -->┬á ┬á <cancel_cue┬ácue="Baz"/>┬á┬á┬á ┬á┬á┬á ┬á┬á ┬á┬á <!-- Cancels Baz in the referencing cue -->┬á ┬á <cancel_cue┬ácue="md.Script.Foo"/>┬á┬á┬á <!-- Cancels Foo -->┬á ┬á <cancel_cue┬ácue="md.Script.LibFoo"/>┬á<!-- Error, trying to cancel library -->┬á ┬á <cancel_cue┬ácue="md.Script.Baz"/>┬á┬á┬á <!-- Error, trying to cancel library sub-cue -->┬á </actions>┬á <cues>┬á ┬á <cue┬áname="Baz"> [...]┬á<!-- Sub-cue is created in all cues referencing LibFoo -->┬á </cues></library>{{/code}} 331 331 332 -{{code language="xml"}} 333 -<library name="Lib"> 334 - <params> 335 - <param name="foo"/> 336 - </params> 337 - <actions> 338 - <debug_text text="$foo"/> 339 - </actions> 340 -</library> 341 -{{/code}} 296 +{{warning body="These examples are definitely <u>not</u> examples of good scripting style."/}} 342 342 343 -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. 344 344 345 -= Instantiation = 346 346 347 -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.** 348 -\\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. 349 -\\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. 300 +(% 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. 350 350 351 - ==Cleaningup instancesexplicitly ==302 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Notes: 352 352 353 -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. 304 +* (% 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). 305 +* (% 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! 306 +** (% 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. 354 354 355 -{{info}} 356 -<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. 357 -{{/info}} 308 +(% id="library-parameters" %) 358 358 359 -== Accesstoinstances ==310 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Library Parameters(%%) == 360 360 361 -{{info}} 362 -This sub-section requires basic knowledge of script expressions. 363 -{{/info}} 312 +(% 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. 364 364 365 - Incase of instances with sub-instances, you willoftenwant to access arelated instancefrom thecurrente.Like inthe non-instancecase, you can simply write the cue namein an expressionto reference that cue. However, youshouldbeawareof thepitfalls that areaccompaniedbythis.314 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Parameters are defined like this: 366 366 367 - When you usecuenamefromthe same scriptinn expression, itwillalwaysberesolvedtosome cue- usually a static cue, even if itis still in thedisabled state, butitcanlsoean instance, ifitis "related" to thecurrentne.316 +{{code}}<library┬áname="Lib" onfail="cancel">┬á <params>┬á┬á┬á <param┬áname="foo"/>┬á┬á┬á <param┬áname="bar"┬ádefault="42"/>┬á┬á┬á <param┬áname="baz"┬ádefault="player.age"/>┬á </params>┬á [...]</library>{{/code}} 368 368 369 - Relatedmeansthatthiscueand the referencedcuehave acommonncestornstance,andthereferencedcue isadirect(non-instantiated)descendantofthatcommon ancestor.318 +(% 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: 370 370 371 - Examplehart:320 +{{code}}<cue┬áname="Foo"┬áref="Lib">┬á<param┬áname="foo"┬ávalue="race.argon"/>┬á<param┬áname="bar"┬ávalue="0"/></cue>{{/code}} 372 372 373 - [[~[~[image:MissionDirectorGuide- Instantiation.png~|~|width="800px"~]~]>>attach:ARCHIVE_XRWIKI_Modding_support_Mission_Director_GuideMission_Director_Guide_-_Instantiation.png]]322 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 374 374 375 - Thischart represents a script of 5 cues: Foo, Bar, SubBar, Baz and SubBaz. Continuousarrowsdenoteparent-child relationship. Foo and Baz are instantiatingcues(highlightedwith redborder). The static cues always exist, although staticchildren of instantiatingcues can never become active. Instances only existaslongas they are needed.324 +{{code}}<library┬áname="Lib">┬á <params>┬á ┬á <param┬áname="foo"/>┬á </params>┬á <actions>┬á ┬á <debug_text┬átext="$foo"/>┬á </actions></library>{{/code}} 376 376 377 - Example situations:326 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 378 378 379 -* In the static tree: Cue names in expressions are always resolved to the static cues. 380 -* In the inst-2 tree: "SubBar" in an expression will be resolved to SubBar (inst 2). 381 -* 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. 382 -* In the inst-2a tree: "SubBaz" in an expression will be resolved to SubBaz (inst 2a) 383 -* In the inst-2a tree: "Bar" in an expression will be resolved to Bar (inst 2) because Foo (inst 2) is a common ancestor. 384 -* 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. 328 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 385 385 386 -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. 387 387 388 - Toget the realstatic cue that always exists and serves as templateforinstances, usetheproperty **staticbase**. This works for all cues, evenfor thestatic cues themselves.331 +(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á 389 389 390 - Ingeneral, to access ancestors of the current cue, you canalso usethe keyword **parent**, also recursivelyas propertiesof other cues (such as **parent.parent.parent).**333 +(% id="instantiation" %) 391 391 392 - Youcanstoreue references in variables. But when storingan instance cue in a variable, and later accessingthat variable,be awarethat theinstance may not existany more. Use the property **exists** tocheck if aninstanceis still alive. (Incontrast, non-instance cues always exist, but may beinthe //disabled//or //cancelled// state.)335 += (% style="color: rgb(0,0,0);text-decoration: none;" %)Instantiation(%%) = 393 393 394 -== Pitfalls ==337 +(% 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. 395 395 396 - Some additionalcommonpitfalls withrespect toinstantiation are listed here.Theremay be more.339 +(% 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. 397 397 398 - ***Conditionswith results:**Ifthe instantiatingcuehas conditionswith results,those resultsare stored invariables-but inthevariables ofthe staticcue,not ofthe instance!Sointhe<actions>youhave toaccessthevariables viathe**static**keyword:341 +(% 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. 399 399 400 -{{code language="xml"}}<debug_text text="static.$foo"/>{{/code}} 401 -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: 402 -{{code language="xml"}}<set_value name="$foo" exact="static.$foo"/>{{/code}} 343 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 403 403 404 -* **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. 405 -* **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. 406 406 407 - =Expressions=346 +(% id="cleaning-up-instances-explicitly" %) 408 408 409 - Mostofthe attribute values in actions and conditions areinterpreted as script expressions andparsed accordingly.Anexpressionis a phrasethat can be evaluated toasinglevalue. The simplestexpressionsare actualnumericvaluesand strings, so called **literals:**348 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Cleaning up instances explicitly(%%) == 410 410 411 -* {{code language="xml"}}0{{/code}}(integer number) 412 -* {{code language="xml"}}0772{{/code}}(leading 0 means octal integer number) 413 -* {{code language="xml"}}3.14159{{/code}}(floating point number) 414 -* {{code language="xml"}}5e12{{/code}}(float in exponent notation, "times ten to the power of") 415 -* {{code language="xml"}}0xCAFE{{/code}}(hexadecimal integer number) 350 +(% 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. 416 416 417 -{{info}} 418 -Since octal numbers are hardly ever used (usually unknowingly), the parser is will produce a warning if an octal number is encountered." 419 -{{/info}} 352 +{{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>"/}} 420 420 421 -You can write string literals by putting the string in single quotes: 422 422 423 -* {{code language="xml"}}'Hello world'{{/code}} 424 -* {{code language="xml"}}''{{/code}}(empty string) 425 -* {{code language="xml"}}'String with a line break\n'{{/code}} 426 426 427 -{{info}} 428 -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 ''' 429 -''' for the backslash itself. 430 -{{/info}} 356 +(% id="access-to-instances" %) 431 431 432 -== Numeric datatypesandsuffixes ==358 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Access to instances(%%) == 433 433 434 -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: 435 435 436 -* {{code language="xml"}}5000000000L{{/code}}(large integer) 437 -* {{code language="xml"}}1f{{/code}}(floating point number, same as 1.0, just 1 would be an integer) 438 -* {{code language="xml"}}1000Cr{{/code}}(Money in Credits, converted to 100000 cents automatically) 439 -* {{code language="xml"}}500m{{/code}}(Length in metres) 440 -* {{code language="xml"}}10s{{/code}}(Time in seconds) 441 -* {{code language="xml"}}1h{{/code}}(Time in hours, which is converted to 3600s automatically) 442 442 443 - Aspace between number andsuffix is allowed.362 +{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">This sub-section requires basic knowledge of [[NULL|script expressions]].</span>"/}} 444 444 445 -Here is the complete list of numeric data types and corresponding unit suffixes: 446 446 365 + 366 +(% 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. 367 + 368 +(% 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. 369 + 370 +(% 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. 371 + 372 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Example chart: 373 + 374 +(% 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]] 375 + 376 + 377 +(% 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. 378 + 379 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Example situations: 380 + 381 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)In the static tree: Cue names in expressions are always resolved to the static cues. 382 +* (% 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). 383 +* (% 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. 384 +* (% 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) 385 +* (% 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. 386 +* (% 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. 387 + 388 +(% 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. 389 + 390 +(% 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. 391 + 392 +(% 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).(%%)** 393 + 394 +(% 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.) 395 + 396 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 397 + 398 + 399 +(% id="pitfalls" %) 400 + 401 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Pitfalls(%%) == 402 + 403 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Some additional common pitfalls with respect to instantiation are listed here. There may be more. 404 + 405 +* **(% 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: 406 +\\{{code}}<debug_text┬átext="static.$foo"/>{{/code}}(% style="color: rgb(0,0,255);text-decoration: none;" %) 407 +\\(% 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: 408 +\\{{code}}<set_value┬áname="$foo"┬áexact="static.$foo"/>{{/code}} 409 +* **(% 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. 410 +* **(% 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. 411 + 412 +(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á 413 + 414 +(% id="categorybroken_macroanchorexpressions" %) 415 + 416 += (% style="color: rgb(0,0,0);text-decoration: none;" %)Expressions(%%) = 417 + 418 +(% 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;" %) 419 + 420 + 421 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}0{{/code}} (integer number) 422 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}0772{{/code}} (leading 0 means octal integer number) 423 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}3.14159{{/code}} (floating point number) 424 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}5e12{{/code}} (float in exponent notation, ΓÇ£times ten to the power ofΓÇ¥) 425 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}0xCAFE{{/code}} (hexadecimal integer number) 426 + 427 + 428 + 429 +{{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>"/}} 430 + 431 + 432 + 433 +(% style="color: rgb(0,0,0);text-decoration: none;" %)You can write string literals by putting the string in single quotes: 434 + 435 +* {{code}}'Hello world'{{/code}} 436 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}''{{/code}} (empty string) 437 +* {{code}}'String with a line break\n'{{/code}} 438 + 439 + 440 + 441 +{{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>"/}} 442 + 443 + 444 + 445 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 446 + 447 + 448 +(% id="numeric-data-types-and-suffixes" %) 449 + 450 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Numeric data types and suffixes(%%) == 451 + 452 +(% 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: 453 + 454 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}5000000000L{{/code}} (large integer) 455 +* (% 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) 456 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}1000Cr{{/code}} (Money in Credits, converted to 100000 cents automatically) 457 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}500m{{/code}} (Length in metres) 458 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}10s{{/code}} (Time in seconds) 459 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}1h{{/code}} (Time in hours, which is converted to 3600s automatically) 460 + 461 +(% style="color: rgb(0,0,0);text-decoration: none;" %)A space between number and suffix is allowed. 462 + 463 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Here is the complete list of numeric data types and corresponding unit suffixes: 464 + 465 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 466 + 467 + 447 447 (% style="margin-left: 0.0px;" %) 448 448 ((( 449 -|Data type|Suffix|Examples|Description 450 -|null|(none)|null|Converted to non-null data type of value 0 when needed. 451 -|integer|i|42|32-bit signed integer. Default for integer literals, so the suffix is not required for them. 452 -|largeint|L|0x1ffffffffL|Large 64-bit signed integer. 453 -|float|f| 454 -3.14 455 -\\0x100f|32-bit float (single precision). Default for floating point literals, so the suffix is not required for them. 456 -|largefloat|LF|1.5e300 LF|Large 64-bit floating point number (double precision). 457 -|money|ct (default) 458 -\\Cr|200Cr 459 -\\50ct|Money in Credits or cents, always stored in cents. Do not forget to write Cr when working with Credits. 460 -|length| 461 -m (default) 462 -\\km| 463 -500m 464 -\\2.3km|Length in metres or kilometres, respectively. A length value is always stored in metres. 465 -|angle| 466 -rad (default) 467 -\\deg| 468 -90deg 469 -\\3.14159rad|Angle in radians or degrees, respectively. An angle value is always stored in radians. 470 -|hitpoints|hp|100hp|Hit points 471 -|time| 472 -ms 473 -\\s (default) 474 -\\min 475 -\\h| 476 -800ms 477 -\\1.5s 478 -\\10min 479 -\\24h|Time in milliseconds, seconds, minutes, or hours, respectively. A time value is always stored in seconds. 470 +\\ 471 + 472 + 473 + 474 +|(%%)(% 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 475 +|(%%)(% 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. 476 +|(%%)(% 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. 477 +|(%%)(% 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. 478 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)float|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)f| 479 +(% style="color: rgb(0,0,0);text-decoration: none;" %)3.14(%%) 480 +\\(% 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. 481 +|(%%)(% 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). 482 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)money|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)ct (default) 483 +\\Cr|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)200Cr 484 +\\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. 485 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)length| 486 +(% style="color: rgb(0,0,0);text-decoration: none;" %)m (default)(%%) 487 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)km| 488 +(% style="color: rgb(0,0,0);text-decoration: none;" %)500m(%%) 489 +\\(% 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. 490 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)angle| 491 +(% style="color: rgb(0,0,0);text-decoration: none;" %)rad (default)(%%) 492 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)deg| 493 +(% style="color: rgb(0,0,0);text-decoration: none;" %)90deg(%%) 494 +\\(% 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. 495 +|(%%)(% 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 496 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)time| 497 +(% style="color: rgb(0,0,0);text-decoration: none;" %)ms(%%) 498 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)s (default)(%%) 499 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)min(%%) 500 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)h| 501 +(% style="color: rgb(0,0,0);text-decoration: none;" %)800ms(%%) 502 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)1.5s(%%) 503 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)10min(%%) 504 +\\(% 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. 480 480 ))) 481 481 482 -{{info}} 483 -All unit data types are floating point types, except for money, which is an integer data type. 484 -{{/info}} 507 +{{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>"/}} 485 485 486 - == Operators ==509 +\\ 487 487 488 -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 489 489 512 + 513 +(% id="categorybroken_macroanchoroperators" %) 514 + 515 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Operators(%%) == 516 + 517 +(% 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: 518 + 519 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 520 + 521 + 490 490 (% style="margin-left: 0.0px;" %) 491 491 ((( 492 -|Operator / Delimiter / Constant|Type|Example|Result of example|Description 493 -|null|constant|{{code language="xml"}}null + 1{{/code}}|{{code language="xml"}}1{{/code}}|Null value, see above 494 -|false|constant|{{code language="xml"}}1 == 0{{/code}}|{{code language="xml"}}false{{/code}}|Integer value 0, useful in Boolean expressions 495 -|true|constant|{{code language="xml"}}null == 0{{/code}}|{{code language="xml"}}true{{/code}}|Integer value 1, useful in Boolean expressions 496 -|pi|constant|{{code language="xml"}}2 * pi{{/code}}|{{code language="xml"}}6.2831853rad{{/code}}|╧Ç as an angle (same as 180deg) 497 -|()|delimiter|{{code language="xml"}}(2 + 4) * (6 + 1){{/code}}|{{code language="xml"}}42{{/code}}|Parentheses for arithmetic grouping 498 -|[]|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 499 -|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 500 -|{}|delimiter|{{code language="xml"}}{101, 3}{{/code}}|{{code language="xml"}}'Some text'{{/code}}|Text lookup (page ID and text ID) from TextDB 501 -\\(Note: Braces are also used for [[property lookups>>doc:||anchor="HValueproperties" style="outline-width: 0px !important; user-select: auto !important;"]]) 502 -|+|unary|{{code language="xml"}}+21 * (+2){{/code}}|{{code language="xml"}}42{{/code}}|Denotes positive number (no effect) 503 -|-|unary|{{code language="xml"}}-(21 * -2){{/code}}|{{code language="xml"}}42{{/code}}|Negates the following number 504 -|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 505 -|typeof|unary| 506 -{{code language="xml"}}typeof null{{/code}} 507 -\\{{code language="xml"}}typeof 0{{/code}} 508 -\\{{code language="xml"}}typeof 'Hello world'{{/code}}| 509 -{{code language="xml"}}datatype.null{{/code}} 510 -\\{{code language="xml"}}datatype.integer{{/code}} 511 -\\{{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;"]] 512 -|sin|unary| 513 -{{code language="xml"}}sin(30deg){{/code}} 514 -\\{{code language="xml"}}sin(pi){{/code}}| 515 -{{code language="xml"}}0.5{{/code}} 516 -\\{{code language="xml"}}1.0{{/code}}|Sine (function-style, parentheses required) 517 -|cos|unary| 518 -{{code language="xml"}}cos(60deg){{/code}} 519 -\\{{code language="xml"}}cos(pi){{/code}}| 520 -{{code language="xml"}}0.5{{/code}} 521 -\\{{code language="xml"}}-1.0{{/code}}|Cosine (function-style, parentheses required) 522 -|tan|unary| 523 -{{code language="xml"}}tan(-45deg){{/code}} 524 -\\{{code language="xml"}}tan(45deg){{/code}}| 525 -{{code language="xml"}}-1.0{{/code}} 526 -\\{{code language="xml"}}1.0{{/code}}|((( 527 -Tangent (function-style, parentheses required) 524 +\\ 528 528 529 -Available from X4 v7.0 530 -))) 531 -|asin|unary| 532 -{{code language="xml"}}asin(-0.5f){{/code}} 533 -\\{{code language="xml"}}asin(1){{/code}}| 534 -{{code language="xml"}}-0.523599rad{{/code}} 535 -\\{{code language="xml"}}1.5708rad{{/code}}|((( 536 -Inverse sine (function-style, parentheses required) 537 537 538 -Available from X4 v7.0 539 -))) 540 -|acos|unary| 541 -{{code language="xml"}}acos(-0.5f){{/code}} 542 -\\{{code language="xml"}}acos(1.0f){{/code}}| 543 -{{code language="xml"}}2.0944rad{{/code}} 544 -\\{{code language="xml"}}0rad{{/code}}|((( 545 -Inverse cosine (function-style, parentheses required) 546 546 547 -Available from X4 v7.0 548 -))) 549 -|atan|unary| 550 -{{code language="xml"}}atan(1.0f){{/code}}| 551 -{{code language="xml"}}0.785398rad{{/code}}|((( 552 -Inverse tangent (function-style, parentheses required) 553 - 554 -Available from X4 v7.0 555 -))) 556 -|sqrt|unary|{{code language="xml"}}sqrt(2){{/code}}|{{code language="xml"}}1.414213LF{{/code}}|Square root (function-style, parentheses required) 557 -|exp|unary|{{code language="xml"}}exp(1){{/code}}|{{code language="xml"}}2.71828LF{{/code}}|Exponential function (function-style, parentheses required) 558 -|log|unary|{{code language="xml"}}log(8) / log(2){{/code}}|{{code language="xml"}}3.0LF{{/code}}|Natural logarithm (function-style, parentheses required) 559 -|^|binary|{{code language="xml"}}10 ^ 3{{/code}}|{{code language="xml"}}1000.0LF{{/code}}|Power 560 -|*|binary|{{code language="xml"}}21 * 2{{/code}}|{{code language="xml"}}42{{/code}}|Multiplication 561 -|/|binary|{{code language="xml"}}42 / 1042.0 / 10.0{{/code}}|{{code language="xml"}}44.2{{/code}}|Division 562 -|%|binary|{{code language="xml"}}42 % 10{{/code}}|{{code language="xml"}}2{{/code}}|Modulus (remainder of integer division) 563 -|+|binary| 564 -{{code language="xml"}}1 + 1{{/code}} 565 -\\{{code language="xml"}}'Hello' + ' world'{{/code}}| 566 -{{code language="xml"}}2{{/code}} 567 -\\{{code language="xml"}}'Hello world'{{/code}}| 568 -Addition 569 -\\String concatenation 570 -|-|binary|{{code language="xml"}}1 - 1{{/code}}|{{code language="xml"}}0{{/code}}|Subtraction 528 +|(%%)(% 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 529 +|(%%)(% 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 530 +|(%%)(% 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 531 +|(%%)(% 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 532 +|(%%)(% 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) 533 +|(%%)(% 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 534 +|(%%)(% 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 535 +|table[]|delimiter|{{code}}table[$foo='bar', {1+1}=40+2]{{/code}}|{{code}}table[$foo='bar', {2}=42]{{/code}}|[[Table>>MediaWiki.NULL]] of values 536 +|(%%)(% 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 537 +\\(Note: Braces are also used for [[property lookups>>MediaWiki.NULL]]) 538 +|(%%)(% 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) 539 +|(%%)(% 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 540 +|(%%)(% 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 541 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)typeof|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary| 542 +{{code}}typeof null{{/code}} 543 +\\{{code}}typeof 0{{/code}} 544 +\\{{code}}typeof 'Hello world'{{/code}}| 545 +{{code}}datatype.null{{/code}} 546 +\\{{code}}datatype.integer{{/code}} 547 +\\{{code}}datatype.string{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Yields the [[data type of the following sub-expression>>MediaWiki.NULL]] 548 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)sin|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary| 549 +{{code}}sin(30deg){{/code}} 550 +\\{{code}}sin(pi){{/code}}| 551 +{{code}}0.5{{/code}} 552 +\\{{code}}1.0{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Sine (function-style, parentheses required) 553 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)cos|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)unary| 554 +{{code}}cos(60deg){{/code}} 555 +\\{{code}}cos(pi){{/code}}| 556 +{{code}}0.5{{/code}} 557 +\\{{code}}0.0{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Cosine (function-style, parentheses required) 558 +|(%%)(% 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) 559 +|(%%)(% 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) 560 +|(%%)(% 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) 561 +|(%%)(% 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 562 +|(%%)(% 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 563 +|(%%)(% 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 564 +|(%%)(% 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) 565 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)+|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary| 566 +{{code}}1 + 1{{/code}} 567 +\\{{code}}'Hello' + ' world'{{/code}}| 568 +{{code}}2{{/code}} 569 +\\{{code}}'Hello world'{{/code}}| 570 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Addition(%%) 571 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)String concatenation 572 +|(%%)(% 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 571 571 | 572 -lt 573 -\\< (<)|binary| 574 -{{code language="xml"}}1 lt 3{{/code}}|{{code language="xml"}}true{{/code}}|Less than 574 +(% style="color: rgb(0,0,0);text-decoration: none;" %)lt(%%) 575 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)< (<)|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary| 576 +{{code}}1 lt 3{{/code}} 577 +\\{{code}}1 &lt; 3{{/code}}|{{code}}true{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Less than 575 575 | 576 -le 577 -\\<=|binary| 578 -{{code language="xml"}}1 le 3{{/code}}|{{code language="xml"}}true{{/code}}|Less than or equal to 579 +(% style="color: rgb(0,0,0);text-decoration: none;" %)le(%%) 580 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)<=|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary| 581 +{{code}}1 le 3{{/code}} 582 +\\{{code}}1 &lt;= 3{{/code}}|{{code}}true{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Less than or equal to 579 579 | 580 -gt 581 -\\> (>)|binary| 582 -{{code language="xml"}}1 gt 3{{/code}}|{{code language="xml"}}false{{/code}}|Greater than 584 +(% style="color: rgb(0,0,0);text-decoration: none;" %)gt(%%) 585 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)> (>)|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary| 586 +{{code}}1 gt 3{{/code}} 587 +\\{{code}}1 &gt; 3{{/code}}|{{code}}false{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Greater than 583 583 | 584 -ge 585 -\\>=|binary| 586 -{{code language="xml"}}1 ge 3{{/code}}|{{code language="xml"}}false{{/code}}|Greater than or equal to 587 -|((( 588 - 589 -)))|binary|{{code language="xml"}}1 + 1 == 2.0{{/code}}|{{code language="xml"}}true{{/code}}|Equal to 590 -|~!=|binary|{{code language="xml"}}1 + 1 != 2.0{{/code}}|{{code language="xml"}}false{{/code}}|Not equal to 591 -|and|binary|{{code language="xml"}}true and false{{/code}}|{{code language="xml"}}false{{/code}}|Logical AND (short-circuit semantics) 592 -|or|binary|{{code language="xml"}}true or false{{/code}}|{{code language="xml"}}true{{/code}}|Logical OR (short-circuit semantics) 589 +(% style="color: rgb(0,0,0);text-decoration: none;" %)ge(%%) 590 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)>=|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)binary| 591 +{{code}}1 ge 3{{/code}} 592 +\\{{code}}1 &gt;= 3{{/code}}|{{code}}false{{/code}}|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Greater than or equal to 593 +|(%%)(% 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 594 +|(%%)(% 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 595 +|(%%)(% 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) 596 +|(%%)(% 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) 593 593 | 594 594 if ... then ... 595 595 \\if ... then ... else ...|ternary| 596 -{{code language="xml"}}if 1 == 2 then 'F'{{/code}} 597 -\\{{code language="xml"}}if 1 == 2 then 'F' else 'T'{{/code}}| 598 -{{code language="xml"}}null{{/code}} 599 -\\{{code language="xml"}}'T'{{/code}}|Conditional operator ("inline if") 600 +{{code}}if 1 == 2 then 'F'{{/code}} 601 +\\{{code}}if 1 == 2 then 'F' else 'T'{{/code}}| 602 +{{code}}null{{/code}} 603 +\\{{code}}'T'{{/code}}|Conditional operator ("inline if") 604 + 605 + 606 +\\ 607 + 608 + 600 600 ))) 601 601 602 - ===Operator===611 +(% id="operator-precedence-rules" %) 603 603 604 - Youcangroupsub-expressions using parentheses, but ifyou don't, thefollowing orderof operations is applied, sothat 5-1+2*3 == 10 as you wouldxpect. Theorder is the same asinthe table above,but there are operatorswith the sameprecedence- these are appliedfrom left to right.613 +=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Operator precedence rules(%%) === 605 605 606 -* Unary operators: +, -, not, typeof, function-style operators (highest precedence) 607 -* Power operator: ^ 608 -* Multiplicative: *, /, % 609 -* Additive: +, - 610 -* Comparison: lt, le, gt, ge 611 -* Equality: ==, != 612 -* and 613 -* or 614 -* if/then/else (lowest precedence) 615 +(% 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. 615 615 616 -=== Type conversion === 617 617 618 -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: 618 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Unary operators: +, -, not, typeof, function-style operators (highest precedence) 619 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Power operator: ^ 620 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Multiplicative: *, /, % 621 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Additive: +, - 622 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Comparison: lt, le, gt, ge 623 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Equality: ==, != 624 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)and 625 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)or 626 +* if/then/else(% style="color: rgb(0,0,0);text-decoration: none;" %) (lowest precedence) 619 619 620 -* Null and something else: The null value will be interpreted as "0" of the other type. 621 -* Two non-unit integers: The result will be an integer of the largest involved type. 622 -* Two non-unit numbers, not all integers: The result will be the largest involved float type. 623 -* Non-unit and unit: The result will be the unit type. 624 -* Two different units: The types are incompatible. This is an error, the result is undefined. 628 +(% id="type-conversion" %) 625 625 626 - Formultiplicationand division,this maynot be intuitive in all cases: Dividing alength by anotherlength results in a length-sof you wanttohavea simplefloat as a result, you will have toconvertit manually.630 +=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Type conversion(%%) === 627 627 628 - Thereisaway toconvertanumberintoadifferent typemanually:Youappendthecorresponding suffixto asub-expressionin parentheses,like this:632 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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: 629 629 630 -* {{code language="xml"}}(1 + 1)f{{/code}}⟹ {{code language="xml"}}2f{{/code}} ⟹ {{code language="xml"}}2.0{{/code}} 631 -* {{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}} 634 +* (% 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. 635 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Two non-unit integers: The result will be an integer of the largest involved type. 636 +* (% 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. 637 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Non-unit and unit: The result will be the unit type. 638 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Two different units: The types are incompatible. This is an error, the result is undefined. 632 632 633 - Whenconvertingto anon-defaultunittype, this meansyouinterpretthe numberasinthegivenunits:"{{code language="xml"}}(1km+500m)h{{/code}}"meansthatyouinterpret1500mas1500 hours,sotheresultingvaluewillbe1500x3600seconds. (As stated above,thedefault unitforalength is metres.)640 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 634 634 635 - Thedivisionoperationwill be anintegerdivision(roundingtowardszero)if both operandsareintegers(seetheexamplein thetableabove). So if youwantto geta floatingpointresult,you havetomakesurethat at leastoneoftheoperandsis a floatingpointtype.642 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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: 636 636 637 -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: 644 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}(1 + 1)f{{/code}} Γƒ╣ {{code}}2f{{/code}} Γƒ╣ {{code}}2.0{{/code}} 645 +* (% 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}} 638 638 639 -* {{code language="xml"}}'One plus one is equal to ' + (1+1) + '.'{{/code}}⟹ {{code language="xml"}}'One plus one is equal to 2.'{{/code}} 640 -* {{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}} 647 +(% 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.) 641 641 642 - Asyoucansee,operators of thesameprecedence(+in thiscase) are alwaysevaluatedfromleft to right.649 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 643 643 651 +(% 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: 644 644 645 -=== Boolean operators === 653 +* (% 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}} 654 +* (% 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}} 646 646 647 - Someadditionalnotes onBoolean operators(such as and,or, not,==):656 +(% style="color: rgb(0,0,0);text-decoration: none;" %)As you can see, operators of the same precedence (+ in this case) are always evaluated from left to right. 648 648 649 -* Of course a Boolean operation always results in true or false (integer 1 or 0). 650 -* 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**. 651 -* != 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. 652 -* "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 653 -** Example:{{code language="xml"}} false and $foo{{/code}} ⟹ {{code language="xml"}}false{{/code}} (the value of $foo is not checked at all) 654 -* 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. 655 -* <, <=, >, >= 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. 658 +(% id="boolean-operators" %) 656 656 657 -== (% id="categorybroken_macroanchorstrings-and-formatting" %)Stringsandformatting(%%) ==660 +=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Boolean operators(%%) === 658 658 659 - Youcan concatenatestringliterals usingthe+operator,butthere isalsoa printf-likeformattingsyntax,whichis easierto use thanconcatenatinglotsof small pieces:662 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Some additional notes on Boolean operators (such as and, or, not, ==): 660 660 661 -* {{code language="xml"}}'The %1 %2 %3 jumps over the %5 %4'.['quick', 'brown', 'fox', 'dog', 'lazy']{{/code}} 662 -* {{code language="xml"}}'%1 + %2 = %3'.[$a, $b, $a + $b]{{/code}} 663 663 664 -See also the section about [[value properties>>doc:||anchor="HValueproperties" style="outline-width: 0px !important; user-select: auto !important;"]]. 665 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Of course a Boolean operation always results in true or false (integer 1 or 0). 666 +* (% 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;" %). 667 +* (% 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. 668 +* (% 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 669 +** 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) 670 +* (% 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. 671 +* (% 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. 665 665 666 -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'. 667 -\\To get a percent character in the result string, use '%%' in the format string. 668 -\\\\\\If you need a more sophisticated method for text substitution, try **<substitute_text>**. See the XML schema documentation for this script action. 669 -\\**[New as of X Rebirth 4.0]** 670 -\\ 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): 673 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 671 671 672 -* {{code language="xml"}}'%,s'.[12345678]{{/code}}⟹ {{code language="xml"}}'12,345,678'{{/code}} (the "," modifier shows a number with thousands separators, correctly localised) 673 -* {{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) 674 -* {{code language="xml"}}'%,.1s'.[12345.67]'{{/code}}⟹ {{code language="xml"}}'12,345.7'{{/code}} (combination of the above) 675 675 676 +(% id="categorybroken_macroanchorstrings-and-formatting" %)(%%) 677 +~== (% style="color: rgb(0,0,0);text-decoration: none;" %)Strings and formatting 678 +\\(%%) == 679 + 680 +(% 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: 681 + 682 +* {{code}}'The %1 %2 %3 jumps over the %5 %4'.['quick', 'brown', 'fox', 'dog', 'lazy']{{/code}} 683 +* {{code}}'%1 + %2 = %3'.[$a, $b, $a + $b]{{/code}} 684 + 685 +(% style="color: rgb(0,0,0);text-decoration: none;" %)See also the section about [[value properties>>MediaWiki.NULL]]. 686 + 687 +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'. 688 + 689 +To get a percent character in the result string, use '%%' in the format string. 690 + 691 + 692 +(% 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. 693 + 694 +**[New as of X Rebirth 4.0]** 695 + 696 +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): 697 + 698 +* {{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) 699 +* {{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) 700 +* {{code}}'%,.1s'.[12345.67]'{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) {{code}}'12,345.7'{{/code}} (combination of the above) 701 + 676 676 Additional remarks: 677 677 678 678 * The "," and "." formatting modifiers only apply to numbers. They are ignored if used on values of other types. 679 -* 705 +* ┬áIf "," is used without "." then any fractional digits are discarded. 680 680 * "." 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). 681 681 682 -{{info}} 683 -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. 684 -{{/info}} 685 685 686 -== Lists == 687 687 688 - Another examplefora non-numeric value islist: It is an orderedcollection of otherarbitrary values (calledarray or vectorin other languages). Itcan be constructedwithinan expressionusing the[[~[~] syntax>>doc:||anchor="HOperators"]].It may alsobe generated byspecialactions andconditions,andthere are actionsthat can[[insertor remove values>>doc:||anchor="HCreatingandremovingvariables"style="outline-width:0px !important;user-select:auto!important;"]].710 +{{info body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">There are also special methods to [[NULL|format money values and time values]] using the "formatted" property.</span>"/}} 689 689 690 -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 "[ ]". 691 691 692 -{{info}} 693 -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." 694 -{{/info}} 695 695 696 - Listsarestored in variables as references, somultiple variables can refer tothe same **shared list**:If you change a shared list through a variable,e.g. by changingthevalue of an element, you changeit as well forll other variables. However, the operators == and!= canalsobe used ontwo distinct lists to comparetheir elements.714 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 697 697 698 -{{info}} 699 -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. 700 700 701 - Badusage attemptingtove the last element of the list: <remove_from_listname="$List"exact="$List.{$List.count}"/>717 +(% id="categorybroken_macroanchorlists" %) 702 702 703 -If you know the index, simply use <remove_value/> e.g. <remove_value name="$List.{$List.count}"/> 704 -{{/info}} 719 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Lists(%%) == 705 705 721 +(% 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]]. 722 + 723 +(% 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 ΓÇ£[ ]ΓÇ¥. 724 + 725 +{{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>"/}} 726 + 727 + 728 + 729 +(% 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. 730 + 731 +{{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. 732 + 733 +Bad usage attempting to remove the last element of the list: <remove_from_list name="$List" exact="$List.{$List.count}"/> 734 + 735 +If you know the index, simply use <remove_value/> e.g. <remove_value name="$List.{$List.count}"/>"/}} 736 + 737 + 738 + 739 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 740 + 741 + 706 706 (% id="categorybroken_macroanchortables" %) 707 -== Tables == 708 708 709 - Tablesare associative arrays - they are like lists, but you can assign values to(almost)arbitrary keys, notjust 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 accessthe contents of a table. [[Creating andremoving 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 valueto a table key. If the key doesnot exist yet, it will be created.744 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Tables(%%) == 710 710 711 - Almost all values are allowed as table keys,but there are afew exceptions:746 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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>>MediaWiki.NULL]]. See the section about [[value properties>>MediaWiki.NULL]] for how to access the contents of a table. [[Creating and removing entries>>MediaWiki.NULL]] 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. 712 712 713 -* Strings must start with '$', like variables 714 -* null cannot be used as table key (but the number 0 is valid) 715 -* Lists, tables, groups, buildplans, loadouts and constructionsequences cannot be used as table keys 716 716 717 - These restrictionsonlyapply tothe keys,thereareno restrictionsforvalues thatyou assigntothem.For example:749 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Almost all values are allowed as table keys, but there are a few exceptions: 718 718 719 -* {{code language="xml"}}table[]{{/code}}⟹ creates an empty table 720 -* {{code language="xml"}}table[{0} = null]{{/code}}⟹ creates a table that maps the number 0 to null 751 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Strings must start with '$', like variables 752 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)null cannot be used as table key (but the number 0 is valid) 753 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Lists, tables, groups and buildplans cannot be used as table keys 754 +\\ 721 721 722 -* {{code language="xml"}}table[{'$foo'} = 'bar']{{/code}}⟹ a table that maps the string '$foo' to the string 'bar' 723 -* {{code language="xml"}}table[$foo = 'bar']{{/code}}⟹ exactly the same, just a shorter notation for string keys 724 -* {{code language="xml"}}table[foo = 'bar']{{/code}}⟹ error, 'foo' does not start with a '$' 725 -* {{code language="xml"}}table[{1} = [], {2} = table[]] {{/code}}⟹ a table that maps 1 to an empty list and 2 to an empty table 726 -* {{code language="xml"}}table[faction.argon = 'bar']{{/code}}⟹ error, the expression faction.argon will not be resolved into a key value. Requires { } braces. 727 -* {{code language="xml"}}table[{faction.argon} = 'bar'] {{/code}}⟹ a table that maps the value faction.argon to the string 'bar' 756 +(% 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: 728 728 729 -Just like lists, tables are stored as references, so it's possible that multiple variables reference the same table (see above). 758 +* (% 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 759 +* (% 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 730 731 -== Value properties == 732 732 733 -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. 734 734 735 -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. 736 736 737 -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: 764 +* (% 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' 765 +* (% 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 766 +* (% 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 '$' 767 +* (% 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 738 739 -* 1 ⟹ 42 740 -* 2 ⟹ null 741 -* 3 ⟹ 'text' 742 -* 'count' ⟹ 3 743 743 744 - Asyoucansee, a propertykeycanbe anumber or atring. Actuallythereisnorestrictionregardingthedatatype of thekey.770 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Just like lists, tables are stored as references, so it's possible that multiple variables reference the same table (see above). 745 745 746 -You can look up a property by appending a dot and the key in curly braces: 747 747 748 -* {{code language="xml"}}[100, 200, 300, 400].{1}{{/code}}⟹ 100 (reading the first element) 749 -* {{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) 750 -* {{code language="xml"}}[].{'count'}{{/code}}⟹ 0 751 -* {{code language="xml"}}table[{21} = 42].{21}{{/code}}⟹ 42 773 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 752 752 753 -In most cases the property key is a fixed string, like "name" or "class". You can write this like above: 754 754 755 -* {{code language="xml"}}[42].{'count'}{{/code}} 756 -* {{code language="xml"}}$ship.{'name'}{{/code}} 757 -* {{code language="xml"}}$ship.{'class'}{{/code}} 758 -* {{code language="xml"}}table[$foo='bar'].{'$foo'}{{/code}} 776 +(% id="categorybroken_macroanchorvalue-properties" %) 759 759 760 - Butitisasierjustwritethe property key without braces,which is equivalent:778 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Value properties(%%) == 761 761 762 -* {{code language="xml"}}[0].count{{/code}} 763 -* {{code language="xml"}}$ship.name{{/code}} 764 -* {{code language="xml"}}$ship.class{{/code}} 765 -* {{code language="xml"}}table[$foo='bar'].$foo{{/code}} 780 +(% 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. 766 766 767 -( Inthis case,$shipisaable.Allvariablesstartwitha"$",so theycannot beconfusedwithkeywords.)782 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 768 768 769 - Alisthas evenmore properties:784 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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: 770 770 771 -**random'** returns a randomly chosen element (which requires that the list is non-empty) 786 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)1 Γƒ╣ 42 787 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)2 Γƒ╣ null 788 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)3 Γƒ╣ 'text' 789 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)'count' Γƒ╣ 3 772 772 773 - **min'**and'**max'**returntheminimum ormaximum(all elementshave tobenumeric)791 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 774 774 775 - *{{codelanguage="xml"}}[1,6,8].min{{/code}}⟹1793 +(% style="color: rgb(0,0,0);text-decoration: none;" %)You can look up a property by appending a dot and the key in curly braces: 776 776 777 -**average'** returns the average (but all element types have to be compatible) 795 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[100, 200, 300, 400].{1}{{/code}} Γƒ╣ 100 (reading the first element) 796 +* (% 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) 797 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[].{'count'}{{/code}} Γƒ╣ 0 798 +* (% 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 778 779 -* {{code language="xml"}}[1, 6, 8].average{{/code}}⟹ 5 780 780 781 - **indexof'**isfollowedby another property,andtheindexof thefirstoccurence ofthatkey inthelistsreturned,or0 if it'snotin thelist801 +(% style="color: rgb(0,0,0);text-decoration: none;" %)In most cases the property key is a fixed string, like ΓÇ£nameΓÇ¥ or ΓÇ£classΓÇ¥. You can write this like above: 782 782 783 -* {{code language="xml"}}[1, 6, 8].indexof.{8}{{/code}}⟹ 3 803 +* {{code}}[42].{'count'}{{/code}} 804 +* {{code}}$ship.{'name'}{{/code}} 805 +* {{code}}$ship.{'class'}┬á{{/code}} 806 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[$foo='bar'].{'$foo'}{{/code}} 807 +\\ 784 784 785 - **clone'**createsashallowcopyofthelist(i.e. liststhat arecontainedaselementsinthelistarenot copied,only thereferenceto them)809 +(% style="color: rgb(0,0,0);text-decoration: none;" %)But it is easier just to write the property key without braces, which is equivalent: 786 786 787 -* {{code language="xml"}}[1, 6, 8].clone{{/code}}⟹ {{code language="xml"}}[1, 6, 8]{{/code}} 811 +* {{code}}[0].count{{/code}} 812 +* {{code}}$ship.name{{/code}} 813 +* {{code}}$ship.class{{/code}} 814 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}table[$foo='bar'].$foo{{/code}} 815 +\\ 788 788 789 - Atable hasdifferentproperties:817 +(% style="color: rgb(0,0,0);text-decoration: none;" %)(In this case, $ship is a variable. All variables start with a ΓÇ£$ΓÇ¥, so they cannot be confused with keywords.) 790 790 791 -* '**clone'** creates a shallow copy of the table 792 -* '**keys'** allows you to access data about the table's keys 819 +(% style="color: rgb(0,0,0);text-decoration: none;" %)A list has even more properties: 793 793 794 - However,'keys' alonewill notgiveyouaresult.'keys'mustbefollowedbyanotherkeywordto retrievethedesiredinformation,forexample:821 +(% 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 chosen element (which requires that the list is non-empty) 795 795 823 +(% 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) 796 796 825 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[1, 6, 8].min{{/code}} Γƒ╣ 1 797 797 798 - *{{codelanguage="xml"}}$table.keys.list{{/code}}:Yieldsalist ofallkeysinthetable(reliably sortedbykey ifallkeys arenumeric)827 +(% 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 (but all element types have to be compatible) 799 799 800 -* {{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) 801 -* {{code language="xml"}}$table.keys.random{{/code}}: A randomly chosen key (which requires that the table is non-empty) 829 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[1, 6, 8].average{{/code}} Γƒ╣ 5 802 802 803 -{{info}} 804 -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'.{[...]}. 805 -{{/info}} 831 +(% 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 806 806 807 - ===(%id="lookup-tests-and-suppressing-errors" %)Lookup testsandsuppressingerrors(%%)===833 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[1, 6, 8].indexof.{8}{{/code}} Γƒ╣ 3 808 808 809 - Ifyoulookup a property thatdoesnotexist, therewillbeanerror,andtheresultwill beull.Totestwhetherapropertyexists,you canappend aquestionmark"?" tohelookup, which yieldstrue orfalse:835 +(% 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;" %)' 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) 810 810 811 -* {{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 812 -* {{code language="xml"}}$list.{5}?{{/code}}⟹ true if $list exists and has the property 5, false otherwise 813 -* {{code language="xml"}}$table.$key?{{/code}}⟹ Analogously, true if $table exists and has the string property '$key' 837 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}[1, 6, 8].clone{{/code}} Γƒ╣ {{code}}[1, 6, 8]{{/code}} 814 814 815 - Thequestion markcaneven be appliedtovariables:839 +(% style="color: rgb(0,0,0);text-decoration: none;" %)A table has different properties: 816 816 817 -* {{codelanguage="xml"}}$list{{/code}}⟹ The value storedunderhename$list,or anerrorif thereis no such variable818 -* {{codelanguage="xml"}}$list?{{/code}}⟹trueifthevariable exists,false otherwise841 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)'**clone'** creates a shallow copy of the table 842 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)'**keys'** allows you to access data about the table's keys 819 819 820 - Tolookupthevaluefaproperty althoughitmaynotexist,youcanuse theat-sign"@"asprefix:844 +(% style="color: rgb(0,0,0);text-decoration: none;" %)However, 'keys' alone will not give you a result. 'keys' must be followed by another keyword to retrieve the desired information, for example: 821 821 822 -* {{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) 823 -* {{code language="xml"}}@$list{{/code}}⟹ The list if this variable exists, null otherwise 824 -* {{code language="xml"}}@$list.{5}.{1}{{/code}}⟹ The first element of the fifth element of $list, if it exists, null otherwise 825 825 826 -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. 847 +* (% 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) 848 +\\ 849 +* (% 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) 850 +* (% 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 827 828 -=== Static lookups === 829 829 830 -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. 831 831 832 - Hereare afewenumerationclasses andcorresponding examplelookupvalues:854 +{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">The string formatting syntax that you have seen [[NULL|above]] 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'.{[...]}.</span>"/}} 833 833 856 + 857 + 858 +(% id="lookup-tests-and-suppressing-errors" %)(%%) 859 +~=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Lookup tests and suppressing errors 860 +\\(%%) === 861 + 862 +(% 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: 863 + 864 +* (% 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 865 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$list.{5}?{{/code}} Γƒ╣ true if $list exists and has the property 5, false otherwise 866 +* (% 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' 867 + 868 + 869 +(% style="color: rgb(0,0,0);text-decoration: none;" %)The question mark can even be applied to variables: 870 + 871 +* (% 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 872 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$list?{{/code}} Γƒ╣ true if the variable exists, false otherwise 873 + 874 +(% 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: 875 + 876 +* (% 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) 877 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}@$list{{/code}} Γƒ╣ The list if this variable exists, null otherwise 878 +* (% 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 879 + 880 +(% 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. 881 + 882 +\\ 883 + 884 +(% id="static-lookups" %) 885 + 886 +=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Static lookups(%%) === 887 + 888 +(% 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. 889 + 890 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Here are a few enumeration classes and corresponding example lookup values: 891 + 834 834 (% style="margin-left: 0.0px;" %) 835 835 ((( 836 -|Data type (= value name)|Examples|Description 837 -|class| 838 -class.ship 839 -\\class.ship_xl 840 -\\class.space 841 -\\class.weapon|Component classes 842 -|purpose| 843 -purpose.combat 844 -\\purpose.transportation|Purposes 845 -|killmethod| 846 -killmethod.hitbybullet 847 -\\killmethod.hitbymissile|Ways to die (already used before destruction) 848 -|datatype| 849 -datatype.float 850 -\\datatype.component 851 -\\datatype.class 852 -\\datatype.datatype|Script value datatypes 853 -|profile| 854 -profile.flat 855 -\\profile.increasing 856 -\\profile.bell|Probability distribution profile (see [[random ranges>>doc:||anchor="HRandomranges" style="outline-width: 0px !important; user-select: auto !important;"]]) 857 -|cuestate| 858 -cuestate.waiting 859 -\\cuestate.active 860 -\\cuestate.complete|[[Cue states>>||anchor="HCues" style="outline-width: 0px !important; user-select: auto !important;"]] 861 -|level| 862 -level.easy 863 -\\level.medium 864 -\\level.veryhard|Mission difficulty levels (comparable with each other using lt, gt, etc.) 865 -|attention| 866 -attention.insector 867 -\\attention.visible 868 -\\attention.adjacentzone|Attention levels (comparable with each other using lt, gt, etc.) 869 -|ware| 870 -ware.ore 871 -\\ware.silicon|Wares 872 -|race| 873 -race.argon 874 -\\race.boron|Races 875 -|faction| 876 -faction.player 877 -\\faction.argongovernment|Factions 878 -))) 894 +\\ 879 879 880 -{{id name="typeof"/}} 881 881 882 -{{info}} 883 -With the ''typeof'' operator you can get the datatype of any expression and compare it with what you expect, for example: 884 884 898 +|(%%)(% 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 899 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)class| 900 +(% style="color: rgb(0,0,0);text-decoration: none;" %)class.ship(%%) 901 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)class.ship_xl(%%) 902 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)class.space(%%) 903 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)class.weapon|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Component classes 904 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)purpose| 905 +(% style="color: rgb(0,0,0);text-decoration: none;" %)purpose.combat(%%) 906 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)purpose.transportation|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Purposes 907 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)killmethod| 908 +(% style="color: rgb(0,0,0);text-decoration: none;" %)killmethod.hitbybullet(%%) 909 +\\(% 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) 910 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)datatype| 911 +(% style="color: rgb(0,0,0);text-decoration: none;" %)datatype.float(%%) 912 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)datatype.component(%%) 913 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)datatype.class(%%) 914 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)datatype.datatype|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Script value datatypes 915 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)profile| 916 +(% style="color: rgb(0,0,0);text-decoration: none;" %)profile.flat(%%) 917 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)profile.increasing(%%) 918 +\\(% 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]]) 919 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)cuestate| 920 +(% style="color: rgb(0,0,0);text-decoration: none;" %)cuestate.waiting(%%) 921 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)cuestate.active(%%) 922 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)cuestate.complete|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)[[Cue states>>MediaWiki.NULL]] 923 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)level| 924 +(% style="color: rgb(0,0,0);text-decoration: none;" %)level.easy(%%) 925 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)level.medium(%%) 926 +\\(% 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.) 927 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)attention| 928 +(% style="color: rgb(0,0,0);text-decoration: none;" %)attention.insector(%%) 929 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)attention.visible(%%) 930 +\\(% 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.) 931 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)ware| 932 +(% style="color: rgb(0,0,0);text-decoration: none;" %)ware.ore(%%) 933 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)ware.silicon|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Wares 934 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)race| 935 +(% style="color: rgb(0,0,0);text-decoration: none;" %)race.argon(%%) 936 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)race.boron|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Races 937 +|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)faction| 938 +(% style="color: rgb(0,0,0);text-decoration: none;" %)faction.player(%%) 939 +\\(% style="color: rgb(0,0,0);text-decoration: none;" %)faction.argongovernment|(%%)(% style="color: rgb(0,0,0);text-decoration: none;" %)Factions 940 +))) 941 + 942 +{{note body="[[Category:Broken_macro/anchor]]With the ''typeof'' operator you can get the datatype of any expression and compare it with what you expect, for example: 943 + 885 885 <code>typeof $value == datatype.faction</code> 886 886 887 -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:946 +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 888 889 -<code>(typeof $value).isstring</code>" 890 -{{/info}} 948 +<code>(typeof $value).isstring</code>"/}} 891 891 892 -{{info}} 893 -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." 894 -{{/info}} 950 +{{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>"/}} 895 895 896 - ===Playerproperties===952 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 897 897 898 -You can access many player-related game properties via the keyword "player": 899 899 900 -* player.**name**: The player's name 901 -* player.**age**: The passed in-game time since game start 902 -* player.**money**: The money in the player's account 903 -* player.**ship**: The ship the player is currently on (not necessarily the player's ship), or null if the player is on a station 955 +(% id="player-properties" %) 904 904 905 -* player.**primaryship**: The player's own ship (but the player is not necessarily on board) 906 -* player.**entity**: The actual player object 957 +=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Player properties(%%) === 907 907 908 -* player.**zone**, player.**sector**, player.**cluster**, player.**galaxy**: Location of the player entity 909 -* player.**copilot**: The co-pilot NPC 959 +(% style="color: rgb(0,0,0);text-decoration: none;" %)You can access many player-related game properties via the keyword ΓÇ£playerΓÇ¥: 910 910 961 +* (% 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 962 +* (% 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 963 +* (% 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 964 +* (% 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 965 +\\ 966 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)player.**primaryship**: The player's own ship (but the player is not necessarily on board) 967 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)player.**entity**: The actual player object 968 +\\ 969 +* (% 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 970 +* (% 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 971 + 911 911 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. 912 912 913 - ===Safe===974 +(% id="safe-properties" %) 914 914 915 - Mostpropertiescause errorsif you use them on non-existingobjects, suchas destroyed ships. There are a few exceptions:976 +=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Safe properties(%%) === 916 916 917 -* exists 918 -* isoperational 919 -* iswreck 920 -* isconstruction 921 -* available 922 -* isclass.(...) 978 +(% 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: 923 923 924 -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. 980 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)exists 981 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)isoperational 982 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)iswreck 983 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)isconstruction 984 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)available 985 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)isclass.(...) 925 925 926 - ===(%id="categorybroken_macroanchormoney-and-time-formatting"%)Money and timeformatting(%%)===987 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 927 927 928 -**[New as of X Rebirth 4.0]** 929 -\\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. 989 +(% id="categorybroken_macroanchormoney-and-time-formatting" %)(%%) 990 +~=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Money and time formatting 991 +\\(%%) === 930 930 931 -* {{code language="xml"}}$money.formatted.{'formatstring'}{{/code}} 932 -* {{code language="xml"}}$money.formatted.default{{/code}}(using default format string '%s') 993 +(% style="color: rgb(0,0,0);text-decoration: none;" %)**[New as of X Rebirth 4.0]** 933 933 934 -* {{code language="xml"}}$time.formatted.{'formatstring'}{{/code}} 935 -* {{code language="xml"}}$time.formatted.default{{/code}}(using default format string '%T') 995 +(% 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. 936 936 937 -In scripts, money is stored in cents, not Credits. The formatted representation always shows the value in Credits, including thousands separators. 997 +* {{code}}$money.formatted.{'formatstring'}┬á{{/code}} 998 +* (% style="color: rgb(0,0,0);text-decoration: none;" %){{code}}$money.formatted.default{{/code}} (using default format string '%s') 999 +\\ 1000 +* {{code}}$time.formatted.{'formatstring'}{{/code}} 1001 +* {{code}}$time.formatted.default{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á(%%) (using default format string '%T') 938 938 939 - Whenformatting the moneyvalue, any specifier (such as '%s')intheformatstringis replacedbythemoneyvalue,sousuallythe formatstringonlyconsists ofthisonespecifier. The following modifiers can beusedbetween'%'andthe specifiercharacter,to enableformatting options:1003 +(% style="color: rgb(0,0,0);text-decoration: none;" %)In scripts, money is stored in cents, not Credits. The formatted representation always shows the value in Credits, including thousands separators. 940 940 1005 +(% 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: 1006 + 1007 + 941 941 |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.) 942 942 |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'. 943 943 |.|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) 944 944 |_|Spaces|An underscore adds trailing spaces to the result string for better right-aligned display in a tabular layout. 945 945 946 -By default, these options are disabled. 1013 +(% style="color: rgb(0,0,0);text-decoration: none;" %)By default, these options are disabled. 947 947 948 -More available specifiers (in addition to %s): 1015 +(% style="color: rgb(0,0,0);text-decoration: none;" %)More available specifiers (in addition to %s): 949 949 950 -* %k: Credits (truncated) in kilo format 951 -* %M: Credits (truncated) in Mega format 952 -* %G: Credits (truncated) in Giga format 953 -* %T: Credits (truncated) in Tera format 954 -* %Cr: Localised "Cr" string 955 -* %%: A % sign 1017 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)%k: Credits (truncated) in kilo format 1018 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)%M: Credits (truncated) in Mega format 1019 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)%G: Credits (truncated) in Giga format 1020 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)%T: Credits (truncated) in Tera format 1021 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)%Cr: Localised "Cr" string 1022 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)%%: A % sign 1023 +\\ 956 956 957 -Examples: 1025 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Examples: 958 958 959 -* {{code language="xml"}}(1234Cr).formatted.{'%s'}{{/code}}⟹{{code language="xml"}}'1,234'{{/code}} 960 -* {{code language="xml"}}(1234Cr).formatted.default{{/code}}⟹{{code language="xml"}}'1,234'{{/code}} (same as {'%s'}) 961 -* {{code language="xml"}}(1234Cr).formatted.{'%.s %Cr'}{{/code}}⟹{{code language="xml"}}'1,234.00 Cr'{{/code}} 962 -* {{code language="xml"}}(1234Cr).formatted.{'%1s'}{{/code}}⟹{{code language="xml"}}'1 k'{{/code}} (rounding towards zero) 963 -* {{code language="xml"}}(1234Cr).formatted.{'%cM'}{{/code}}⟹{{code language="xml"}}'0 M'{{/code}} 964 964 965 -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;"]]. 1028 +* {{code}}(1234Cr).formatted.{'%s'}{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣{{code}}'1,234'{{/code}} 1029 +* {{code}}(1234Cr).formatted.default{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣{{code}}'1,234'{{/code}}(%%) (same as {'%s'}) 1030 +* {{code}}(1234Cr).formatted.{'%.s %Cr'}{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣{{code}}'1,234.00 Cr'{{/code}} 1031 +* {{code}}(1234Cr).formatted.{'%1s'}{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣{{code}}'1 k'{{/code}}(%%) (rounding towards zero) 1032 +* {{code}}(1234Cr).formatted.{'%cM'}{{/code}}(% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣{{code}}'0 M'{{/code}} 966 966 1034 +For documentation of time format strings, see the Lua function ConvertTimeString() in the [[MediaWiki.ARCHIVE.XRWIKIModding_supportUI_Modding_supportLua_function_overview]]. 1035 + 967 967 Examples: 968 968 969 -* {{code language="xml"}}(151s).formatted.{'%T'}{{/code}}⟹{{codelanguage="xml"}}'00:02:31'{{/code}}970 -* {{code language="xml"}}(151s).formatted.default{{/code}}⟹{{codelanguage="xml"}}'00:02:31'{{/code}} (same as {'%T'})971 -* {{code language="xml"}}(151s).formatted.{'%.3T'}{{/code}}⟹{{codelanguage="xml"}}'00:02:31.000'{{/code}}972 -* {{code language="xml"}}(151s).formatted.{'%h:%M'}{{/code}}⟹{{codelanguage="xml"}}'0:02'{{/code}}1038 +* {{code}}(151s).formatted.{'%T'}{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) {{code}}'00:02:31'{{/code}} 1039 +* {{code}}(151s).formatted.default{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) {{code}}'00:02:31'{{/code}} (same as {'%T'}) 1040 +* {{code}}(151s).formatted.{'%.3T'}{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) {{code}}'00:02:31.000'{{/code}} 1041 +* {{code}}(151s).formatted.{'%h:%M'}{{/code}} (% style="color: rgb(0,0,0);text-decoration: none;" %)Γƒ╣(%%) {{code}}'0:02'{{/code}} 973 973 974 - ===Complete===1043 +(% id="complete-property-documentation" %) 975 975 976 - Toaccessthescriptpropertydocumentation that is included in the game, youcan 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 theHTML file __scriptproperties.html__ inthe game's root folder, and all files in the"libraries"sub-folder. For resolvingtextreferences in the browserautomatically,alsoxtract0001-L044.xmlinthe "t" sub-folder.1045 +=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Complete property documentation(%%) === 977 977 978 -The r awdocumentationdata is located in libraries/scriptproperties.xml,butitis recommendedto openscriptproperties.html inabrowser.1047 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 979 979 980 -{{info}} 981 -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: 1049 +(% 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. 982 982 983 -* Firefox: On the about:config page, the value of "security.fileuri.strict_origin_policy" has to be changed to "false". 984 -* Chrome: The Chrome launcher has to be started with the command-line parameter --~-~---allow-file-access-from-files 985 -{{/info}} 986 986 987 - This providesyou with a complete list ofallsupported"basekeywords" andproperties.Tofilterinthislist,youcanenteranexpression inthext field:1052 +{{note body="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: 988 988 989 -* Enter the beginning of a base keyword 990 -* Enter $ followed by the data type you are looking for (e.g. "$ship"), as if it were a variable 991 -* To see the properties of a base keyword or data type, enter a dot (".") 992 -* After the dot, you can enter a property name 993 -* You can also enter a dot (".") as first character to search globally for a property 1054 +* Firefox: On the about:config page, the value of "security.fileuri.strict_origin_policy" has to be changed to "false". 1055 +* Chrome: The Chrome launcher has to be started with the command-line parameter --allow-file-access-from-files"/}} 994 994 995 -{{info}} 996 -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. 997 -{{/info}} 998 998 999 -= MD refreshing and patching = 1000 1000 1001 - Whenasaved game isloaded,thesaved MD stateisrestored,but also all MD filesare reloaded and changesinthemareappliedto theMDstate.Thisis called"refresh". It is alsopossible torefreshtheMDat run-time using thecommand"refreshmd"onthe in-gamecommand line. This isaconvenientwayto updateMDscriptswhilethegame is already running.1059 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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: 1002 1002 1003 -== Details and restrictions == 1061 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Enter the beginning of a base keyword 1062 +* (% 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 1063 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)To see the properties of a base keyword or data type, enter a dot (ΓÇ£.ΓÇ¥) 1064 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)After the dot, you can enter a property name 1065 +* (% 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 1004 1005 - Herearesome noteworthyfacts aboutrefreshing scriptsand cues, andthe restrictions:1067 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 1006 1006 1007 -* 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). 1008 -* 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. 1009 -** (!) Pitfall: It is recommended that cues are not removed if they were previously released in public builds, to prevent future cues with the same name leading to errors (see example below). Instead they can be emptied and marked as deprecated. 1010 -* 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. 1011 -* You CANNOT change a <cue> to a <library> or vice versa. 1012 -* 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.) 1013 -* 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. 1014 -* You CAN change a library and change/add/remove its sub-cues. This automatically updates all cues that use the library. 1015 -* 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. 1016 -* 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). 1017 -* Adding root cues enables their condition checks immediately (if the module attribute allows it). 1018 -* Adding sub-cues to active or complete cues enables their condition checks immediately. 1019 -* 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. 1020 -* Changing instantiate="false" to "true" turns the cue into "waiting" state if it was active or complete before. 1021 -* Changing instantiate="true" to "false" removes all instantiated cues and their descendants. 1022 1022 1023 -{{warning}} 1024 -Be aware that completed instances can be auto-deleted, and so added sub-cues will not become active in such a case. 1025 -{{/warning}} 1070 +{{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>"/}} 1026 1026 1027 -{{warning}} 1028 -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. 1029 -{{/warning}} 1030 1030 1031 -{{warning}} 1032 -(% id="cke_bm_221021S" style="display:none" %) (%%)Cue Removal Pitfall: 1033 -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. 1034 -{{code language="xml"}}<cue name="Deprecated_Test1"> 1035 - <actions> 1036 - <set_value name="$val_1" exact="'old value'"/> 1037 - <debug_text text="$val_1"/> 1038 - </actions> 1039 -</cue>{{/code}} 1040 -\\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. 1041 -{{code language="xml"}}<cue name="Deprecated_Test1"> 1042 - <actions> 1043 - <set_value name="$val_2" exact="'new value'"/> 1044 - <debug_text text="$val_2"/> 1045 - </actions> 1046 - <cues> 1047 - <cue name="PrintValue"> 1048 - <actions> 1049 - <debug_text text="$val_2"/> 1050 - </actions> 1051 - </cue> 1052 - </cues> 1053 -</cue>{{/code}} 1054 -\\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. 1055 -{{code language="xml"}}<!-- Deprecated Cues, kept to not duplicate names in future cues --> 1056 -<cue name="Deprecated_Test1" comment="deprecated"></cue>{{/code}} 1057 -{{/warning}} 1058 1058 1059 - == Patching ==1074 +\\ 1060 1060 1061 - Cuescan have **<patch>** elements with actions that will be performedwhen an old savegame is loaded. To control which savegames should be affected, you can add a //**version **//attributeto the <cue> node and a //**sinceversion**// attribute in the patch. When a cueis loaded from a savegame that has anolder version than //sinceversion//, the <patch> actions will be performed immediately after loading.1076 +(% id="md-refreshing-and-patching" %) 1062 1062 1063 -{{code language="xml"}} 1064 - <cue [...] version="42"> 1065 - <conditions> [...] </conditions> 1066 - <actions> [...] </actions> 1067 - <patch sinceversion="42"> 1068 - [patch actions] 1069 - </patch> 1070 - </cue> 1071 -{{/code}} 1078 += (% style="color: rgb(0,0,0);text-decoration: none;" %)MD refreshing and patching(%%) = 1072 1072 1073 - Thepatchactionsareonlyperformedifthecue isinacertainstate,"complete"bydefault.Use the//**state**//attribute tochange this requirement.Formoreinformation,see theXMLschema documentationofthe<patch>element.1080 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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. 1074 1074 1075 - 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.1082 +\\ 1076 1076 1077 -{{info}} 1078 -The <patch> elements will be ignored when refreshing the MD at run-time. They only affect loaded savegames." 1079 -{{/info}} 1084 +(% id="details-and-restrictions" %) 1080 1080 1081 -= Commonattributegroups =1086 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Details and restrictions(%%) == 1082 1082 1083 - Thereare manymmonlyusedactionsand conditionswhichsharegroups ofattributes. Themostimportantones are explained here.1088 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Here are some noteworthy facts about refreshing scripts and cues, and the restrictions: 1084 1084 1085 -== Value comparisons == 1090 +* (% 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). 1091 +* (% 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. 1092 +* (% 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. 1093 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)You CANNOT change a <cue> to a <library> or vice versa. 1094 +* (% 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.) 1095 +* (% 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. 1096 +* (% 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. 1097 +* (% 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. 1098 +* (% 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). 1099 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Adding root cues enables their condition checks immediately (if the module attribute allows it). 1100 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Adding sub-cues to active or complete cues enables their condition checks immediately. 1101 +* (% 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. 1102 +* (% 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. 1103 +* (% style="color: rgb(0,0,0);text-decoration: none;" %)Changing instantiate="true" to "false" removes all instantiated cues and their descendants. 1086 1086 1087 - Thereare many conditionsand conditionalactions that require a value comparison,foramplethendition<check_value>:1105 +(% style="color: rgb(0,0,0);text-decoration: none;" %) 1088 1088 1089 -{{code language="xml"}} 1090 - <check_value value="$ware == ware.silicon and $amount != 0"/> 1091 -{{/code}} 1092 1092 1093 - In the value attributeyouspecifyabooleanexpression,andif it is true(thatis, not equalto zero),theconditionismet. This isaspecial case: This conditionandallothernodesthatsupportavalue comparisonallowsyoutospecify an upper limit, a lower limit, a numberrange,or a listofallowedvalues. Examples:1108 +{{warning body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">Be aware that completed instances can be auto-deleted, and so added sub-cues will not become active in such a case.</span>"/}} 1094 1094 1095 -{{code language="xml"}} 1096 - <check_value value="FooCue.state" exact="cuestate.complete"/> 1097 - <check_value value="$foo.count" min="5"/> 1098 - <check_value value="$foo" max="player.age + 1min"/> 1099 - <check_value value="player.money" min="300Cr" max="600Cr"/> 1100 - <check_value value="$method" list="[killmethod.hitbymissile, killmethod.collected]"/> 1101 - <check_value value="$attention" min="attention.visible"/> 1102 -{{/code}} 1110 +{{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>"/}} 1103 1103 1104 -{{info}} 1105 -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." 1106 -{{/info}} 1107 1107 1108 -== Random ranges == 1109 1109 1110 - 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:1114 +\\ 1111 1111 1112 -{{code language="xml"}} 1113 - <set_value name="$race" exact="race.teladi"/> 1114 -{{/code}} 1116 +(% id="patching" %) 1115 1115 1116 - Toselectarandomelementfromalist, this syntaxcan be used:1118 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Patching(%%) == 1117 1117 1118 -{{code language="xml"}} 1119 - <set_value name="$prime" list="[2, 3, 5, 7, 11]"/> 1120 -{{/code}} 1120 +(% 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. 1121 1121 1122 - Togetarandomnumberwithinagivenrange,youcanusemin/max:1122 +{{code}}<cue┬á[...] version="42">┬á <conditions> [...] </conditions>┬á <actions> [...] </actions>┬á <patch┬ásinceversion="42">┬á┬á┬á [patch actions]┬á </patch></cue>{{/code}} 1123 1123 1124 -{{code language="xml"}} 1125 - <set_value name="$foo" min="-20" max="20"/> 1126 - <set_value name="$timeout" max="20s"/> 1127 -{{/code}} 1124 +(% 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. 1128 1128 1129 - minandmaxhavebe compatiblenumbertypes.Enumerationtypesare notallowed,notevenlevelandattention.Theminattributeisoptionalanddefaults to0(ofthenumbertypeused inmax).1126 +(% style="color: rgb(0,0,0);text-decoration: none;" %)A sequence of multiple <patch> elements is possible. They will be performed in order of appearance, checking the (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)sinceversion// and (%%)//(% style="color: rgb(0,0,0);text-decoration: none;" %)state// attributes in each case. Patches are also applied to all users of a library and to instances. 1130 1130 1131 - Youcan selectoneof 5 differentprobability distributionprofiles for the random range,"flat" being thedefault(all values inthe rangeareequally likely). If you select anotherprofile,e.g."increasing"to makehighernumbersmorelikely, you alsohave to specify a scale value (integer)that is greaterorequalto2. Higherscale values resultn higherpeaks in thedistributionprofiles(probablevalues becomeevenmorerobable).1128 +{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">The <patch> elements will be ignored when refreshing the MD at run-time. They only affect loaded savegames.</span>"/}} 1132 1132 1133 -{{code language="xml"}} 1134 - <set_value name="$foo" min="-20" max="20" profile="profile.increasing" scale="4"/> 1135 -{{/code}} 1136 1136 1137 -= Variables and namespaces = 1138 1138 1139 - 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).1132 +\\ 1140 1140 1141 - ==Creating andremoving variables==1134 +(% id="common-attribute-groups" %) 1142 1142 1143 - Youcancreatevariables with certain actionsand conditions,suchasthe <set_value>action:1136 += (% style="color: rgb(0,0,0);text-decoration: none;" %)Common attribute groups(%%) = 1144 1144 1145 -{{code language="xml"}} 1146 - <set_value name="$foo" exact="$bar + 1" /> 1147 -{{/code}} 1138 +(% 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. 1148 1148 1149 - <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>.)1140 +\\ 1150 1150 1151 - Thedefaultoperation of <set_value> is "**set**",but there are more: "**add**", "**subtract**", and "**insert**". //add// and //subtract// change thevalueof an existing variable, which is created as 0 if it didn't exist before. If neither //min//, //max// nor//exact// attribute isprovided, anexact value of 1 isassumed.1142 +(% id="categorybroken_macroanchorvalue-comparisons" %) 1152 1152 1153 -{{code language="xml"}} 1154 - <set_value name="$foo" operation="add" /> 1155 -{{/code}} 1144 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Value comparisons(%%) == 1156 1156 1157 - Thetrickisthat<set_value>not onlyworkson variables,butalsoon listelementsandblekeys:1146 +(% style="color: rgb(0,0,0);text-decoration: none;" %)There are many conditions and conditional actions that require a value comparison, for example the condition <check_value>: 1158 1158 1159 -{{code language="xml"}} 1160 - <set_value name="$list.{1}" exact="42" /> 1161 - <set_value name="$table.$foo" exact="42" /> 1162 -{{/code}} 1148 +{{code}}<check_value┬ávalue="$ware == ware.silicon and $amount != 0"/>{{/code}} 1163 1163 1164 - Theoperation//insert//isspecial, and itonlyworksonlists.Itinsertsthevalue at thespecifiedposition(note that the positionbeyondthe lastelementis also validhere):1150 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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: 1165 1165 1166 -{{code language="xml"}} 1167 - <set_value name="$list.{1}" exact="42" operation="insert" /> 1168 -{{/code}} 1152 +{{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}} 1169 1169 1170 - This shifts thepositions ofallfollowingelements upby one.Ifmin/max/exact are missing,the default value isnullfor insertions,not1like in other cases.1154 +{{note body="<span style=~"color: rgb(0,0,0);text-decoration: none;~">Values of most enumeration types cannot be compared via </span>''<span style=~"color: rgb(0,0,0);text-decoration: none;~">min</span>''<span style=~"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.). The only data types that can be used with </span>''<span style=~"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;~"> are numbers 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>''<span style=~"color: rgb(0,0,0);text-decoration: none;~">attention</span>''<span style=~"color: rgb(0,0,0);text-decoration: none;~"> (see Boolean operators). 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 is equivalent to using the == operator.</span>"/}} 1171 1171 1172 -Appending is easier than that. The following actions are equivalent: 1173 1173 1174 -{{code language="xml"}} 1175 - <set_value name="$list.{$list.count + 1}" exact="42" operation="insert" /> 1176 - <append_to_list name="$list" exact="42" /> 1177 -{{/code}} 1178 1178 1179 - Inserting at a position below 1 or above $list.count + 1 is not possible.1158 +\\ 1180 1180 1181 - Toremovevariablesorlist/table entries,use <remove_value>:1160 +(% id="categorybroken_macroanchorrandom-ranges" %) 1182 1182 1183 -{{code language="xml"}} 1184 - <remove_value name="$foo" /> 1185 - <remove_value name="$list.{1}" /> 1186 - <remove_value name="$table.$foo" /> 1187 -{{/code}} 1162 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Random ranges(%%) == 1188 1188 1189 - Removingan entryfrom alist shifts all followingelementsdownbyone.Ifyou wanttoclear anentrywithout removingitfromthelist,just use <set_value>instead.1164 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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: 1190 1190 1191 - == Accessingremotevariables ==1166 +{{code}}<set_value┬áname="$race"┬áexact="race.teladi"/>{{/code}} 1192 1192 1193 - Youcan also readdwritevariables inothercuesby usingthe variablenameaspropertykey:1168 +(% style="color: rgb(0,0,0);text-decoration: none;" %)To select a random element from a list, this syntax can be used: 1194 1194 1195 -{{code language="xml"}} 1196 - <set_value name="OtherCue.$foo" min="0.0" max="1.0" /> 1197 - <set_value name="md.OtherScript.YetAnotherCue.$bar" exact="OtherCue.$foo" /> 1198 -{{/code}} 1170 +{{code}}<set_value┬áname="$prime"┬álist="[2, 3, 5, 7, 11]"/>{{/code}} 1199 1199 1200 - Insteadofreferencinga cue byname,youcouldalsoreference itviaakeywordoranothervariable:1172 +(% style="color: rgb(0,0,0);text-decoration: none;" %)To get a random number within a given range, you can use min/max: 1201 1201 1202 -{{code language="xml"}} 1203 - <set_value name="static.$counter" operation="add" /> 1204 - <set_value name="parent.$foo" exact="42" /> 1205 - <set_value name="this.$bar" exact="parent" /> 1206 - <set_value name="$baz" exact="this.$bar.$foo" /> 1207 -{{/code}} 1174 +{{code}}<set_value┬áname="$foo"┬ámin="-20"┬ámax="20"/><set_value┬áname="$timeout"┬ámax="20s"/>{{/code}} 1208 1208 1209 -= =Namespaces==1176 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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). 1210 1210 1211 - Inthe examplesabove,avariablewaswrittento and readfromthe"this"cue. Thiscanbe necessary:theexpression"$foo"may bedifferentfromtheexpression"this.$foo".Theonfor thatarenamespaces.1178 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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). 1212 1212 1213 - Considerthis case:1180 +{{code}}<set_value┬áname="$foo"┬ámin="-20"┬ámax="20" profile="profile.increasing" scale="4"/>{{/code}} 1214 1214 1215 -{{code language="xml"}} 1216 -<cue name="Root"> 1217 - <actions> 1218 - <set_value name="$foo" /> 1219 - </actions> 1220 - <cues> 1221 - <cue name="SubCue"> [...] 1222 - </cue> 1223 - </cues> 1224 -</cue> 1225 -{{/code}} 1182 +(% style="color: rgb(0,0,255);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %)┬á 1226 1226 1227 - Whenthe root cue creates $foo, the variable is storedin 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'svery common to have a single location formost variablesin the whole cue tree, the easy solution is to write just "$foo"-because variablenames are lookedup inthe **namespacecue**, which isthe root by default. Also newly created variables end up in the namespace, and not in"this"cue.1184 +(% id="variables-and-namespaces" %) 1228 1228 1229 - Youcanalsousehekeyword "**namespace**"in expressionstogetthe namespacecue.1186 += (% style="color: rgb(0,0,0);text-decoration: none;" %)Variables and namespaces(%%) = 1230 1230 1231 -= ==Defining a cue'snamespace===1188 +(% style="color: rgb(0,0,0);text-decoration: none;" %)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). 1232 1232 1233 - Whenwriting a cue,youcan specify whatthenamespaceoftheue shouldbe,by addingthe//**namespace**//attribute. The followingvalues are possible:1190 +(% style="color: rgb(0,0,255);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %) 1234 1234 1235 -* **this**: Use "this" cue as namespace, even for instances: $foo == this.$foo 1236 -* **static**: Same as "this", but when instantiated, use the static cue: $foo == static.$foo 1237 -* **default**: The namespace is inherited from the parent cue. The default for root cues and for libraries is the same as "static". 1238 1238 1239 -{{warning}} 1240 -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: 1193 +(% id="categorybroken_macroanchorcreating-and-removing-variables" %) 1241 1241 1242 -{{code language="xml"}} 1243 -<cue name="LibRef" ref="Lib"> 1244 - <cke:param name="Param1" value="$foo" ></cke:param> <!-- $foo from parent namespace --> 1245 - <cke:param name="Param2" value="namespace.$foo" ></cke:param> <!-- LibRef.$foo (error) --> 1246 -</cue> 1247 -{{/code}} 1248 -{{/warning}} 1195 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Creating and removing variables(%%) == 1196 + 1197 +(% 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: 1198 + 1199 +{{code}}┬á<set_value┬áname="$foo"┬áexact="$bar + 1" />{{/code}} 1200 + 1201 +(% 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>.) 1202 + 1203 +(% 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. 1204 + 1205 +{{code}}<set_value┬áname="$foo"┬áoperation="add" />{{/code}} 1206 + 1207 +(% 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: 1208 + 1209 +{{code}}<set_value┬áname="$list.{1}"┬áexact="42" /><set_value┬áname="$table.$foo"┬áexact="42" />{{/code}}\\ 1210 + 1211 +(% 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): 1212 + 1213 +{{code}}<set_value┬áname="$list.{1}"┬áexact="42"┬áoperation="insert" />{{/code}} 1214 + 1215 +(% 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. 1216 + 1217 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Appending is easier than that. The following actions are equivalent: 1218 + 1219 +{{code}}<set_value┬áname="$list.{$list.count + 1}"┬áexact="42"┬áoperation="insert" /><append_to_list┬áname="$list"┬áexact="42" />{{/code}} 1220 + 1221 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Inserting at a position below 1 or above $list.count + 1 is not possible. 1222 + 1223 +(% style="color: rgb(0,0,0);text-decoration: none;" %)To remove variables or list/table entries, use <remove_value>: 1224 + 1225 +{{code}}<remove_value┬áname="$foo" /><remove_value┬áname="$list.{1}" /><remove_value┬áname="$table.$foo" />{{/code}}\\ 1226 + 1227 +(% 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. 1228 + 1229 +(% style="color: rgb(0,0,255);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %) 1230 + 1231 + 1232 +(% id="accessing-remote-variables" %) 1233 + 1234 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Accessing remote variables(%%) == 1235 + 1236 +(% 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: 1237 + 1238 +{{code}}<set_value┬áname="OtherCue.$foo"┬ámin="0.0"┬ámax="1.0" /><set_value┬áname="md.OtherScript.YetAnotherCue.$bar"┬áexact="OtherCue.$foo" />{{/code}} 1239 + 1240 +(% 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: 1241 + 1242 +{{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}} 1243 + 1244 +(% style="color: rgb(0,0,255);text-decoration: none;" %)(% style="color: rgb(0,0,0);text-decoration: none;" %) 1245 + 1246 + 1247 +(% id="namespaces" %) 1248 + 1249 +== (% style="color: rgb(0,0,0);text-decoration: none;" %)Namespaces(%%) == 1250 + 1251 +(% 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. 1252 + 1253 +(% style="color: rgb(0,0,0);text-decoration: none;" %)Consider this case: 1254 + 1255 +{{code}}<cue┬áname="Root">┬á <actions>┬á ┬á <set_value┬áname="$foo" />┬á </actions>┬á <cues>┬á ┬á <cue┬áname="SubCue"> [...]┬á ┬á </cue>┬á </cues></cue>{{/code}} 1256 + 1257 +(% 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. 1258 + 1259 +(% 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. 1260 + 1261 +(% id="defining-a-cues-namespace" %) 1262 + 1263 +=== (% style="color: rgb(0,0,0);text-decoration: none;" %)Defining a cueΓÇÖs namespace(%%) === 1264 + 1265 +(% 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: 1266 + 1267 +* **(% 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 1268 +* **(% 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 1269 +* **(% 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ΓÇ¥. 1270 + 1271 +(% style="color: rgb(0,0,255);text-decoration: none;" %) 1272 + 1273 + 1274 +{{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> 1275 + 1276 +<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>"/}}
- Mission Director Guide - Instantiation.png
-
- Author
-
... ... @@ -1,1 +1,0 @@ 1 -xwiki:XWiki.Daniel - Size
-
... ... @@ -1,1 +1,0 @@ 1 -47.0 KB - Content