<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.wesnoth.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Elvish+Hunter</id>
	<title>The Battle for Wesnoth Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.wesnoth.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Elvish+Hunter"/>
	<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/Special:Contributions/Elvish_Hunter"/>
	<updated>2026-04-25T22:34:27Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ImageMetadata&amp;diff=74448</id>
		<title>ImageMetadata</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ImageMetadata&amp;diff=74448"/>
		<updated>2025-07-23T14:23:47Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* Basic usage of exiftool */ Updated command for EXIF tags (without &amp;quot;EXIF:&amp;quot; it didn't work correctly for me on PNG files)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Image Metadata ==&lt;br /&gt;
&lt;br /&gt;
Author and copyright data of Wesnoth images are contained in the image metadata.  For most of Wesnoth's project history, image authorship and copyrights were tracked in a separate text document.  Such a document can still be generated from the metadata, but is not currently (2025) part of the commit process.  There is no expectation that an artist correctly format the metadata, but the individual committing the image to the project files is expected to do so.&lt;br /&gt;
&lt;br /&gt;
A lot of different programs can manipulate metadata, and they all seem to have different ways of doing it.  &lt;br /&gt;
'''Exiftool''' is platform-independent, command-line application that has been the primary toolkit applied to Wesnoth images.  More info can be found at https://www.exiftool.org/index.html&lt;br /&gt;
&lt;br /&gt;
The discussion assumes GIMP (or Krita) is the image editor used, but it is probably equally valid for Adobe Photoshop.  Other editors probably have some metadata support, this is a wiki. &lt;br /&gt;
&lt;br /&gt;
===Basic usage of exiftool===&lt;br /&gt;
&lt;br /&gt;
To view metadata of an image &amp;lt;file&amp;gt; grouped by tag&lt;br /&gt;
    exiftool -g &amp;lt;file&amp;gt;&lt;br /&gt;
'''Note:''' WEBP must contain &amp;quot;Alpha&amp;quot; in RIFF:WebP_Flags or else the transparent background will be lost when EXIF tags are added.  Exiftool is supposed to read but not write this flag (so ''-all='' argument shouldn't clobber it, but sometimes it does).  GIMP will set this flag, but it can get removed by further processing.  Viewing the image metadata with the above command will allow you to check.&lt;br /&gt;
&lt;br /&gt;
To write the needed metadata (Author and Copyright) but remove all the other info injected by image editors (most of which is useful in some context, just not this one), we use ''-all='' to clear the deck.  For small PNG files, thumbnail data can double the file size, and this matters because we have ''a lot'' of these little files.  We can also use ''-overwrite_original'' to prevent a backup file.  Different tag groups have different names for very similar fields, and they often don't match what you see in the image editor dialogs.&lt;br /&gt;
* XMP (dc &amp;quot;Dublin Core&amp;quot;) tags - were briefly used for PNG because they are most likely to be edited with GIMP.  However, this fact was not worth the extra size and complication, so they are no longer used.  Please use the EXIF tags for PNG, just like JPG and WEBP.&lt;br /&gt;
    exiftool -overwrite_original -all= -Date=&amp;quot;&amp;lt;Y:m:d H:M:S&amp;gt;&amp;quot; -Rights=&amp;quot;&amp;lt;copyright&amp;gt;&amp;quot; -Creator=&amp;quot;&amp;lt;name (account name)&amp;gt;&amp;quot; -Description=&amp;quot;&amp;lt;comment&amp;gt;&amp;quot; &amp;lt;target file&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* EXIF - Used for WEBP, JPG and PNG, as Exif data seemed more visible in some file managers.  We could add both XMP and Exif to all images, but that would make the files larger.&lt;br /&gt;
    exiftool -overwrite_original -all= -EXIF:CreateDate=&amp;quot;&amp;lt;Y:m:d H:M:S&amp;gt;&amp;quot; -EXIF:Copyright=&amp;quot;&amp;lt;copyright&amp;gt;&amp;quot; -EXIF:Artist=&amp;quot;&amp;lt;name (account name)&amp;gt;&amp;quot; -EXIF:UserComment=&amp;quot;&amp;lt;comment&amp;gt;&amp;quot; &amp;lt;target file&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Metadata and CI===&lt;br /&gt;
&lt;br /&gt;
====Authorship and Copyright====&lt;br /&gt;
&lt;br /&gt;
To satisfy CI, image metadata is checked for a small set of entries.&lt;br /&gt;
&lt;br /&gt;
For PNG, JPEG, WEBP:&lt;br /&gt;
* '''EXIF:Artist''' must exist.&lt;br /&gt;
&lt;br /&gt;
* '''EXIF:Copyright''' must contain &amp;quot;GNU GPL v2+&amp;quot;, &amp;quot;CC BY-SA 4.0&amp;quot;, or &amp;quot;CC0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====Optional tags reported in CI====&lt;br /&gt;
(This needs to be fixed, both here and CI.)&lt;br /&gt;
&lt;br /&gt;
===Metadata and Image Editors===&lt;br /&gt;
====GIMP (2.10)====&lt;br /&gt;
''Image-&amp;gt;Metadata-&amp;gt;Edit Metadata''&lt;br /&gt;
*PNG - Can read/write XMP:Creator, XMP:Rights, and XMP:Description under the &amp;quot;Description&amp;quot; tab&lt;br /&gt;
*WEBP - Can read/write XMP:Creator, XMP:Rights, and XMP:Description under the &amp;quot;Description&amp;quot; tab&lt;br /&gt;
*JPEG - Can read IPTC:By-line or EXIF:Artist (IPTC takes precedence), shown under &amp;quot;Description&amp;quot;, exports to XMP and IPTC groups&lt;br /&gt;
&lt;br /&gt;
====Krita (5.1)====&lt;br /&gt;
''Layer-&amp;gt;Edit Metadata...''&lt;br /&gt;
*PNG - Does not always import XMP:Creator or XMP:Rights, but can write to them under &amp;quot;Dublin Core&amp;quot; tab, as well as XMP:Description&lt;br /&gt;
*WEBP - Does not seem to import anything, but can write XMP:Creator and XMP:Rights&lt;br /&gt;
*JPEG - Can import EXIF:Artist and EXIF:Copyright, shown under &amp;quot;Dublin Core&amp;quot; as Creator &amp;amp; Rights, exported under IPTC:By-line and IPTC:Copyright Notice&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
A sprite (PNG) with the needed EXIF tags is shown below.&lt;br /&gt;
&lt;br /&gt;
https://forums.wesnoth.org/download/file.php?id=99973&amp;amp;type=.png&lt;br /&gt;
&lt;br /&gt;
Examples of WebP showing the Alpha flag issue can be found at this forum post:&lt;br /&gt;
 &lt;br /&gt;
https://forums.wesnoth.org/viewtopic.php?p=694451#p694451&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Create]]&lt;br /&gt;
* [[Maintenance_tools]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=EffectWML&amp;diff=70740</id>
		<title>EffectWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=EffectWML&amp;diff=70740"/>
		<updated>2023-04-05T18:26:58Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [effect] */ added apply_to=level&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
== [effect] ==&lt;br /&gt;
&lt;br /&gt;
The tag [effect] is used to describe one modification to a unit. Any number of [effect] tags can be used to describe a complete modification.&lt;br /&gt;
&lt;br /&gt;
Modifications are permanent changes to a unit; however using an [[DirectActionsWML#.5Bobject.5D|[object]]] with a limited ''duration'' to apply an [effect] will cause the unit to be rebuilt without the effect's effects when the duration expires. &lt;br /&gt;
&lt;br /&gt;
The following keys and subtags are always recognized:&lt;br /&gt;
* '''[filter]''': only apply this effect if the affected unit matches. See [[StandardUnitFilter]] for details.&lt;br /&gt;
* '''times''': describes how many times the effect is applied. The default is to apply the effect once. Other possible value : &amp;quot;per level&amp;quot; which means that the effect is applied level times, where level is the unit level. {{DevFeature1.13|5}} Integers are now supported for ''times''.&lt;br /&gt;
* '''apply_to''': describes what the effect actually affects. New effect types can be added with [[LuaWML/Units#wesnoth.effects]].&lt;br /&gt;
[effect] uses different keys depending on the value of '''apply_to'''.  '''apply_to''' can take the following values:&lt;br /&gt;
* '''new_attack''': will use all other keys and tags as the description of an attack that will be added to the unit. See [attack] in [[UnitTypeWML#Attacks|UnitTypeWML]].&lt;br /&gt;
* '''remove_attacks''': remove the matching attacks. All tags from the attack filter construct will be used to match the attack; see [[FilterWML#Filtering Weapons|FilterWML]]. Do not use a [filter] tag otherwise it will not work properly.&lt;br /&gt;
* '''attack''': find an attack and modify it.  All tags from the attack filter construct will be used to match the attack; see [[FilterWML#Filtering Weapons|FilterWML]].  After that, the following keys and tags can be used to modify the attack.  Note: do not use a [filter] tag.  Just put the keys you want to filter on inside the [effect] tag.&lt;br /&gt;
** '''set_name''': change the attack's name (ie identifier).&lt;br /&gt;
** '''set_description''': change the attack's description (ie displayed name). &lt;br /&gt;
** '''set_type''': change the attack type. The standard values are '''blade''', '''pierce''', '''impact''', '''fire''', '''cold''', and '''arcane'''.&lt;br /&gt;
** '''set_range''': change the attack range. The standard values are '''ranged''' and '''melee'''.&lt;br /&gt;
** '''set_icon''': change the attack's icon.&lt;br /&gt;
** '''[set_specials]''': change the attack's specials. The specials to add are given exactly as in the [[AbilitiesWML#The_.5Bspecials.5D_tag|[specials]]] tag.&lt;br /&gt;
*** '''mode''': if '''append''', adds the given specials to the attack. If '''replace''', replaces the existing specials with the given ones. Default '''replace'''.&lt;br /&gt;
**** {{DevFeature1.15|3}} A deprecation warning is triggered unless the '''mode''' attribute is set, although the effect will still be '''replace'''. This is to allow the default to change in the 1.17.x series.&lt;br /&gt;
** '''remove_specials''': remove the listed specials. The value of this key is the comma-separated list of the id of the specials to remove. This key is always evaluated before a [set_specials] tags in the same [effect]&lt;br /&gt;
** '''increase_damage''': increases the attack's damage.  This can be positive or negative, so you can use it to decrease damage as well.  If it ends in a percent(''''%''''), the change in damage will be a percentage ratio of the attack's original damage.&lt;br /&gt;
** '''increase_attacks''': increases the number of attack strikes. Like '''increase_damage''', it can be positive or negative, or a percentage.&lt;br /&gt;
** '''increase_accuracy''': increases the attack accuracy; can be positive or negative, or a percentage&lt;br /&gt;
** '''increase_parry''': increases the attack parry bonus; can be positive or negative, or a percentage&lt;br /&gt;
** '''increase_movement_used''': {{DevFeature1.13|2}} increases the movement points used by the attack; can be positive or negative, or a percentage&lt;br /&gt;
** '''increase_attacks_used''': {{DevFeature1.17|13}} increases the attack points used by the attack; can be positive or negative, or a percentage&lt;br /&gt;
** '''set_damage''' {{DevFeature1.13|2}} like increase_damage, but sets the damage to a specific value instead of setting it relative to its original value&lt;br /&gt;
** '''set_attacks''' {{DevFeature1.13|2}} like increase_attacks, but sets the attacks to a specific value instead of setting it relative to its original value&lt;br /&gt;
** '''set_accuracy''' {{DevFeature1.13|2}} like increase_accuracy, but sets the accuracy to a specific value instead of setting it relative to its original value&lt;br /&gt;
** '''set_parry''' {{DevFeature1.13|2}} like increase_parry, but sets the parry to a specific value instead of setting it relative to its original value&lt;br /&gt;
** '''set_movement_used''' {{DevFeature1.13|2}} like increase_movement_used, but sets the movement used to a specific value instead of setting it relative to its original value&lt;br /&gt;
** '''set_attacks_used''' {{DevFeature1.17|13}} like increase_attacks_used, but sets the attacks used to a specific value instead of setting it relative to its original value&lt;br /&gt;
** '''attack_weight''': change the attack's attack_weight. See [attack] in [[UnitTypeWML#Attacks|UnitTypeWML]] for explanations about attack_weight.&lt;br /&gt;
** '''defense_weight''': change the attack's defense_weight. See [attack] in [[UnitTypeWML#Attacks|UnitTypeWML]] for explanations about defense_weight.&lt;br /&gt;
* '''max_attacks''': {{DevFeature1.13|2}} change the unit's maximum attacks per turn&lt;br /&gt;
** '''increase''': how much to increase by; can be positive or negative, or a percentage&lt;br /&gt;
* '''hitpoints''': modifies the unit's HP and/or max HP.&lt;br /&gt;
** '''increase''': the amount to increase the unit's HP.&lt;br /&gt;
** '''heal_full''': if present  and not set to &amp;quot;no&amp;quot; the unit will be put back to full HP.&lt;br /&gt;
** '''increase_total''': will increase the total HP of the unit.  Can be specified either as a negative or a positive value.  It can also be specified as a percentage of the current total; i.e. &amp;quot;-50%&amp;quot; will cut max HP in half.&lt;br /&gt;
** '''violate_maximum''': it the unit ends up with more than its max HP after these modifications, and this key is present (set to any non-null value, ex. '''yes'''), the unit's HP won't be lowered to its max HP.&lt;br /&gt;
* '''movement''': modifies the unit's movement points.&lt;br /&gt;
** '''increase''': maximum movement is increased by this amount. It can be positive, negative, or specified as a percentage.&lt;br /&gt;
** '''set''': maximum movement is set to a specific value.&lt;br /&gt;
** '''apply_to_vision''': {{DevFeature1.15|13}} if set to '''yes''' (which is the default), then the vision points will change by the same amount. See [[#Movement_and_Vision|Movement and Vision]].&lt;br /&gt;
* '''vision''': {{DevFeature1.13|2}} modifies the unit's vision points. Note: this has side effects described in [[#Movement_and_Vision|Movement and Vision]].&lt;br /&gt;
** '''increase''': maximum vision is increased by this amount. It can be positive, negative, or specified as a percentage.&lt;br /&gt;
** '''set''': maximum vision is set to a specific value. &lt;br /&gt;
* '''jamming''': {{DevFeature1.13|2}} modifies the unit's jamming points.&lt;br /&gt;
** '''increase''': maximum jamming is increased by this amount. It can be positive, negative, or specified as a percentage.&lt;br /&gt;
** '''set''': maximum jamming is set to a specific value.&lt;br /&gt;
* '''experience''': affects the unit's current XP.&lt;br /&gt;
** '''increase''': current XP is increased by this amount. It can be positive, negative, or specified as a percentage.&lt;br /&gt;
** '''set''': current XP is set to a specific value.&lt;br /&gt;
* '''max_experience''': affects the amount of XP the unit needs for the next level.&lt;br /&gt;
** '''increase''': how to change the xp; again it can be negative, positive or a percentage.&lt;br /&gt;
** '''set''': current max XP is set to a specific value.&lt;br /&gt;
* '''loyal''': no keys associated. The affected unit will be loyal i.e have an upkeep of 0.&lt;br /&gt;
* '''movement_costs''': speed through specific terrain is modified&lt;br /&gt;
** '''replace''': If set to &amp;quot;yes&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values (negative values allowed).&lt;br /&gt;
** '''[movement_costs]''': a subtag that describes the new movement costs just like in [[UnitsWML#.5Bmovetype.5D|UnitsWML]]&lt;br /&gt;
* '''vision_costs''': vision through specific terrain is modified&lt;br /&gt;
** '''replace''': If set to &amp;quot;yes&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values (negative values allowed).&lt;br /&gt;
** '''[vision_costs]''': a subtag that describes the new vision costs just like in [[UnitsWML#.5Bmovetype.5D|UnitsWML]]&lt;br /&gt;
* '''jamming_costs''': jamming through specific terrain is modified&lt;br /&gt;
** '''replace''': If set to &amp;quot;yes&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values (negative values allowed).&lt;br /&gt;
** '''[jamming_costs]''': a subtag that describes the new jamming costs just like in [[UnitsWML#.5Bmovetype.5D|UnitsWML]]&lt;br /&gt;
* '''defense''': Sets the unit's chance to be hit in specific terrain (100 - the unit's defense as shown in-game). &lt;br /&gt;
** '''replace''': If set to &amp;quot;yes&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values. In most cases, adding a positive number makes the unit easier to hit, while adding a negative number makes the unit harder to hit. The new value is added to the absolute value of the old, and the sign of the old value is preserved.&lt;br /&gt;
** '''[defense]''': a subtag that describes the new defense just like in [[UnitsWML#.5Bmovetype.5D|UnitsWML]]&lt;br /&gt;
* '''resistance''': Sets percent damage taken from combat (100 - the unit's resistance as shown in-game)&lt;br /&gt;
** '''replace''': If set to &amp;quot;yes&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values. Adding a positive number makes the unit take more damage, while adding a negative number makes the unit take less damage.&lt;br /&gt;
** '''[resistance]''': a subtag that describes the new resistance just like in [[UnitsWML#.5Bmovetype.5D|UnitsWML]]&lt;br /&gt;
* '''variation''': switches the unit into one of its variations. Similar to the '''type''' effect below, this might not behave properly outside of [advancement], and cannot be combined with '''type''' in the same object due to a bug.&lt;br /&gt;
** '''name''': the id of the variation to invoke. &lt;br /&gt;
* '''type''': transforms the unit into a new unit_type. This does not work in [trait]; in ActionWML it's recommended to use [transform_unit] instead of an [object] with this effect. This effect cannot be undone with [remove_object].&lt;br /&gt;
** '''name''': the id of the unit_type to invoke.&lt;br /&gt;
* '''status''': modifies the status affecting the unit.&lt;br /&gt;
** '''add''': a list of status modifications to add. Beware, these may be reapplied later, such as when the unit is recalled or levels up; if in an event, you can use [[InternalActionsWML|[store_unit]]] and [[DirectActionsWML|[unstore_unit]]], modifying unit.status.name directly, to avoid this, or if you are creating the unit, you can just add it to the unit's [status] tag in the [unit] tag.  These are listed in [status], [[SingleUnitWML]].&lt;br /&gt;
** '''remove''': a list of status modifications to remove.&lt;br /&gt;
* '''zoc''': toggle the zone of control.&lt;br /&gt;
** '''value''': new value for zoc (boolean).&lt;br /&gt;
* '''profile''': customize the profile of the unit. See [[UnitTypeWML]].&lt;br /&gt;
** '''portrait''': new image to display when the unit speaks.&lt;br /&gt;
** '''small_portrait''': new image to display in unit reports.&lt;br /&gt;
** '''description''': sets the text to display when hovering over the unit's type in the righthand pane.&lt;br /&gt;
** '''[special_note]''': {{DevFeature1.15|2}} Adds or removes a special note in the unit's description.&lt;br /&gt;
*** '''remove''': A boolean value specifying whether to add or remove a note. Defaults to '''no'''.&lt;br /&gt;
*** '''note''' (translatable): The text of the note you want to add or remove. If removing a note, this must be an exact match, character-for-character, for the note you want to remove, and must also be in the same textdomain.&lt;br /&gt;
*** Since the tag name is the same, notes can also be added using the standard special note macros, eg '''{NOTE_HEALS}'''.&lt;br /&gt;
*** To remove a note, you can simply suffix '''{NOTE_REMOVE}''' to the regular note macro, eg '''{NOTE_HEALS}{NOTE_REMOVE}'''.&lt;br /&gt;
* '''new_ability''': Adds one or more abilities to a unit.&lt;br /&gt;
** '''[abilities]''': A subtag that contains the ability definitions.&lt;br /&gt;
* '''remove_ability''': Removes one or more abilities from a unit. Abilities are not reference counted: added, added, removed = gone.&lt;br /&gt;
** '''[abilities]''': A subtag that contains the ability definitions. Strictly speaking, all that is needed is the id= inside some tag.&lt;br /&gt;
* '''new_animation''': contain animations that will be added to the unit, it can contain multiple animation blocks, and a single &amp;quot;id=&amp;quot; line. That Id should be unique for each effect block and is used by the engine to reuse WML parsing, making the loading faster. See [[AnimationWML]] for further reference.&lt;br /&gt;
* '''image_mod''': modify the image path function ([[ImagePathFunctions]]) of all the unit's frames. Due to a bug, the effect is permanent even inside [object]duration=turn&lt;br /&gt;
** '''replace''': replaces the image path function(s) to be used, e.g. &amp;quot;RC(magenta&amp;gt;red)&amp;quot;&lt;br /&gt;
** '''add''': adds an image path function without removing any existing ones.&lt;br /&gt;
** If needed, you can also define new [[GameConfigWML#Color_Palettes|color palettes]] here.&lt;br /&gt;
* '''ellipse''': Change the image used for the unit's ellipse.&lt;br /&gt;
** '''ellipse''' : the new image to use. Can be set to &amp;quot;none&amp;quot; to disable the ellipse.&lt;br /&gt;
* '''halo''': Change the image used for the unit's halo.&lt;br /&gt;
** '''halo''': the new image to use.&lt;br /&gt;
* '''overlay''': Change the unit's overlays.&lt;br /&gt;
**'''add''': the specified overlay will be added to the unit's overlays. It can be a comma separated list with multiple overlays. ''Note: overlays added in this way cannot be removed by [remove_unit_overlay] until the effect's duration is over.''&lt;br /&gt;
**'''replace''': all the unit's overlays will be removed and replaced with the specified one. Again, it can be a comma separated list. ''Note: overlays replaced in this way cannot be modified by [unit_overlay] or [remove_unit_overlay] until the effect's duration is over.''&lt;br /&gt;
**'''remove''': {{DevFeature1.15|0}} the specified overlay will be removed from the unit's overlays. It can be a comma separated list with multiple overlays.&lt;br /&gt;
** {{DevFeature1.15|0}} [unit_overlay] and [remove_unit_overlay] are now equivalent to adding a permanent object with this effect, after checking if the unit already has / already doesn't have the overlay (effects with temporary durations will cause false positives / false negatives in this check).&lt;br /&gt;
* '''recall_cost''': {{DevFeature1.13|2}} change a unit's recall cost&lt;br /&gt;
** '''set''': set recall cost to a specific value, or a percentage of original value&lt;br /&gt;
** '''increase''': alter recall cost relative to original value; can be positive or negative, or a percentage&lt;br /&gt;
* '''alignment''': {{DevFeature1.13|2}} change a unit's alignment&lt;br /&gt;
** '''set''': the new alignment (one of chaotic, lawful, neutral, liminal)&lt;br /&gt;
* '''new_advancement''': {{DevFeature1.13|2}} add new advancement choices to the unit&lt;br /&gt;
** '''replace''': whether to replace existing advancement choices; if this key is set to yes, existing advancement choices are cleared only if you're adding a choice of the same type. (That is, unit type advancements are cleared only if you're adding a new unit advancement choice, and AMLA choices are cleared only if you're adding new AMLA choices.)&lt;br /&gt;
** '''types''': a comma-separated list of additional unit types the unit can advance to. ('''Note:''' If using this, you probably want to include a filter to prevent the unit from being able to advance to this type once it has already done so.)&lt;br /&gt;
** '''[advancement]''': an advancement choice to add, see [[UnitTypeWML#After_max_level_advancement_(AMLA)|AMLAs]]; you can have several of these tags to add multiple advancement choices at the same time.&lt;br /&gt;
* '''remove_advancement''': {{DevFeature1.13|2}} remove existing advancement choices from the unit&lt;br /&gt;
** '''types''': a list of unit type advancements to remove as a possibility&lt;br /&gt;
** '''amlas''': a list of AMLA id attributes; any advancement possibility with the given id will be removed&lt;br /&gt;
* '''level''': {{DevFeature1.17|15}} change a unit's level. '''Note:''' this key is incompatible with ''times=per level''; if this combination is used, the engine reports a warning and uses ''times=1'' as fallback value&lt;br /&gt;
** '''set''': set level to a specific value; can be positive or negative, but not a percentage&lt;br /&gt;
** '''increase''': alter level relative to original value; can be positive or negative, but not a percentage&lt;br /&gt;
&lt;br /&gt;
== Movement and Vision ==&lt;br /&gt;
&lt;br /&gt;
Wesnoth 1.14 introduced vision points; by default units have the same number of vision points as their max movement points. However, combining effects that change vision with effects that change movement had edge cases which were reworked in 1.16:&lt;br /&gt;
&lt;br /&gt;
Consider a unit with 5 mp, and default vision:&lt;br /&gt;
* It has (effectively) 5 mp and 5 vp.&lt;br /&gt;
* After (mp + 1), it will have 6 mp and 6 vp.&lt;br /&gt;
* After (vp + 2), it will have 5 mp and 7 vp.&lt;br /&gt;
&lt;br /&gt;
In 1.14, using an effect with apply_to=vision breaks the link between vision and movement:&lt;br /&gt;
* After (mp + 1) (vp + 2), it will have 6 mp and 8 vp.&lt;br /&gt;
* After (vp + 2) (mp + 1), it will have 6 mp and 7 vp.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.15|13}}, [effect]apply_to=movement has another attribute apply_to_vision, which defaults to true. With that change, the order that the effects are applied in doesn't matter:&lt;br /&gt;
* After (mp + 1) (vp + 2), it will have 6 mp and 8 vp.&lt;br /&gt;
* After (vp + 2) (mp + 1), it will have 6 mp and 8 vp.&lt;br /&gt;
&lt;br /&gt;
Increasing movement by 50% increases vision by (50% of movement) not by (50% of vision). For a unit that started with 6 mp and 8 vp, the following effect would give it 9 mp and 11 vp.&lt;br /&gt;
    [effect]&lt;br /&gt;
        apply_to=movement&lt;br /&gt;
        increase=50%&lt;br /&gt;
    [/effect]&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
== Effect: apply_to = new_animation  ==&lt;br /&gt;
This is the only way to change animations of units after they have been placed on the map.&lt;br /&gt;
In this example, I add very simple idle animation (taken from Goblin Spearman) to the unit, which moves to hex (x=1, y=5). If you want something more complex, you need to check [[AnimationWML]] page.&lt;br /&gt;
&lt;br /&gt;
  [event]&lt;br /&gt;
    name = moveto&lt;br /&gt;
    [filter]&lt;br /&gt;
      x,y = 1,5&lt;br /&gt;
    [/filter]&lt;br /&gt;
    [object]&lt;br /&gt;
      [filter]&lt;br /&gt;
        x,y = 1,5&lt;br /&gt;
      [/filter]&lt;br /&gt;
      [effect]&lt;br /&gt;
        apply_to = new_animation&lt;br /&gt;
        [idle_anim]&lt;br /&gt;
          {STANDARD_IDLE_FILTER}&lt;br /&gt;
          start_time=0&lt;br /&gt;
          [frame]&lt;br /&gt;
            image=&amp;quot;units/goblins/spearman-idle-[1~12].png:[150*3,300,150*8]&amp;quot;&lt;br /&gt;
          [/frame]&lt;br /&gt;
        [/idle_anim]&lt;br /&gt;
      [/effect]&lt;br /&gt;
    [/object]&lt;br /&gt;
  [/event]&lt;br /&gt;
&lt;br /&gt;
If you are going to use '''advanced WML''' and want to add animation to unit, stored in variable, then following example might help you. '''This way is not efficient if you have no additional logic like inventoriy, shops, advanced unit modifications in your add-on.''' Is is preferred to use first variant or define all needed animation in unit_type.&lt;br /&gt;
  [event]&lt;br /&gt;
    name = moveto&lt;br /&gt;
    [filter]&lt;br /&gt;
      x,y = 1,5&lt;br /&gt;
    [/filter]&lt;br /&gt;
    [store_unit]&lt;br /&gt;
      [filter]&lt;br /&gt;
        x,y=1,5&lt;br /&gt;
      [/filter]&lt;br /&gt;
      variable = stored_unit&lt;br /&gt;
    [/store_unit]&lt;br /&gt;
    [set_variables]&lt;br /&gt;
      name = stored_unit.modifications.object&lt;br /&gt;
      [value]&lt;br /&gt;
        [effect]&lt;br /&gt;
          apply_to = new_animation&lt;br /&gt;
          [idle_anim]&lt;br /&gt;
            {STANDARD_IDLE_FILTER}&lt;br /&gt;
            start_time=0&lt;br /&gt;
            [frame]&lt;br /&gt;
              image=&amp;quot;units/goblins/spearman-idle-[1~12].png:[150*3,300,150*8]&amp;quot;&lt;br /&gt;
            [/frame]&lt;br /&gt;
          [/idle_anim]&lt;br /&gt;
        [/effect]&lt;br /&gt;
      [/value]&lt;br /&gt;
    [/set_variables]&lt;br /&gt;
    [unstore_unit]&lt;br /&gt;
      variable = stored_unit&lt;br /&gt;
    [/unstore_unit]&lt;br /&gt;
  [/event]&lt;br /&gt;
&lt;br /&gt;
== Where to Use Effects ==&lt;br /&gt;
&lt;br /&gt;
A collection of effects together makes up a &amp;quot;unit modification&amp;quot;, which is encased in one of the three types of modification tags: '''[trait]''', '''[object]''', or '''[advancement]'''. Which tag to use depends on the goal of the modification.&lt;br /&gt;
&lt;br /&gt;
* [[UnitsWML#.5Btrait.5D|Traits]] are shown in the unit details on the sidebar. They can be placed in a race or unit type to include the trait in the pool of random traits for that race or unit type, or they can be placed in the global [units] tag to add them to the global pool of random traits. (Note that this can cause out-of-sync errors in multiplayer.)&lt;br /&gt;
* [[UnitTypeWML#After_max_level_advancement_.28AMLA.29|Advancements]] are offered when a unit levels up. If a unit type has both modification advancements and regular advancements, the player can choose either each time they level up.&lt;br /&gt;
* [[DirectActionsWML#.5Bobject.5D|Objects]] are usually placed on the map or added by special events. They also have a built-in facility to automatically remove under certain conditions.&lt;br /&gt;
&lt;br /&gt;
An effect can also be placed in '''[modify_unit]''' [[DirectActionsWML#.5Bmodify_unit.5D|ActionWML]] to apply it on-the-fly without keeping a record that it has been applied. This is mainly useful for effects that change transient properties such as current hitpoints or experience. An effect applied in this way is liable to be reverted when the unit is rebuilt in the future, for example when they level up or when an object is removed.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[UnitTypeWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
* [[AnimationWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=Team_Color_Shifting&amp;diff=69620</id>
		<title>Team Color Shifting</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=Team_Color_Shifting&amp;diff=69620"/>
		<updated>2022-06-12T19:16:29Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Fixed links and image URLs to use HTTPS&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;originally by Richard Kettering (Jetryl)&lt;br /&gt;
&lt;br /&gt;
:Note: if you're interested in actually changing the color of a sprite that has already had this technique applied to it (i.e. automatically changing the magenta in a sprite to blue or red), see the [[TeamColoring]] page instead.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Wesnoth's sprites are only drawn in one color, but in an actual game, all of our unit's clothing will change color to the color of whatever team they're on.  We call this &amp;quot;team color&amp;quot; shifting.  Any team color shifting system needs a way of indicating which areas of the graphic are to be changed in color.  Ours solves this by selecting a certain, specific range of colors, and shifting the pixels whenever they are that source color in the unit image.  In our system, this can be done with any set of colors that you choose, on a per-unit basis.  However, we've got a shortcut for one set of colors, magenta.  We picked a color that because it would stick out like a sore thumb; it's not an 'earthtone', and isn't commonly seen in nature. &amp;lt;div style=&amp;quot;float:right; width:260px; padding:1ex; margin:1ex; border: thin dotted; font-size:80%;&amp;quot;&amp;gt;https://www.wesnoth.org/forum/download/file.php?id=46095&amp;amp;type=.png&lt;br /&gt;
For the first nine teams, this will look like this after teamcoloring. (The last line is the original magenta image.) [https://www.wesnoth.org/forum/viewtopic.php?f=23&amp;amp;t=31836&amp;amp;start=0]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It's not just any magenta; it has to be from the following, very specific set:&lt;br /&gt;
&lt;br /&gt;
https://www.wesnoth.org/wiki-images/tutorial/team-color/colorswatch.png&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-size:70%&amp;quot;&amp;gt;If you're using GIMP, here is a palette with the team color values: [https://www.wesnoth.org/forum/download/file.php?id=44892]&amp;lt;br/&amp;gt;&lt;br /&gt;
Put this file as &amp;quot;wesnoth-tc.gpl&amp;quot; in your ~/.gimp-2.6/palettes/.&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also, it won't show up on a unit unless they have this line in their unitname.cfg file (not needed anymore since 1.13.6):&lt;br /&gt;
  {MAGENTA_IS_THE_TEAM_COLOR}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You'll need to have some costume element on the unit which can be designated as the team-colored piece of their outfit; It's best to design units around having this.   The easiest way to designate this, is to define a new layer in a capable program (photoshop, gimp, etc), overlaid on the rest of the image, in which you draw with our special values of magenta.&lt;br /&gt;
&lt;br /&gt;
== Time-Saving Tips ==&lt;br /&gt;
&lt;br /&gt;
If units are drawn with a small color set, as used in traditional sprite art, you can use a properly-set paint-bucket tool to replace all instances of a given color.  You'll want to set it to be non-contiguous, non-antialiased and to have a tolerance of 0 (presumably, you also want it to fill based on &amp;quot;all layers&amp;quot; - these settings are based on Photoshop, and the Gimp is likely similar).&lt;br /&gt;
&lt;br /&gt;
If you're working on a sprite which isn't strictly pixel art (e.g. which doesn't have a tiny set of unique RGB values), you're not out of luck at all.  Simply take the same paint-bucket tool with the same settings, and crank the tolerance up to about 20-30.  The paint-bucket will then affect all of those similar, subtle gradations in shade which were achieved with the paintbrush tool, replacing them all with a single color.  Use this with progressively lighter shades, and you'll fill in 90% of the target area, after which it is trivial to fill the holes left behind with a pencil tool.&lt;br /&gt;
&lt;br /&gt;
Also, if you'd like a sane representation of what the final colors will look like, you can shift this separate team-color layer in your graphics application by using a '''temporary''' hue/saturation filter on that layer (I use +40 to the hue on the magenta colors to give a red hue similar but '''not''' identical to the one which the game uses).&lt;br /&gt;
&lt;br /&gt;
It is often easiest to simply sample the colors from a unit to which already has team colors on it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Screenshots ==&lt;br /&gt;
&lt;br /&gt;
This is a screenshot of what a unit would look like if it were drawn directly, without the special pixels:&lt;br /&gt;
&lt;br /&gt;
https://www.wesnoth.org/wiki-images/tutorial/team-color/tcpatch_off.png&lt;br /&gt;
&lt;br /&gt;
This is a screenshot of the team-colored pixels in a separate photoshop layer:&lt;br /&gt;
&lt;br /&gt;
https://www.wesnoth.org/wiki-images/tutorial/team-color/tcpatch_alone.png&lt;br /&gt;
&lt;br /&gt;
And this is what the combined image looks like, which will get mixed-down into a single PNG file:&lt;br /&gt;
&lt;br /&gt;
https://www.wesnoth.org/wiki-images/tutorial/team-color/tcpatch_on.png&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== WML How To ==&lt;br /&gt;
&lt;br /&gt;
(not needed anymore since 1.13.6) We've defined a WML macro to specify a set of magenta colors, as seen in the previous palette.  To use this, you simply sample the color with your graphics program's eyedropper tool, and then draw with it.  The macro is used just like the flag_rgb business - you simply insert the following in your unit .cfg file (for reference, the macro itself is defined in [https://www.wesnoth.org/macro-reference.xhtml#MAGENTA_IS_THE_TEAM_COLOR image-utils.cfg]):&lt;br /&gt;
  {MAGENTA_IS_THE_TEAM_COLOR}&lt;br /&gt;
&lt;br /&gt;
Note that these shift ONLY the precise RGB values given - do not confuse color with hue, because every specific shade - every specific instance with a different luminosity and saturation value - must be specified separately.&lt;br /&gt;
&lt;br /&gt;
The game will shift the color set to one of the team colors; in doing so it will completely overrun the saturation of the original color.  It will change the hue to that of the team, and shift the luminosity as well.  The coloration you give is set in terms of relative luminosity - the entire patch may be bright or dark depending on which team the unit is on.  Also note that the first color specified is special, because it is treated as the median value, and will be assigned the precise luminosity value of the team color.  Anything brighter than it will be brighter than the team color, anything darker will be darker.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design Errata for Nerds/Game-Designers ==&lt;br /&gt;
E.g. &amp;quot;Why we did it the way we did.&amp;quot;  There are a number of other ways to do this, but this was what we settled on.  A different option might have been to use special grayscale image maps to indicate what to change, they would have basically doubled the number of images used by the game.  Alternately, we could have done some bizarre wizardry with graphics files, and included something like an alpha-channel to indicate which pixels to change; we decided against this because that would break the huge advantage of using a very standard format like PNG, which is that everyone can easily grab a program to edit it.  Design nitpickers will notice one minor disadvantage in how we did it.  The colors which get shifted away are inaccessible for direct use; but because they're such a small set of colors, and because they were chosen to be &amp;quot;unusual&amp;quot; colors (rather than common ones like earthtones), it's unlikely that not being able to use these specific RGB values would ever be a problem.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[Create]]&lt;br /&gt;
* [[Art Tutorials]]&lt;br /&gt;
* [[TeamColoring]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Art Tutorials]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=1.17_Roadmap&amp;diff=69362</id>
		<title>1.17 Roadmap</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=1.17_Roadmap&amp;diff=69362"/>
		<updated>2022-02-19T20:31:23Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* 1.17.20 (09/17/2023) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is for consolidating and planning when new features and fixes are intended to land in the 1.17 development branch. The release schedule for Development releases can be found [https://forums.wesnoth.org/viewtopic.php?f=2&amp;amp;t=52785 here]. A thread for discussing this roadmap can also be found [https://forums.wesnoth.org/viewtopic.php?f=2&amp;amp;t=55255 here].&lt;br /&gt;
&lt;br /&gt;
== Instructions ==&lt;br /&gt;
Place the feature or fix you intend to implement within the section of the point release that you intend to have it implemented by, as well as your forum username in parenthesis after the feature description. The point release something is planned to be released with is not set in stone, and can be updated as needed depending on the circumstances.&lt;br /&gt;
&lt;br /&gt;
Additionally, the current set of 1.17 point releases is not final, and can be increased or decreased based on what features and fixes are planned.  The only hard deadline, which ''hopefully'' is not an issue, is to have 1.18 released by February 2024.  This will allow 1.18 to be in the Ubuntu 24.04 LTS release's repositories, and while I realize we don't plan Wesnoth's releases around any distro's schedule, there are also currently no other specific criteria to use as a final deadline. Alternatively, depending on what plans people have, 1.18 can be scheduled to happen earlier than that (in 2023).&lt;br /&gt;
&lt;br /&gt;
== 1.17.0 (01/16/2022) ==&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/6292 #6292] Fix+backport &amp;quot;Multi-turn moves are visible to enemy players&amp;quot; (octalot)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/6283 #6283] Fix+backport &amp;quot;OOS watching MP replays&amp;quot; (Pentarctagon)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/6285 #6285] Fix+backport &amp;quot;Multiplayer scenarios with custom terrains don't load for non-host&amp;quot; (already done by Pentarctagon)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/6315 #6315] Fix+backport &amp;quot;[store_unit] and [modify_unit] move units from recall list to map&amp;quot; (octalot or celticminstrel)&lt;br /&gt;
&lt;br /&gt;
== 1.17.1 (02/20/2022) ==&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/pull/6460 #6460] Add+backport Editor docs about the pink &amp;quot;D&amp;quot; deprecation marker (octalot)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/6383 #6383] Fix+backport (Pentarctagon)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/6400 #6400] Fix+backport show in the terrain help that oases heal (octalot)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/6483 #6483] Inline luadoc (CM)&lt;br /&gt;
&lt;br /&gt;
== 1.17.2 (03/20/2022) ==&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/6225 #6225] Fix+backport Clarify editor docs about terrain mode, possibly revise error handling UX (octalot)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/5892 #5892] wesnoth.game_events.on_mouse_move (CM)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/5837 #5837] Lua floating labels API (CM)&lt;br /&gt;
&lt;br /&gt;
== 1.17.3 (04/17/2022) ==&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/6305 #6305] Fix &amp;quot;[foreach]array=this_item.something does not write back to the outer this_item&amp;quot;. Undecided whether to backport. (octalot)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/6422 #6422] Fix+backport hide editor hints about shift+click (octalot)&lt;br /&gt;
&lt;br /&gt;
== 1.17.4 (05/15/2022) ==&lt;br /&gt;
* Add forum_auth support to campaignd (Pentarctagon)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/5663 #5663] Lua game events API (CM)&lt;br /&gt;
&lt;br /&gt;
== 1.17.5 (06/19/2022) ==&lt;br /&gt;
* UtBS S12 (The Final Confrontation) Rework (knyghtmare)&lt;br /&gt;
* scenario_boss Micro AI (maybe it will be UtBS specific but it remains to be seen) (knyghtmare)&lt;br /&gt;
* Untitled RPG scenario/mini-campaign (depends on my schedule) (knyghtmare)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/5818 #5818] dir() function for Lua (CM)&lt;br /&gt;
&lt;br /&gt;
== 1.17.6 (07/17/2022) ==&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/993 #993] Lua map generator improvements and new random cave map MP scenario (CM)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/5838 #5838] Expose more data to map generators (CM)&lt;br /&gt;
&lt;br /&gt;
== 1.17.7 (08/21/2022) ==&lt;br /&gt;
* Finish adding code comments for the WML unit tests (Pentarctagon)&lt;br /&gt;
&lt;br /&gt;
== 1.17.8 (09/18/2022) ==&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/issues/5041 #5041] Draw text on images in [[IntroWML]], useable for place-name labels on the journey-tracker maps (octalot)&lt;br /&gt;
* Reorganize the WML unit test file/folder structure so it's easier to find specific tests without using grep (Pentarctagon)&lt;br /&gt;
&lt;br /&gt;
== 1.17.9 (10/16/2022) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1.17.10 (11/20/2022) ==&lt;br /&gt;
* sprite palette cleanup completed (doofus-01)&lt;br /&gt;
&lt;br /&gt;
== 1.17.11 (12/18/2022) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1.17.12 (01/15/2023) ==&lt;br /&gt;
* New multiplayer maps focused on player vs player vs ai (Hejnewar)&lt;br /&gt;
* Revert [https://github.com/wesnoth/wesnoth/pull/6463 #6463] removing the deprecated SPECIAL_NOTES macro again (octalot)&lt;br /&gt;
&lt;br /&gt;
== 1.17.13 (02/19/2023) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1.17.14 (03/19/2023) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1.17.15 (04/16/2023) ==&lt;br /&gt;
* finalize sprite palettes and swatches for defined recoloring (doofus-01)&lt;br /&gt;
&lt;br /&gt;
== 1.17.16 (05/21/2023) ==&lt;br /&gt;
* (tentative) New WML tags for custom alignments, damage types, and weapon ranges (CM)&lt;br /&gt;
&lt;br /&gt;
== 1.17.17 (06/18/2023) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1.17.18 (07/16/2023) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1.17.19 (08/20/2023) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1.17.20 (09/17/2023) ==&lt;br /&gt;
* Continue adding more WML/lua unit tests to improve API coverage (Pentarctagon)&lt;br /&gt;
* Balance changes focused mostly on higher levels and experience (Hejnewar)&lt;br /&gt;
* Hybrid Dunefolk campaign (Hejnewar)&lt;br /&gt;
* Rewrite of LoW, tentatively as SP campaign (nemaara)&lt;br /&gt;
* [https://github.com/wesnoth/wesnoth/pull/5532 #5532] Add the Elemental units to the core directory (Elvish_Hunter)&lt;br /&gt;
&lt;br /&gt;
== 1.17.21 (10/15/2023) (Beta 1) ==&lt;br /&gt;
'''This marks the beginning of the feature freeze and string freeze for 1.17;''' the only API changes made past this point must be to fix bugs.&lt;br /&gt;
&lt;br /&gt;
== 1.17.22 (11/19/2023) (Beta 2) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1.17.23 (12/17/2023) (Beta 3) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 1.17.24 (01/21/2024) (RC1) ==&lt;br /&gt;
'''This marks the beginning of the API freeze;''' no API changes for for any reason can be made at this point. Additional RC releases will be done as needed.&lt;br /&gt;
&lt;br /&gt;
== 1.18.0 (02/18/2024) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Roadmaps]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=69165</id>
		<title>DirectActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=69165"/>
		<updated>2022-01-16T13:00:13Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [harm_unit] */ Add support for the id= key in the array&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== Direct actions ==&lt;br /&gt;
&lt;br /&gt;
Direct actions are actions that have a direct effect on gameplay. They can be used inside of [[EventWML|events]].&lt;br /&gt;
&lt;br /&gt;
The following tags are actions:&lt;br /&gt;
&lt;br /&gt;
=== [endlevel] ===&lt;br /&gt;
Ends the scenario.&lt;br /&gt;
* '''result''': before the scenario is over, all events with ''name=result'' are triggered. If ''result=victory'', the player progresses to the next level (i.e., the next scenario in single player); if ''result=defeat'', the game returns to the main menu. &lt;br /&gt;
&lt;br /&gt;
When the result is &amp;quot;victory&amp;quot; the following keys can be used:&lt;br /&gt;
* '''bonus''': whether the player should get bonus gold (maximum possible gold that could have been earned by waiting the level out). The default is bonus=yes. {{DevFeature1.13|2}} Alternatively, a number, defining the bonus multiple (1.0 meaning full).&lt;br /&gt;
* '''carryover_report''': whether the player should receive a summary of the scenario outcome, the default is carryover_report=yes.&lt;br /&gt;
* '''save''': whether a start-of-scenario save should be created for the next scenario, the default is save=yes. Do not confuse this with saving of replays for the current scenario.&lt;br /&gt;
* '''replay_save''': whether a replay save for the current scenario is allowed, the default is replay_save=yes. If yes, the player's settings in preferences will be used to determine if a replay is saved. If no, will override and not save a replay.&lt;br /&gt;
* '''linger_mode''': If ...=yes, the screen is greyed out and there's the possibility to save before advancing to the next scenario, the default is linger_mode=yes.&lt;br /&gt;
* '''reveal_map''': (Multiplayer only) (Default is 'yes') If 'no', shroud doesn't disappear when game ended.&lt;br /&gt;
* '''next_scenario''': (default specified in '''[scenario]''' tag) the ID of the next scenario that should be played.  All units that side 1 controls at this point become available for recall in ''next_scenario''.&lt;br /&gt;
* '''carryover_percentage''': by default 80% of the gold is carried over to the next scenario, with this key the amount can be changed.&lt;br /&gt;
* '''carryover_add''': if yes the gold will be added to the starting gold the next scenario, if no the next scenario will start with the amount of the current scenario (after taxes) or the minimum in the next scenario. Default is no.&lt;br /&gt;
* '''music''': (default specified in '''[scenario]''' or '''[game_config]''' tags) a comma-separated list of music tracks from which one will be chosen and played once after any events related to the end of level result are executed; by default, victory_music is used on victory, and defeat_music on defeat.&lt;br /&gt;
* '''end_credits''': Whether to display the credits screen at the end of a single-player campaign. Defaults to ''yes''. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text''': (translatable) Text that is shown centered in a black screen at the end of a campaign. Defaults to &amp;quot;The End&amp;quot;. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text_duration''': Delay, in milliseconds, before displaying the game credits at the end of a campaign. In other words, for how much time '''end_text''' is displayed on screen. Defaults to 3500. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* &amp;lt;strike&amp;gt;'''[next_scenario_settings]''': Any tags or attribute children of this optional argument to [endlevel] are merged into the scenario/multiplayer tag of the *next* scenario. This allows you to e.g. reconfigure the [side] tags or settings, just before load. &amp;lt;/strike&amp;gt; This feature was removed in 1.11.17, it might be redesigned and reintroduced.&lt;br /&gt;
* &amp;lt;strike&amp;gt;'''[next_scenario_append]''': Any tags of this optional argument are appended at high level to the next scenario. This is most appropriate for [event] tags, although you may find other uses. Example test scenario for these features: https://gna.org/support/download.php?file_id=20119 &amp;lt;/strike&amp;gt; This feature was removed in 1.11.17, it might be redesigned and reintroduced.&lt;br /&gt;
* '''[result]''' {{DevFeature1.13|0}} Allows specification of a side specific result, this is for competitive multiplayer scenarios/campaigns where it might happen that one player wins but another player loses.  The following attributes are accepted and have the same effect as in '''[endlevel]''':&lt;br /&gt;
** '''result'''&lt;br /&gt;
** '''bonus'''&lt;br /&gt;
** '''carryover_percentage'''&lt;br /&gt;
** '''carryover_add'''&lt;br /&gt;
&lt;br /&gt;
And there is also&lt;br /&gt;
** '''side''' The number of the side for which these results should apply.&lt;br /&gt;
&lt;br /&gt;
=== [unit] ===&lt;br /&gt;
Creates a unit (either on the map, on a recall list, or into a variable for later use.)  For syntax see [[SingleUnitWML]].&lt;br /&gt;
* {{Short Note:Predefined Macro|GENERIC_UNIT}}&lt;br /&gt;
&lt;br /&gt;
This tag can also recall an existing unit, which happens when:&lt;br /&gt;
* the '''id=''' attribute is used&lt;br /&gt;
* a unit with that '''id=''' already exists&lt;br /&gt;
* (might be unnecessary) the existing unit is on the side's recall list&lt;br /&gt;
in this case, the unit is recalled at the '''x,y=''' or '''location_id=''' given, and any other data in the tag is ignored.&lt;br /&gt;
&lt;br /&gt;
Campaign authors: a usual way to recall plot-necessary heroes is to use a macro with the data for creating that hero. This helps during debugging, because you can skip to scenarios and the recall-or-create functionality means that any units which are normally met in a previous scenario are automatically created (otherwise some scenarios may be an instant loss). This can only be used for units that must survive the previous scenarios, as it would recreate units if they died in a previous scenario.&lt;br /&gt;
For example,&lt;br /&gt;
[https://github.com/wesnoth/wesnoth/blob/1.14.7/data/campaigns/Heir_To_The_Throne/utils/httt_utils.cfg#L685 HttT's NEED_DELFADOR macro].&lt;br /&gt;
&lt;br /&gt;
=== [recall] ===&lt;br /&gt;
Recalls a unit taking into account any [http://wiki.wesnoth.org/SingleUnitWML filter_recall] of the leader.   The unit is recalled free of charge, and is placed near its leader, e.g., if multiple leaders are present, near the first found which would be able to normally recall it.&lt;br /&gt;
&lt;br /&gt;
If neither a valid map location is provided nor a leader on the map would be able to recall it, the tag is ignored.&lt;br /&gt;
 &lt;br /&gt;
* [[StandardUnitFilter]]: the first matching unit will be recalled.  If no units match this tag is ignored. Do not use a [filter] tag. If a comma separated list is given, every unit currently considered for recall is checked against all the types (not each single one of the types against all units).&lt;br /&gt;
* '''x,y''': the unit is placed here instead of next to the leader.&lt;br /&gt;
* '''location_id''': {{DevFeature1.15|0}} the name of a special map location to recall to. Used instead of '''x,y'''.&lt;br /&gt;
* '''show''': yes/no, default yes: whether the unit is animated (faded in) or instantly displayed&lt;br /&gt;
* '''fire_event''': boolean yes|no (default no); whether any according prerecall or recall events shall be fired.&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit (a nearby passable hex is chosen).&lt;br /&gt;
* '''[secondary_unit]''': {{DevFeature1.13|?}} If present and show=yes, a matching unit will be chosen and their recruiting animation played.&lt;br /&gt;
&lt;br /&gt;
=== [teleport] ===&lt;br /&gt;
Teleports a unit on map. {{Short Note:Predefined Macro|TELEPORT_UNIT}}&lt;br /&gt;
* '''[filter]''': [[StandardUnitFilter]] the first unit matching this filter will be teleported.&lt;br /&gt;
* '''x,y''': the hex to teleport to. If that hex is occupied, the closest unoccupied hex will be used instead.&lt;br /&gt;
* '''location_id''': {{DevFeature1.15|0}} the name of a special map location to teleport to. Used instead of '''x,y'''.&lt;br /&gt;
* '''clear_shroud''': should shroud be cleared on arrival&lt;br /&gt;
* '''animate''': should a teleport animation be played (if the unit doesn't have a teleport animation, it will fade out/fade in)&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): normally, units will not be teleported into terrain that is impassable for them. Setting this attribute to &amp;quot;no&amp;quot; permits it.&lt;br /&gt;
&lt;br /&gt;
(Note: There is also a ability named teleport, see [[AbilitiesWML]].)&lt;br /&gt;
&lt;br /&gt;
=== [terrain_mask] ===&lt;br /&gt;
Changes the terrain on the map.  See [[TerrainMaskWML]].&lt;br /&gt;
&lt;br /&gt;
=== [terrain] ===&lt;br /&gt;
Changes the terrain on the map.&lt;br /&gt;
* '''terrain''': the character of the terrain to use.  See [[TerrainCodesWML]] to see what letter a type of terrain uses.&lt;br /&gt;
* [[StandardLocationFilter]]. This [[StandardLocationFilter]]'s terrain= key is used for the new terrain, filtering by terrain can be done with a nested [[StandardLocationFilter]]: [and]terrain=terrain_string_to_be_filtered_for.&lt;br /&gt;
* '''layer''': (overlay|base|both, default=both) only change the specified layer.&lt;br /&gt;
* '''replace_if_failed''': (default=no) When replacing just one layer failed, try to replace the whole terrain. If '''terrain''' is an overlay only terrain, use the default_base as base layer. If the terrain has no default base, do nothing.&lt;br /&gt;
&lt;br /&gt;
If you want to remove the overlays from a terrain and leave only the base, use:&lt;br /&gt;
 layer=overlay&lt;br /&gt;
 terrain=&amp;quot;^&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages is that there are too many choices to make; should a unit lose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [gold] ===&lt;br /&gt;
Gives sides gold.&lt;br /&gt;
* '''amount''': the amount of gold to give.&lt;br /&gt;
* '''side''': (default=1) the number of the side to give the gold to. Can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [unstore_unit] ===&lt;br /&gt;
Creates a unit from a game variable, and activates it on the playing field or recall list.  This must be a specific variable describing a unit, and may not be an array (if it is, only the first unit will be unstored).&lt;br /&gt;
&lt;br /&gt;
This may be useful in different contexts:&lt;br /&gt;
* To update a unit on the map after having edited its WML. This usage is common, but discouraged - if possible, you should use [[#.5Bmodify_unit.5B|[modify_unit]]] or [[#.5Bobject.5B|[object]]] instead.&lt;br /&gt;
* To place a previously-defined unit into the scenario, if it was directly defined in a WML variable, using [unit] with the key '''to_variable'''. This usage is rather uncommon.&lt;br /&gt;
* To place a unit back into the game that was removed earlier, for example a hero that leaves the party for awhile and then comes back.&lt;br /&gt;
&lt;br /&gt;
The variable is not cleared. To unstore units from an array variable, iterate over the array. See [[SyntaxWML]] and [[VariablesWML/How to use variables]] for more information about variable usage. See also [[InternalActionsWML#.5Bstore_unit.5D|[store_unit]]], [[ConditionalActionsWML|For]], [[ConditionalActionsWML#.5Bwhile.5D|[while]]] and [[InternalActionsWML#.5Bclear_variable.5D|[clear_variable]]].&lt;br /&gt;
&lt;br /&gt;
The tag takes the following keys:&lt;br /&gt;
* '''variable''': This is required to indicate the name of the variable to read the unit from.&lt;br /&gt;
* '''Placement keys''':&lt;br /&gt;
** '''x''' ,'''y''': By default, the unit will be placed at the location specified in the variable, but if these keys are present, the unit will be placed at that location instead. To place the unit on the recall list of its side, use '''x,y=recall,recall'''. (If you want to change the said, you need to first update ''$unit.side'' in the variable before unstoring.)&lt;br /&gt;
** '''location_id''': {{DevFeature1.15|0}} The name of a special map location to unstore to. Used instead of '''x,y'''.&lt;br /&gt;
** '''find_vacant''' (yes|no, default no): Whether the unit should be placed on the nearest vacant tile to its specified location. If this is set to 'no' (default), then any unit on the same tile as the unit being unstored will be destroyed.&lt;br /&gt;
** '''check_passability''' (yes|no, default yes): Only relevant if '''find_vacant=yes'''. In that case, this determines whether game will try to find a passable tile for the unit. If set to no, the unit may be placed on an impassable tile. Note that if both '''find_vacant''' and '''check_passability''' are set, then the unit's position may be shifted even if there is not a unit on the target space, if that space is not passable for the unit.&lt;br /&gt;
* '''Animation keys''' (these determine the visual effect of how the unit is placed or updated):&lt;br /&gt;
** '''text''': (translatable) A floating text to display above the unit, such as a damage amount.&lt;br /&gt;
** '''male_text''', '''female_text''': {{DevFeature1.13|2}} (translatable) gender-specific versions of the above&lt;br /&gt;
** '''red''', '''green''', '''blue''': (default=0,0,0) the color of the text. Values vary from 0-255. You may find it convenient to use the {COLOR_HARM} or {COLOR_HEAL} macro instead. (Use {COLOR_HARM} or {COLOR_HEAL} instead of the whole red,green,blue= line.)&lt;br /&gt;
** '''animate''': (boolean yes|no, default yes) Determines whether to play any animations associated with the unstore. Currently this only affects the advancement animation (&amp;quot;levelout&amp;quot; and &amp;quot;levelin&amp;quot;, defaulting to a fade to white and back) if the unit ends up advancing.&lt;br /&gt;
* '''Side-effect keys''' (these directly modify the behaviour of the action):&lt;br /&gt;
** '''advance''': (default=yes) if yes the unit is advanced if it has enough XP. When modifying XP, make sure to do it from inside a [[EventWML#Multiplayer_safety|synchronized event]] or it may lead to OOS errors, especially when several advancement paths exist. Note that advance and post advance events are called, so infinite loops can happen.&lt;br /&gt;
** '''fire_event''' (yes|no, default no): Whether any advance/post advance events shall be fired if an advancement takes place. This also affects whether the unit placed event is fired.&lt;br /&gt;
&lt;br /&gt;
Units can be unstored with negative (or zero) hit points. This can be useful if modifying a unit in its last_breath event (as the unit's death is already the next step), but tends to look wrong in other cases. In particular, it is possible to have units with negative hit points in play. Such units are aberrations, subject to unusual behavior as the game compensates for them. (For example, such units are currently automatically hit&amp;amp;ndash;and killed&amp;amp;ndash;in combat.) The details of the unusual behavior are subject to change between stable releases without warning.&lt;br /&gt;
&lt;br /&gt;
=== [allow_recruit] ===&lt;br /&gt;
Allows a side to recruit units it couldn't previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that is being allowed to recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [allow_extra_recruit] ===&lt;br /&gt;
Allows a leader to recruit units it couldn't previously recruit.&lt;br /&gt;
These types add to the types the leader can recruit because of [side]recruit=.&lt;br /&gt;
* '''extra_recruit''': the types of units that the unit can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_recruit] ===&lt;br /&gt;
Prevents a side from recruiting units it could previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can no longer recruit. {{DevFeature1.13|0}} If omitted, all recruits for matching sides will be disallowed.&lt;br /&gt;
* '''side''': (default=1) the number of the side that may no longer recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_extra_recruit] ===&lt;br /&gt;
Prevents a leader from recruiting units it could previously recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the side can no longer recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [set_recruit] ===&lt;br /&gt;
Sets the units a side can recruit.&lt;br /&gt;
* '''recruit''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': The number of the side that is having its recruitment set. This can be a comma-separated list.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [set_extra_recruit] === &lt;br /&gt;
Sets the units a leader can recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the leader can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [modify_side] ===&lt;br /&gt;
Modifies some details of a given side in the middle of a scenario.  '''The following listed properties are the only properties that [modify_side] can affect!'''&lt;br /&gt;
* '''side''': (default=1) the number of the side that is to be changed. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* '''income''': the income given at the begining of each turn.&lt;br /&gt;
* '''recruit''': a list of unit types, replacing the side's current recruitment list.&lt;br /&gt;
* '''team_name''': the team in which the side plays the scenario.&lt;br /&gt;
* '''user_team_name''': a translatable string representing the team's description. This has no effect on alliances. Defaults to ''team_name''.&lt;br /&gt;
* '''side_name''': {{DevFeature1.13|?}} a translatable string representing the side leader's description.&lt;br /&gt;
* '''gold''': the amount of gold the side owns.&lt;br /&gt;
* '''village_gold''': the income setting per village for the side.&lt;br /&gt;
* '''controller''': the identifier string of the side's controller. Uses the same syntax of the ''controller'' key in the [[SideWML|[side]]] tag. warning: in multiplayer, changing the controller of a side might result in OOS during some events like, for example 'side_turn_end'; see [https://github.com/wesnoth/wesnoth/issues/2563 issue #2563].&lt;br /&gt;
* '''fog''': a boolean string (yes/no) describing the status of Fog for the side.&lt;br /&gt;
* '''shroud''': a boolean string describing the status of Shroud for the side.&lt;br /&gt;
* '''hidden''': a boolean string specifying whether side is shown in status table.&lt;br /&gt;
* '''color''': a team color range specification, name (e.g. &amp;quot;red&amp;quot;, &amp;quot;blue&amp;quot;), or number (e.g. &amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;) for this side. The default color range names, numbers, and definitions can be found in data/core/team_colors.cfg.&lt;br /&gt;
* '''[ai]''': sets/changes AI parameters for the side. Only parameters that are specified in the tag are changed, this does not reset others to their default values. Uses the same syntax as described in [[AiWML]].  Note that [modify_side][ai] works for all simple AI parameters and some, but not all, of the composite ones. If in doubt, use [http://wiki.wesnoth.org/AiWML#Adding_and_Deleting_Aspects_with_the_.5Bmodify_ai.5D_Tag [modify_ai]] instead, which always works. {{DevFeature1.13|?}} If this contains an '''ai_algorithm''', the AI parameters will be reset to those of the indicated AI before adding any additional parameters included in the tag. In other words, this allows replacing the AI config rather than appending to it.&lt;br /&gt;
* '''switch_ai''': replaces a side ai with a new AI from specified file(ignoring those AI parameters above). Path to file follows the usual WML convention.&lt;br /&gt;
* '''reset_maps''': If set to &amp;quot;yes&amp;quot;, then the shroud is spread to all hexes, covering the parts of the map that had already been explored by the side, including hexes currently seen. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if shroud is on, but this is evaluated after shroud= (and before shroud_data=).&lt;br /&gt;
* '''reset_view''': If set to &amp;quot;yes&amp;quot;, then the fog of war is spread to all hexes, covering the parts of the map that had already been seen this turn by the side, including hexes currently seen, excluding hexes affected by multi-turn {{tag|DirectActionsWML|lift_fog}}. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if fog is on, but this is evaluated after fog=.&lt;br /&gt;
* '''share_maps''': change the share_maps side attribute. Be sure to use shroud=yes for that side and have it as an ally&lt;br /&gt;
* '''share_view''': change the share_view side attribute. Be sure to use fog=yes for that side and have it as an ally&lt;br /&gt;
* '''share_vision''': change both the above at the same time&lt;br /&gt;
* '''shroud_data''': changes to the side's shroud, using the same format as when defining the [side].&lt;br /&gt;
* '''suppress_end_turn_confirmation''': Boolean value controlling whether or not a player is asked for confirmation when skipping a turn.&lt;br /&gt;
* '''scroll_to_leader''': Boolean value controlling whether or not the game view scrolls to the side leader at the start of their turn when present.&lt;br /&gt;
* '''flag''': Flag animation for villages owned by this side (see [[SideWML|[side]]]).&lt;br /&gt;
* '''flag_icon''': Flag icon used for this side in the status bar (see [[SideWML|[side]]]).&lt;br /&gt;
* '''village_support''': The number of unit levels this side is able to support (does not pay upkeep on) per village it controls.&lt;br /&gt;
* '''defeat_condition''' {{DevFeature1.13|0}}: When the side is considered defeated (see [[SideWML|[side]]]).&lt;br /&gt;
* '''[set_variable]''', '''[clear_variable]''' {{DevFeature1.15|3}} Sets or clears a variable within the side; uses the same syntax as [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] or [[InternalActionsWML#.5Bclear_variable.5D|[clear_variable]]] in ActionWML.&lt;br /&gt;
* '''[variables]''' {{DevFeature1.15|3}} The contents of this tag is merged into the side's variables.&lt;br /&gt;
&lt;br /&gt;
=== [modify_turns] ===&lt;br /&gt;
Modifies the turn limit in the middle of a scenario.&lt;br /&gt;
* '''value''': the new turn limit.&lt;br /&gt;
* '''add''': if used instead of ''value'', specifies the number of turns to add to the current limit (can be negative).&lt;br /&gt;
* '''current''': changes the current turn number after applying turn limit modifications, if any. It is not possible to change the turn number to exceed the turn limit (1 &amp;lt;= current turns &amp;lt;= max turns).&lt;br /&gt;
&lt;br /&gt;
=== [allow_end_turn] ===&lt;br /&gt;
Allows human players to end their turn through the user interface if they were previously affected by the '''[disallow_end_turn]''' action. This action doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_end_turn] ===&lt;br /&gt;
Disallows human players to end their turn through the user interface. This action doesn't require arguments.&lt;br /&gt;
* '''reason''' (translatable): {{DevFeature1.15|0}} Allows to optionally specify a reason.&lt;br /&gt;
&lt;br /&gt;
=== [capture_village] ===&lt;br /&gt;
Changes the ownership of a village.&lt;br /&gt;
* [[StandardLocationFilter]]: all village locations matching the filter are affected.&lt;br /&gt;
* '''side''': the side that takes control of the village. This side needs to have a leader (canrecruit=yes). If the side key is not given, the village will become neutral (unless [filter_side] is present, in which case that side fiter decides, see below).&lt;br /&gt;
* '''[filter_side]''' with [[StandardSideFilter]] tags and keys as arguments; if both this tag and inline side= are present it's an error. Otherwise, the first matching side gets ownership (or the village becomes neutral if none match).&lt;br /&gt;
* '''fire_event''' (boolean yes|no, default: no): Whether any capture events shall be fired.&lt;br /&gt;
&lt;br /&gt;
=== [kill] ===&lt;br /&gt;
Removes all units (including units in a recall list) that match the filter from the game.&lt;br /&gt;
* [[StandardUnitFilter]]: Selection criterion; do not use a [filter] tag.&lt;br /&gt;
* '''animate''' (default 'no'): if 'yes', displays the unit dying (fading away). {{DevFeature1.13|8}} If '''[secondary_unit]''' is given, also plays the victory animation of that unit.&lt;br /&gt;
* '''fire_event''' (default 'no'): if 'yes', triggers any appropriate 'die' events (See [[EventWML]]). Note that events are only fired for killed units that have been on the map (as opposed to recall list).&lt;br /&gt;
* '''[secondary_unit]''' with a [[StandardUnitFilter]] as argument. Do not use a [filter] tag. Has an effect only if fire_event=yes ({{DevFeature1.13|8}} or if it has a victory animation and animate=yes). The first on-map unit matching the filter becomes second_unit in any fired die and last breath events. If an on-map unit matches and if there are several units killed with a single [kill] tag, second_unit is this same unit for all of them. If no on-map unit matches or [secondary_unit] isn't present, the variable second_unit in each of the die and last breath events is always the same as the variable unit (the dying unit).&lt;br /&gt;
* '''[primary_attack]''', '''[secondary_attack]''' {{DevFeature1.13|8}} The attacks to use for matching the animation. Useful for example on the wose, whose death animation depends on the damage type it was killed by.&lt;br /&gt;
&lt;br /&gt;
=== [move_unit] ===&lt;br /&gt;
Moves a unit along a path on the map. The path can be specified exactly, or as a series of waypoints that the unit will pass through.&lt;br /&gt;
* [[StandardUnitFilter]] as argument; do not use a [filter] tag. All units matching the filter are moved. If the target location is occupied, the nearest free location is chosen.&lt;br /&gt;
* '''to_x''' (unsigned integer): The units are moved to this x coordinate. Can be a comma-separated list, in which case the unit follows this given path during the move.&lt;br /&gt;
* '''to_y''' (unsigned integer): The units are moved to this y coordinate. Can be a comma-separated list.&lt;br /&gt;
* '''dir''' (string): {{DevFeature1.15|0}} Performs a relative movement instead of an absolute movement. For example, dir=n,n,nw will move two spaces north and then one space to the northwest. This is used instead of '''to_x''' and '''to_y'''.&lt;br /&gt;
* '''to_location''': {{DevFeature1.15|0}} Moves matching units to locations placed in the map editor with the &amp;quot;New Location&amp;quot; button. Can be a comma-separated list. This is used instead of '''to_x''' and '''to_y'''.&lt;br /&gt;
* '''check_passability''' (boolean yes|no, default yes): Whether the terrain the unit is moved to should be checked for suiting the unit. (If it does not, a nearby suitable hex is chosen.)&lt;br /&gt;
* '''force_scroll''': Whether to scroll the map or not even when [[InterfaceActionsWML#.5Block_view.5D|[lock_view]]] is in effect or ''Follow Unit Actions'' is disabled in ''Advanced Preferences''. Defaults to using [[InterfaceActionsWML#.5Bmove_unit_fake.5D|[move_unit_fake]]]'s default value.&lt;br /&gt;
* '''clear_shroud''': {{DevFeature1.15|0}} (boolean yes|no, default no) Whether to remove shroud and fog after the unit was moved, but before events are fired. It will not clear all alongside the path, only around the target destination.&lt;br /&gt;
* '''fire_event''' (boolean yes|no, default no): Whether any according moveto events shall be fired. The target location ($x1, $y1 in the event) may not be the same location that the unit was tried to be moved to, if the original target location is occupied or impassable.&lt;br /&gt;
&lt;br /&gt;
=== [modify_ai] ===&lt;br /&gt;
Changes AI objects (aspects, goals, candidate actions or stages) for a specified side. See [[Modifying_AI_Components#The_.5Bmodify_ai.5D_Tag|Modifying AI Components]] for full description.&lt;br /&gt;
&lt;br /&gt;
* '''action''' (string): Takes values 'add', 'change', 'delete' or 'try_delete' to do just that for the AI object.&lt;br /&gt;
* '''path''' (string): Describes which AI object is to be modified.  &lt;br /&gt;
* '''[facet]''', '''[goal]''', '''[candidate_action]''' or '''[stage]''': Details about the AI object to be modified.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [modify_unit] ===&lt;br /&gt;
works similar to the MODIFY_UNIT macro.&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. All units matching this filter are modified. Matches on recall list units too.&lt;br /&gt;
* '''[object]''', '''[trait]''', {{DevFeature1.13|5}} '''[advancement]''' - The given modifications will be immediately applied to all units matching the filter. ([object] is described further below)&lt;br /&gt;
** '''delayed_variable_substitution''' {{DevFeature1.13|5}} (boolean yes|no, default no): If set to &amp;quot;yes&amp;quot;, the wml block contained in this [object], [trait], or [advancement] is not variable-substituted at execution time of the event containing this [modify_unit]. You need this for any effect that uses variable substitution or when using [effect][filter] with a $this_unit. {{DevFeature1.13|9}} This is no longer needed when adding ABILITY_TELEPORT, ABILITY_LEADERSHIP or SPECIAL_BACKSTAB.&lt;br /&gt;
** Do not use a '''[modifications]''' tag, as this may skip some of the special-case handling for newly added objects, traits and advancements.&lt;br /&gt;
* '''[effect]''' {{DevFeature1.13|6}} Applies the effect directly to the unit. See [[EffectWML]].&lt;br /&gt;
* '''[set_variable]''', '''[clear_variable]''' {{DevFeature1.15|3}} Sets or clears a variable within the unit; uses the same syntax as [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] or [[InternalActionsWML#.5Bclear_variable.5D|[clear_variable]]] in ActionWML.&lt;br /&gt;
* Accepts generally the syntax inside of wml unit variables created by [store_unit] which can be viewed in a savefile or by using the [[CommandMode|inspect command]]. Cannot remove things or add/alter unit animations. Subtags with the same name must be written in the correct order to match them with the tag they are supposed to modify. Note that keys will be processed in arbitrary order, which may cause problems if you use formulas that depend on other formulas. To work around this you may need to use the tag twice with the same filter.&lt;br /&gt;
example usage (see also the test scenario):&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
[modify_unit]&lt;br /&gt;
  [filter]&lt;br /&gt;
    x,y=38,6&lt;br /&gt;
  [/filter]&lt;br /&gt;
  hitpoints=10&lt;br /&gt;
  {TRAIT_HEALTHY}&lt;br /&gt;
[/modify_unit]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The unit which is currently modified is accessible via $this_unit, e.g. hitpoints = &amp;quot;$($this_unit.hitpoints / 2)&amp;quot; to set the hitpoints of all units to half of their particular maxima. This this_unit variable is independent from the this_unit variable available in the SUF used to determine which units to modify (first all matching units are gathered, and then all those are modified).&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Some some properties of the units are reset sometimes (for example when the unit advances or when [remove_object] is called), so it's usually better to change them with [object] ([object] inside [modify_unit]) than to change those properties directly via [modify_unit]. The following properties are _not_ reset in [remove_object] and are thus safe to use directly in [modify_unit]:&lt;br /&gt;
* '''side'''&lt;br /&gt;
* '''gender'''&lt;br /&gt;
* '''name'''&lt;br /&gt;
* '''canrecruit'''&lt;br /&gt;
* '''unrenamable'''&lt;br /&gt;
* '''extra_recruit'''&lt;br /&gt;
* '''[variables]'''&lt;br /&gt;
* '''facing'''&lt;br /&gt;
* '''goto_x, goto_y'''&lt;br /&gt;
* '''hitpoints'''&lt;br /&gt;
* '''experience'''&lt;br /&gt;
* '''moves'''&lt;br /&gt;
* '''[status]''' (not sure on this one)&lt;br /&gt;
* '''attacks_left'''&lt;br /&gt;
* '''role'''&lt;br /&gt;
&lt;br /&gt;
=== [transform_unit] ===&lt;br /&gt;
Transforms every unit on the map matching the filter to the given unit type. Keeps intact hit points, experience and status. If the unit is transformed to a non-living type (undead or mechanical), it will be also unpoisoned. Hit points will be changed if necessary to respect the transformed unit's maximum hit points.&lt;br /&gt;
* [[StandardUnitFilter]]: do not use a [filter] tag.&lt;br /&gt;
* '''transform_to''': the unit type in which all the units matching the filter will be transformed. If missing, the units will follow their normal advancement.&lt;br /&gt;
&lt;br /&gt;
=== [petrify] ===&lt;br /&gt;
&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are petrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [unpetrify] ===&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are unpetrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [object] ===&lt;br /&gt;
Gives some unit an object which modifies their stats in some way.&lt;br /&gt;
* '''id''': (Optional) allows the item to be removed later. By default, an object with a defined ID can only be picked up once per scenario, even if it is removed later or first_time_only=no is set for the event. You can remove this restriction by setting take_only_once=no. For filtering objects, it might be simpler to use a custom key such as item_id. The id string can contain only letters, numbers and underscores.&lt;br /&gt;
* '''take_only_once''': (default yes) {{DevFeature1.13|6}} If set to &amp;quot;no&amp;quot;, the object's ID does not prevent it from being taken more than once.&lt;br /&gt;
* '''delayed_variable_substitution''' (boolean yes|no, default no): If set to &amp;quot;yes&amp;quot;, the wml block contained in this [object] is not variable-substituted at execution time of the event where this [object] is within.  You need this for any effect that uses variable substitution or when using [effect][filter] with a $this_unit. {{DevFeature1.13|9}} This is no longer needed when adding ABILITY_TELEPORT, ABILITY_LEADERSHIP or SPECIAL_BACKSTAB.&lt;br /&gt;
* '''[effect]''': one or more effect elements may be listed.  See [[EffectWML]] for a description of [effect].&lt;br /&gt;
* '''duration''':&lt;br /&gt;
**if 'scenario', effects only last until the end of the scenario.&lt;br /&gt;
**if 'forever' or not set, effects never wear off.&lt;br /&gt;
** if 'turn', effects only last until the start of the unit's next turn (when the unit refreshes movement and attacks). (Like other start-of-turn behavior, objects with a duration of &amp;quot;turn&amp;quot; won't expire before turn 2.)&lt;br /&gt;
** {{DevFeature1.13|1}} if 'turn end' or 'turn_end', effects only last until the end of the unit's next turn (exactly like the slowed status).&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. The first unit found that matches the filter will be given the object. Only on-map units are considered. If no unit matches or no [filter] is supplied, it is tried to apply the object to the unit at the $x1,$y1 location of the event where this [object] is in. The case of no unit being at that spot is handled in the same way as no unit matching a given filter ([else] commands executed, cannot_use_message displayed). Note that units on the recall list will not be checked. To add an [object] to a unit on the recall list you have to use '''[modify_unit][object]'''.&lt;br /&gt;
* '''[then]''': a subtag that lets you execute actions if the filter conditions are met.  The most common action that should be inside here is a '''[remove_item]''' tag, but you could probably put any tags that otherwise work in a [then] tag.&lt;br /&gt;
* '''[else]''': a subtag that lets you execute actions if the filter conditions are *not* met.&lt;br /&gt;
* '''silent''': whether or not messages should be suppressed. Default is &amp;quot;no&amp;quot;. {{DevFeature1.13|2}} If no description is provided, this defaults to yes, but can still be overridden.&lt;br /&gt;
* '''image''': the displayed image of the object.&lt;br /&gt;
* '''name''': (translatable) displayed as a caption of the image.&lt;br /&gt;
&lt;br /&gt;
* '''description''': (translatable) displayed as a message of the image.&lt;br /&gt;
* '''cannot_use_message''': (translatable) displayed instead of '''description''' if no unit passes the filter test.&lt;br /&gt;
&lt;br /&gt;
=== [remove_object] ===&lt;br /&gt;
{{DevFeature1.13|6}}&lt;br /&gt;
&lt;br /&gt;
Removes an object from matching units.&lt;br /&gt;
&lt;br /&gt;
* [[StandardUnitFilter]]: All units matching the filter have matching objects removed. Use no [filter] tag.&lt;br /&gt;
* '''object_id''': The id of the object to be removed.&lt;br /&gt;
&lt;br /&gt;
Note that some unit properties are not restored ideally, e.g. current unit's health reversion might not work as expected (max_hitpoints will though). {{DevFeature1.15|0}} This was fixed.&lt;br /&gt;
&lt;br /&gt;
Note that remove_object worked the following way: Step1) remove thos objects from the unit wml, Step2) Rebuild the unit to make the changes effective. Step2 implies that changes done for example via [modify_unit] (or via the [store_unit] + [set_variable] + [unstore_unit] technique) will be reset if those changes change a property that is a property of the unit type. See the note under [modify_unit] to get a list of properties that can safely be changes via [modify_unit]&lt;br /&gt;
&lt;br /&gt;
=== [remove_trait] ===&lt;br /&gt;
{{DevFeature1.15|2}}&lt;br /&gt;
&lt;br /&gt;
* [[StandardUnitFilter]]: All units matching the filter have matching traits removed. Use no [filter] tag.&lt;br /&gt;
* '''trait_id''': The id of the object to be removed.&lt;br /&gt;
&lt;br /&gt;
=== [remove_shroud] ===&lt;br /&gt;
Removes some shroud from the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to remove shroud. This can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles for which shroud should be removed&lt;br /&gt;
&lt;br /&gt;
=== [place_shroud] ===&lt;br /&gt;
Places some shroud on the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to place shroud. This can be a comma-separated list. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles on which shroud should be placed&lt;br /&gt;
&lt;br /&gt;
=== [lift_fog] ===&lt;br /&gt;
Lifts the fog of war from parts of the map for a certain side (only relevant for sides that have fog=yes), allowing a player to witness what occurs there even if that player has no units within vision range.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the tiles from which fog should be lifted.&lt;br /&gt;
* '''multiturn''': ''yes/no, default:no''. The default (not multiturn) causes fog to be removed in the same way that normal vision works; the cleared tiles will remain cleared until fog is recalculated (which normally happens when a side ends its turn). When multiturn is set to &amp;quot;yes&amp;quot;, the cleared tiles remain clear until {{tag||reset_fog}} cancels the clearing. This allows tiles to remain clear for multiple turns, or to be refogged before the end of the current turn (without also refogging all tiles). Multiturn lifted fog is not shared with allies (even when share_vision=all).&lt;br /&gt;
&lt;br /&gt;
=== [reset_fog] ===&lt;br /&gt;
The primary use of this tag is to remove multiturn lifted fog (created by {{tag||lift_fog}}), which causes the fog to reset to what it would have been had WML not interfered. (That is, hexes that a side's units could not see at any point this turn will be re-fogged, while seen hexes remain defogged.)&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the fog reset will be restricted to these tiles.&lt;br /&gt;
* '''reset_view''': ''yes/no, default: no'' If set to &amp;quot;yes&amp;quot;, then in addition to removing multiturn fog, the side's current view is canceled (independent of the SLF). This means that all hexes will become fogged for the side unless multiturn fog exists outside the tiles selected by the SLF. Normally, one would want the currently seen hexes to become clear of fog; this is done automatically at the end of many events, and it can be done manually with {{tag|InterfaceActionsWML|redraw}}.&lt;br /&gt;
Omitting both the SSF and the SLF would cancel all earlier uses of [lift_fog].&lt;br /&gt;
Additionally setting reset_view=&amp;quot;yes&amp;quot; would cause the side's entire map to be fogged (unless an ally keeps hexes clear by sharing its view).&lt;br /&gt;
&lt;br /&gt;
=== [allow_undo] ===&lt;br /&gt;
Normally when an event with a handler fires, the player's undo stack is cleared, preventing all actions performed so far from being undone. Including this tag in the event handler prevents the stack from being cleared for this reason, allowing the player to undo actions. (However, the stack might still be cleared for other reasons, such as fog being cleared or combat occurring.) In the common cases, this means '''[allow_undo]''' allows the current action to be undone even though an event was handled. There is a less common case, though &amp;amp;mdash; specifically when handling a menu item, where there is no current action &amp;amp;mdash; and in this case, '''[allow_undo]''' means merely that earlier actions can still be undone.&lt;br /&gt;
* Using this tag in a menu item has an additional side effect in 1.11. Starting with version 1.11.1, executing a WML menu item normally counts as doing something as far as the &amp;quot;you have not started your turn yet&amp;quot; dialog is concerned. However, a menu item whose handler includes '''[allow_undo]''' will not count.&lt;br /&gt;
&lt;br /&gt;
The types of actions that can be undone are movement, recalling, and dismissing a unit from the recall list. If an action is undone, only the position (or existence) of the involved unit will be restored; any altered variables or changes to the game will remain changed after the action is undone.  It is up to the scenario designer to avoid abusing this command.&lt;br /&gt;
* Technically, if '''[allow_undo]''' is inside an '''[event]''' with ''first_time_only=yes'' (the default setting), and the user undoes the event, then the state of the game has changed in this way: the event will not fire a second time, even though the user undid the action the first time.&lt;br /&gt;
* Although recalling can be undone, recruitment can not be undone; this seems to apply even when the recruit's traits are not randomly-generated (tested on 1.12.6 and 1.14.4+dev).&lt;br /&gt;
&lt;br /&gt;
If an '''[event]''' uses both '''[allow_undo]''' and [[InternalActionsWML#.5Bfire_event.5D|'''[fire_event]''']] then the '''[allow_undo]''' must be after the '''[fire_event]'''.&lt;br /&gt;
&lt;br /&gt;
Due to a bug in 1.12 (https://gna.org/bugs/?23323) '''[allow_undo]''' should not be used in events that use one of the following things because it might cause OOS: &lt;br /&gt;
* [message] with [option]s&lt;br /&gt;
* [get_global_variable]&lt;br /&gt;
* wesnoth.synchronize_choice&lt;br /&gt;
&lt;br /&gt;
While in 1.13 using '''[allow_undo]''' together with those things won't give you a guaranteed OOS, there are some non-obvious situations where it will, for example assume the following event:&lt;br /&gt;
&lt;br /&gt;
   [event]&lt;br /&gt;
     name=&amp;quot;moveto&amp;quot;&lt;br /&gt;
     [message]&lt;br /&gt;
       message = &amp;quot;message&amp;quot;&lt;br /&gt;
       [option]&lt;br /&gt;
         label = &amp;quot;option 1&amp;quot;&lt;br /&gt;
         [command]&lt;br /&gt;
         [/command]&lt;br /&gt;
       [/option]&lt;br /&gt;
       [option]&lt;br /&gt;
         label = &amp;quot;option 2&amp;quot;&lt;br /&gt;
         [command]&lt;br /&gt;
         [/command]&lt;br /&gt;
       [/option]&lt;br /&gt;
     [/message]&lt;br /&gt;
     [allow_undo]&lt;br /&gt;
     [/allow_undo]&lt;br /&gt;
   [/event]&lt;br /&gt;
&lt;br /&gt;
It will cause OOS when the message is undone: since the event is already executed (erased) on one client only , the clients will disagree about how many choices happen during the next moveto action.&lt;br /&gt;
&lt;br /&gt;
=== [on_undo] ===&lt;br /&gt;
{{DevFeature1.13|2}}&lt;br /&gt;
Contains commands to execute when the player undoes the action which triggered the parent event.&lt;br /&gt;
*'''delayed_variable_substitution''' {{DevFeature1.13|5}}: ''yes/no, default no (always no before 1.13.5)'' As in [[EventWML]], specifies whether to perform variable substitution when the parent event is run, or when the contents are run. If delayed substitution is used, [[SyntaxWML#Automatically_Stored_Variables|automatically stored variables]] from the parent event context are available, but may occasionally have unexpected values. (In particular, $unit.x and $unit.y may not have the expected value when undoing a move event, though $x1 and $y1 should be correct.)&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
It is not clear where whether the actionwml in [on_undo] in executed before or after the action is undone. Also, specially for enter/leave_hex events the units position when executing the [on_undo] code is usually different than when executing the original event. The recommended way to work around these issues is to refer to the unit by id instead of position and store all other needed information variables as 'upvalues'. You can also move the actual undo code to an external event. For example&lt;br /&gt;
 [event]&lt;br /&gt;
   name=&amp;quot;undo_blah&amp;quot;&lt;br /&gt;
   first_time_only=no&lt;br /&gt;
   [store_unit]&lt;br /&gt;
     id=&amp;quot;$moved_unit_id&amp;quot;&lt;br /&gt;
   [/store_unit]&lt;br /&gt;
   ... do undo stuff stuff&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
 ... in some other event&lt;br /&gt;
   [on_undo]&lt;br /&gt;
     # store ''upvalues&lt;br /&gt;
     {VARIABLE moved_unit_id $unit.id}&lt;br /&gt;
     # call actual undo handler&lt;br /&gt;
     [fire_event]&lt;br /&gt;
       name = &amp;quot;undo_blah&amp;quot;&lt;br /&gt;
     [/fire_event]&lt;br /&gt;
   [on_undo]&lt;br /&gt;
&lt;br /&gt;
=== [on_redo] ===&lt;br /&gt;
{{DevFeature1.13|2}}&lt;br /&gt;
Same as [on_undo], except executes the commands on redo. Note that the parent event is not triggered again on a redo.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|8}} [on_redo] is deprecated and has no effect anymore.&lt;br /&gt;
&lt;br /&gt;
Note that [on_redo] is not guaranteed to be called when redoing an action, the engine might also decide to just fire the original events again.&lt;br /&gt;
&lt;br /&gt;
=== [cancel_action] ===&lt;br /&gt;
Although Wesnoth 1.12 does not have this tag, it is the default behavior of {{tag|EventWML|enter_hex}}/{{tag|EventWML|leave_hex}} events in that version.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|9}} In this version, [cancel_action] is recognised, but has no effect (a bug).&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|11}}&lt;br /&gt;
In an {{tag|EventWML|enter_hex}}/{{tag|EventWML|leave_hex}} event, interrupt the movement, leaving the unit where it is. This is intended to be used with an event that gives the player new information, to let the player choose whether to change their plans. For example, if the player has commanded a unit to move from (1,1) to (3,3) and attack a unit on (4,4); then a [cancel_action] inside an [enter_hex] event on (2,2) would make the unit stop on (2,2). A [cancel_action] inside an [enter_hex] on (3,3) would let the player choose whether to attack.&lt;br /&gt;
&lt;br /&gt;
=== [heal_unit] ===&lt;br /&gt;
Heal a unit. The variable '''$heal_amount''' will be set to the exact number of points healed (i.e can be less than the parameter '''amount''' if the unit is fully healed). $heal_amount contains only the number of hitpoints the first unit that was found got healed. When the variable is not needed, use {CLEAR_VARIABLE heal_amount} after this tag.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.17|0}} The '''$heal_amount''' variable is no longer set. Use the '''variable''' key instead.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] All matching on-map units are healed. If no filter is supplied, it is tried to take the unit at $x1, $y1.&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] all the units matching the filter ''and'' having the ''heals'' ability will have their animation played (if ''animate'' is set to yes) for each of the units healed.&lt;br /&gt;
*  '''amount''': (integer, default full) the maximum points the unit(s) will be healed. This can't be used to set the unit's hitpoints below 1 or above the unit's maximum hitpoints. If &amp;quot;full&amp;quot;, it fully heals the unit.&lt;br /&gt;
*  '''animate''': a boolean which indicate if the healing animations must be played. (default no)&lt;br /&gt;
*  '''moves''': (integer, default 0) The maximum current movement points the units will be &amp;quot;healed&amp;quot;. Can't set below 0 or above max_moves. If &amp;quot;full&amp;quot;, sets moves to max_moves.&lt;br /&gt;
* '''restore_attacks''': (boolean, default no) Whether the units' attacks_left should be reset to their max_attacks (usually 1).&lt;br /&gt;
* '''restore_statuses''': (boolean, default yes) Whether standard statuses should be reset to &amp;quot;no&amp;quot;. This affects poisoned, slowed, petrified and unhealable.&lt;br /&gt;
* '''variable''': {{DevFeature1.17|0}} creates an array with the given name; each item of the array has two fields, ''id='' (the ID of the unit being healed) and ''heal_amount='' (the amount of HPs the unit has been healed by).&lt;br /&gt;
&lt;br /&gt;
=== [harm_unit] ===&lt;br /&gt;
Harms every unit matching the filter, for the specific damage amount.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] all matching units will be harmed (required).&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] if present, the first matching unit will attack all the units matching the filter above.&lt;br /&gt;
*  '''amount''': the amount of damage that will be done (required).&lt;br /&gt;
*  '''alignment''': (default neutral) applies an alignment to the damage, this means that if alignment=chaotic, the damage will be increased at night and reduced at day.&lt;br /&gt;
*  '''damage_type''': if present, amount will be altered by unit resistance to the damage type specified.&lt;br /&gt;
*  '''kill''': (default yes) if yes, when a harmed unit goes to or below 0 HP, it is killed; if no its HP are set to 1.&lt;br /&gt;
*  '''fire_event''': (default no) if yes, when a unit is killed by harming, the corresponding events are fired.  If yes, also the corresponding advance and post advance events are fired.&lt;br /&gt;
*  '''animate''': (default no) if yes, scrolls to each unit before harming it and plays its defense (or attack, if it's the harmer) and death animations. Special values supported, other than the usual yes and no, are &amp;quot;attacker&amp;quot;, that means only the harmer will be animated, and &amp;quot;defender&amp;quot;, that means only the harmed units will be animated. If the supplied value is yes, attacker or defender also advancement animations are played.&lt;br /&gt;
*  '''[primary_attack], [secondary_attack]''': these set the weapon against which the harmed units will defend, and that the harming unit will use to attack, respectively (notice this is the opposite of '''[filter]''' and '''[filter_second]''' above). This allows for playing specific defense and attack animations. Both tags are expected to contain a [[FilterWML#Filtering_Weapons|Standard Weapon Filter]].&lt;br /&gt;
*  '''delay''': if animate=yes, sets the delay (in milliseconds, default 500) between each unit harming.&lt;br /&gt;
*  '''variable''': if present, the damage caused to the unit, altered by resistances, will be stored in a WML array with the given name, under the ''harm_amount='' key. {{DevFeature1.17|0}} Each item of the array also has an ''id='' key, which contains the ID of the unit being harmed.&lt;br /&gt;
*  '''poisoned, slowed, petrified, unhealable''': (default no) if yes, every harmed unit that doesn't already have such status will have it set.&lt;br /&gt;
*  '''experience''': if yes, and there is a harmer, experience will be attributed like in regular combat.&lt;br /&gt;
*  '''resistance_multiplier''': the harmed unit's resistance is multiplied by the supplied value; this means that a value lower than 1 increases it, and a value greater than 1 decreases it. Default value is 1, that means no modification.&lt;br /&gt;
&lt;br /&gt;
=== [time_area] ===&lt;br /&gt;
How a day should progress in a given area. Everywhere not specified in a [time_area] tag is affected by the [time] tags in the [scenario] tag.&lt;br /&gt;
* [[StandardLocationFilter]]: the locations to affect. ''note: only for [event][time_area]s - at scenario toplevel [time_area] does not support [[StandardLocationFilter]], only location ranges''&lt;br /&gt;
* '''[time]''': one or more tags describing the new schedule, see [[TimeWML]].&lt;br /&gt;
* '''id''': an unique identifier assigned to a time_area. Optional, unless you want to remove the time_area later or reference it from a location filter elsewhere. Can be a comma-separated list when removing time_areas, see below.&lt;br /&gt;
* '''remove''': (boolean) yes/no value. Indicates whether the specified time_area should be removed. Requires an identifier. If no identifier is used, however, all time_areas are removed.&lt;br /&gt;
* '''current_time''': The time slot number (starting with zero) active at the creation of the area.&lt;br /&gt;
&lt;br /&gt;
''Example:'' (caves in parts of a map)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=wml&amp;gt;&lt;br /&gt;
[time_area]&lt;br /&gt;
    id = cave_area&lt;br /&gt;
    x = 1-2,4-5&lt;br /&gt;
    y = 1-2,1-2&lt;br /&gt;
    {UNDERGROUND}&lt;br /&gt;
[/time_area]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying an id allows the area to be referenced from location filters. Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=wml&amp;gt;&lt;br /&gt;
    [time_area]&lt;br /&gt;
        id = glyphs&lt;br /&gt;
        x = 9,14&lt;br /&gt;
        y = 11,3&lt;br /&gt;
    [/time_area]&lt;br /&gt;
    [event]&lt;br /&gt;
        name = moveto&lt;br /&gt;
        first_time_only=no&lt;br /&gt;
        [filter]&lt;br /&gt;
            side = 1&lt;br /&gt;
            [filter_location]&lt;br /&gt;
                area = glyphs&lt;br /&gt;
            [/filter_location]&lt;br /&gt;
        [/filter]&lt;br /&gt;
        # Do something, for example healing the unit&lt;br /&gt;
    [/event]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [remove_time_area] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|2}}&lt;br /&gt;
&lt;br /&gt;
This is a syntactic shortcut for [time_area] remove=.&lt;br /&gt;
* '''id''': Comma-separated list of time area ids to remove.&lt;br /&gt;
&lt;br /&gt;
=== [end_turn] ===&lt;br /&gt;
End the current side's turn. The current event is finished before the turn is ended. Also, if the current event (where the tag appears) has been fired by another event, that event (and the complete stack of other possible parent events) is ended before [end_turn] comes into affect. Also, events following the event stack that fired [end_turn] are not omitted (e.g. [end_turn] is used by a side turn event and a turn refresh event does something afterwards).&lt;br /&gt;
&lt;br /&gt;
=== [replace_map] ===&lt;br /&gt;
&lt;br /&gt;
Replaces the entire map.&lt;br /&gt;
* '''map_data''': Content of a wesnoth map file. (This key used to be just '''map='''.) Example:&lt;br /&gt;
 map_data=&amp;quot;{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}&amp;quot;&lt;br /&gt;
* '''map_file''': {{DevFeature1.13|?}} Path to a Wesnoth map file; can be used instead of '''map'''. The file will be loaded when the tag is executed, rather than being embedded wholesale in the preprocessed WML. Example:&lt;br /&gt;
 map_file=campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map&lt;br /&gt;
{{DevFeature1.15|3}} If the file is not found directly, it will be searched for in the [[BinaryPathWML|[binary_path]]]. Assuming a standard campaign or add-on layout, the example above can be replaced by:&lt;br /&gt;
 map_file=01_The_Elves_Besieged.map&lt;br /&gt;
* '''expand''': if 'yes', allows the map size to increase. The expansion direction is currently always bottom-right.&lt;br /&gt;
* '''shrink''': if 'yes', allows the map size to decrease. If the map size is reduced, any units that would no longer be on the map due to its coordinates no longer existing will be put into the recall list.&lt;br /&gt;
Note: When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages it that there are too many choices to make; should a unit lose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [replace_schedule] ===&lt;br /&gt;
Replace the time of day schedule of the entire scenario.&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
* '''current_time''': The time slot number (starting with zero) active at schedule replacement.&lt;br /&gt;
&lt;br /&gt;
=== [tunnel] ===&lt;br /&gt;
&lt;br /&gt;
Create a tunnel between some locations, later usable by units to move from source hex to target hex (using the movement cost of unit on the target terrain).&lt;br /&gt;
&lt;br /&gt;
'''Behavior Change as of Wesnoth 1.13.6:''' Vision is now possible (and enabled by default) through tunnels and allied units on the exit hex do not block a tunnel by default any more. This is done in order for moves through tunnels to be consistent with other moves. The previous behavior can still be accomplished by using the new optional keys listed below.&lt;br /&gt;
&lt;br /&gt;
* '''[filter]''': (required) [[StandardUnitFilter]] the units which can use the tunnel. Leave empty for &amp;quot;all units&amp;quot;.&lt;br /&gt;
* '''[source]''': (required) [[StandardLocationFilter]] the source hex(es).&lt;br /&gt;
* '''[target]''': (required) [[StandardLocationFilter]] the target hex(es).&lt;br /&gt;
* '''id''': (optional) identifier for the tunnel, to allow removing.&lt;br /&gt;
* '''remove''': (boolean, default: no)  If yes, removes all defined tunnels with the same ID (then only id= is necessary).&lt;br /&gt;
* '''bidirectional''': (boolean, default: yes) If yes, creates also a tunnel in the other direction. &lt;br /&gt;
* '''always_visible''': (boolean, default: no) If yes, the possible movement of enemies under fog can be seen.&lt;br /&gt;
* '''allow_vision''': (boolean, default: yes) {{DevFeature1.13|6}} If no, vision through a tunnel is not possible. Note that in that case the tunnel cannot be used if the tunnel exit is under shroud (which previously was ''always'' the case).&lt;br /&gt;
* '''pass_allied_units''': (boolean, default: yes) {{DevFeature1.13|6}} If no, allied (including own) units on the exit hex block a tunnel.&lt;br /&gt;
* '''delayed_variable_substitution''' (boolean, default: yes): If yes, the WML block contained in this [tunnel] is not variable-substituted at execution time of the event where this [tunnel] is within. Instead, variables are substituted when the tunnel is used by a unit. See [[EventWML#Nested_Events]]&lt;br /&gt;
&lt;br /&gt;
(Note: The tunnel tag can also be used inside the [[AbilitiesWML|[teleport]]] ability, without remove= and id=).&lt;br /&gt;
&lt;br /&gt;
=== [do_command] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Executes a command, specified using the same syntax as a [command] tag in [[ReplayWML]]. Not all [command]'s are valid: only these are accepted&lt;br /&gt;
&lt;br /&gt;
* [attack]&lt;br /&gt;
* [move]&lt;br /&gt;
* [recruit]&lt;br /&gt;
* [recall]&lt;br /&gt;
* [disband]&lt;br /&gt;
* [fire_event]&lt;br /&gt;
* [lua_ai] {{DevFeature1.13|12}} This has been removed and is replaced with [custom_command]&lt;br /&gt;
&lt;br /&gt;
The tags corresponding to player actions generally use the same codepath as if a player had ordered it. That means for example that only moves that player would be allowed to do are possible, and movement is interrupted when sighting enemy unit.&lt;br /&gt;
&lt;br /&gt;
One purpose of this tag is to allow scripting of noninteractive scenarios -- without a tag like this, this might require elaborate mechanisms to coerce ais in order to test these code paths.&lt;br /&gt;
&lt;br /&gt;
This command should be replay safe if it is either invoked in a synced context, ''or'' invoked in code that is never synced, like AI code, a select event, or a menu item with `synced = false`. However, if you use desynchronized logic ''during'' an event that is otherwise synced, invoking [do_command] based on that desynchronized logic will result in out-of-sync errors during the replay; in this case, you must explicitly synchronize which command to do using something like the lua function wesnoth.sync.evaluate_single.&lt;br /&gt;
&lt;br /&gt;
=== [put_to_recall_list] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Puts a unit to the recall list of its side.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': the unit(s) to get put to the recall list.&lt;br /&gt;
* '''heal''': (default=no) Whether the unit should be refreshed, similar to the unit moving to the recall list at the end of a scenario.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Useful Macros ==&lt;br /&gt;
There are some predefined macros that you find useful for direct actions. You can find a complete list along with a detailed explanation of how they work [https://www.wesnoth.org/macro-reference.html here].&lt;br /&gt;
* '''{MOVE_UNIT}''': Moves a unit to another location in the map and the player sees the movement (unlike [teleport])&lt;br /&gt;
* '''{FULL_HEAL}''': Brings a unit to full HP&lt;br /&gt;
* '''{LOYAL_UNIT}''': Create a loyal unit&lt;br /&gt;
* '''{MODIFY_TERRAIN_MASK}''': Modify an area of terrain&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=69164</id>
		<title>DirectActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=69164"/>
		<updated>2022-01-16T12:57:23Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [heal_unit] */ Removed heal_amount variable and added variable= key&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== Direct actions ==&lt;br /&gt;
&lt;br /&gt;
Direct actions are actions that have a direct effect on gameplay. They can be used inside of [[EventWML|events]].&lt;br /&gt;
&lt;br /&gt;
The following tags are actions:&lt;br /&gt;
&lt;br /&gt;
=== [endlevel] ===&lt;br /&gt;
Ends the scenario.&lt;br /&gt;
* '''result''': before the scenario is over, all events with ''name=result'' are triggered. If ''result=victory'', the player progresses to the next level (i.e., the next scenario in single player); if ''result=defeat'', the game returns to the main menu. &lt;br /&gt;
&lt;br /&gt;
When the result is &amp;quot;victory&amp;quot; the following keys can be used:&lt;br /&gt;
* '''bonus''': whether the player should get bonus gold (maximum possible gold that could have been earned by waiting the level out). The default is bonus=yes. {{DevFeature1.13|2}} Alternatively, a number, defining the bonus multiple (1.0 meaning full).&lt;br /&gt;
* '''carryover_report''': whether the player should receive a summary of the scenario outcome, the default is carryover_report=yes.&lt;br /&gt;
* '''save''': whether a start-of-scenario save should be created for the next scenario, the default is save=yes. Do not confuse this with saving of replays for the current scenario.&lt;br /&gt;
* '''replay_save''': whether a replay save for the current scenario is allowed, the default is replay_save=yes. If yes, the player's settings in preferences will be used to determine if a replay is saved. If no, will override and not save a replay.&lt;br /&gt;
* '''linger_mode''': If ...=yes, the screen is greyed out and there's the possibility to save before advancing to the next scenario, the default is linger_mode=yes.&lt;br /&gt;
* '''reveal_map''': (Multiplayer only) (Default is 'yes') If 'no', shroud doesn't disappear when game ended.&lt;br /&gt;
* '''next_scenario''': (default specified in '''[scenario]''' tag) the ID of the next scenario that should be played.  All units that side 1 controls at this point become available for recall in ''next_scenario''.&lt;br /&gt;
* '''carryover_percentage''': by default 80% of the gold is carried over to the next scenario, with this key the amount can be changed.&lt;br /&gt;
* '''carryover_add''': if yes the gold will be added to the starting gold the next scenario, if no the next scenario will start with the amount of the current scenario (after taxes) or the minimum in the next scenario. Default is no.&lt;br /&gt;
* '''music''': (default specified in '''[scenario]''' or '''[game_config]''' tags) a comma-separated list of music tracks from which one will be chosen and played once after any events related to the end of level result are executed; by default, victory_music is used on victory, and defeat_music on defeat.&lt;br /&gt;
* '''end_credits''': Whether to display the credits screen at the end of a single-player campaign. Defaults to ''yes''. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text''': (translatable) Text that is shown centered in a black screen at the end of a campaign. Defaults to &amp;quot;The End&amp;quot;. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text_duration''': Delay, in milliseconds, before displaying the game credits at the end of a campaign. In other words, for how much time '''end_text''' is displayed on screen. Defaults to 3500. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* &amp;lt;strike&amp;gt;'''[next_scenario_settings]''': Any tags or attribute children of this optional argument to [endlevel] are merged into the scenario/multiplayer tag of the *next* scenario. This allows you to e.g. reconfigure the [side] tags or settings, just before load. &amp;lt;/strike&amp;gt; This feature was removed in 1.11.17, it might be redesigned and reintroduced.&lt;br /&gt;
* &amp;lt;strike&amp;gt;'''[next_scenario_append]''': Any tags of this optional argument are appended at high level to the next scenario. This is most appropriate for [event] tags, although you may find other uses. Example test scenario for these features: https://gna.org/support/download.php?file_id=20119 &amp;lt;/strike&amp;gt; This feature was removed in 1.11.17, it might be redesigned and reintroduced.&lt;br /&gt;
* '''[result]''' {{DevFeature1.13|0}} Allows specification of a side specific result, this is for competitive multiplayer scenarios/campaigns where it might happen that one player wins but another player loses.  The following attributes are accepted and have the same effect as in '''[endlevel]''':&lt;br /&gt;
** '''result'''&lt;br /&gt;
** '''bonus'''&lt;br /&gt;
** '''carryover_percentage'''&lt;br /&gt;
** '''carryover_add'''&lt;br /&gt;
&lt;br /&gt;
And there is also&lt;br /&gt;
** '''side''' The number of the side for which these results should apply.&lt;br /&gt;
&lt;br /&gt;
=== [unit] ===&lt;br /&gt;
Creates a unit (either on the map, on a recall list, or into a variable for later use.)  For syntax see [[SingleUnitWML]].&lt;br /&gt;
* {{Short Note:Predefined Macro|GENERIC_UNIT}}&lt;br /&gt;
&lt;br /&gt;
This tag can also recall an existing unit, which happens when:&lt;br /&gt;
* the '''id=''' attribute is used&lt;br /&gt;
* a unit with that '''id=''' already exists&lt;br /&gt;
* (might be unnecessary) the existing unit is on the side's recall list&lt;br /&gt;
in this case, the unit is recalled at the '''x,y=''' or '''location_id=''' given, and any other data in the tag is ignored.&lt;br /&gt;
&lt;br /&gt;
Campaign authors: a usual way to recall plot-necessary heroes is to use a macro with the data for creating that hero. This helps during debugging, because you can skip to scenarios and the recall-or-create functionality means that any units which are normally met in a previous scenario are automatically created (otherwise some scenarios may be an instant loss). This can only be used for units that must survive the previous scenarios, as it would recreate units if they died in a previous scenario.&lt;br /&gt;
For example,&lt;br /&gt;
[https://github.com/wesnoth/wesnoth/blob/1.14.7/data/campaigns/Heir_To_The_Throne/utils/httt_utils.cfg#L685 HttT's NEED_DELFADOR macro].&lt;br /&gt;
&lt;br /&gt;
=== [recall] ===&lt;br /&gt;
Recalls a unit taking into account any [http://wiki.wesnoth.org/SingleUnitWML filter_recall] of the leader.   The unit is recalled free of charge, and is placed near its leader, e.g., if multiple leaders are present, near the first found which would be able to normally recall it.&lt;br /&gt;
&lt;br /&gt;
If neither a valid map location is provided nor a leader on the map would be able to recall it, the tag is ignored.&lt;br /&gt;
 &lt;br /&gt;
* [[StandardUnitFilter]]: the first matching unit will be recalled.  If no units match this tag is ignored. Do not use a [filter] tag. If a comma separated list is given, every unit currently considered for recall is checked against all the types (not each single one of the types against all units).&lt;br /&gt;
* '''x,y''': the unit is placed here instead of next to the leader.&lt;br /&gt;
* '''location_id''': {{DevFeature1.15|0}} the name of a special map location to recall to. Used instead of '''x,y'''.&lt;br /&gt;
* '''show''': yes/no, default yes: whether the unit is animated (faded in) or instantly displayed&lt;br /&gt;
* '''fire_event''': boolean yes|no (default no); whether any according prerecall or recall events shall be fired.&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit (a nearby passable hex is chosen).&lt;br /&gt;
* '''[secondary_unit]''': {{DevFeature1.13|?}} If present and show=yes, a matching unit will be chosen and their recruiting animation played.&lt;br /&gt;
&lt;br /&gt;
=== [teleport] ===&lt;br /&gt;
Teleports a unit on map. {{Short Note:Predefined Macro|TELEPORT_UNIT}}&lt;br /&gt;
* '''[filter]''': [[StandardUnitFilter]] the first unit matching this filter will be teleported.&lt;br /&gt;
* '''x,y''': the hex to teleport to. If that hex is occupied, the closest unoccupied hex will be used instead.&lt;br /&gt;
* '''location_id''': {{DevFeature1.15|0}} the name of a special map location to teleport to. Used instead of '''x,y'''.&lt;br /&gt;
* '''clear_shroud''': should shroud be cleared on arrival&lt;br /&gt;
* '''animate''': should a teleport animation be played (if the unit doesn't have a teleport animation, it will fade out/fade in)&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): normally, units will not be teleported into terrain that is impassable for them. Setting this attribute to &amp;quot;no&amp;quot; permits it.&lt;br /&gt;
&lt;br /&gt;
(Note: There is also a ability named teleport, see [[AbilitiesWML]].)&lt;br /&gt;
&lt;br /&gt;
=== [terrain_mask] ===&lt;br /&gt;
Changes the terrain on the map.  See [[TerrainMaskWML]].&lt;br /&gt;
&lt;br /&gt;
=== [terrain] ===&lt;br /&gt;
Changes the terrain on the map.&lt;br /&gt;
* '''terrain''': the character of the terrain to use.  See [[TerrainCodesWML]] to see what letter a type of terrain uses.&lt;br /&gt;
* [[StandardLocationFilter]]. This [[StandardLocationFilter]]'s terrain= key is used for the new terrain, filtering by terrain can be done with a nested [[StandardLocationFilter]]: [and]terrain=terrain_string_to_be_filtered_for.&lt;br /&gt;
* '''layer''': (overlay|base|both, default=both) only change the specified layer.&lt;br /&gt;
* '''replace_if_failed''': (default=no) When replacing just one layer failed, try to replace the whole terrain. If '''terrain''' is an overlay only terrain, use the default_base as base layer. If the terrain has no default base, do nothing.&lt;br /&gt;
&lt;br /&gt;
If you want to remove the overlays from a terrain and leave only the base, use:&lt;br /&gt;
 layer=overlay&lt;br /&gt;
 terrain=&amp;quot;^&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages is that there are too many choices to make; should a unit lose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [gold] ===&lt;br /&gt;
Gives sides gold.&lt;br /&gt;
* '''amount''': the amount of gold to give.&lt;br /&gt;
* '''side''': (default=1) the number of the side to give the gold to. Can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [unstore_unit] ===&lt;br /&gt;
Creates a unit from a game variable, and activates it on the playing field or recall list.  This must be a specific variable describing a unit, and may not be an array (if it is, only the first unit will be unstored).&lt;br /&gt;
&lt;br /&gt;
This may be useful in different contexts:&lt;br /&gt;
* To update a unit on the map after having edited its WML. This usage is common, but discouraged - if possible, you should use [[#.5Bmodify_unit.5B|[modify_unit]]] or [[#.5Bobject.5B|[object]]] instead.&lt;br /&gt;
* To place a previously-defined unit into the scenario, if it was directly defined in a WML variable, using [unit] with the key '''to_variable'''. This usage is rather uncommon.&lt;br /&gt;
* To place a unit back into the game that was removed earlier, for example a hero that leaves the party for awhile and then comes back.&lt;br /&gt;
&lt;br /&gt;
The variable is not cleared. To unstore units from an array variable, iterate over the array. See [[SyntaxWML]] and [[VariablesWML/How to use variables]] for more information about variable usage. See also [[InternalActionsWML#.5Bstore_unit.5D|[store_unit]]], [[ConditionalActionsWML|For]], [[ConditionalActionsWML#.5Bwhile.5D|[while]]] and [[InternalActionsWML#.5Bclear_variable.5D|[clear_variable]]].&lt;br /&gt;
&lt;br /&gt;
The tag takes the following keys:&lt;br /&gt;
* '''variable''': This is required to indicate the name of the variable to read the unit from.&lt;br /&gt;
* '''Placement keys''':&lt;br /&gt;
** '''x''' ,'''y''': By default, the unit will be placed at the location specified in the variable, but if these keys are present, the unit will be placed at that location instead. To place the unit on the recall list of its side, use '''x,y=recall,recall'''. (If you want to change the said, you need to first update ''$unit.side'' in the variable before unstoring.)&lt;br /&gt;
** '''location_id''': {{DevFeature1.15|0}} The name of a special map location to unstore to. Used instead of '''x,y'''.&lt;br /&gt;
** '''find_vacant''' (yes|no, default no): Whether the unit should be placed on the nearest vacant tile to its specified location. If this is set to 'no' (default), then any unit on the same tile as the unit being unstored will be destroyed.&lt;br /&gt;
** '''check_passability''' (yes|no, default yes): Only relevant if '''find_vacant=yes'''. In that case, this determines whether game will try to find a passable tile for the unit. If set to no, the unit may be placed on an impassable tile. Note that if both '''find_vacant''' and '''check_passability''' are set, then the unit's position may be shifted even if there is not a unit on the target space, if that space is not passable for the unit.&lt;br /&gt;
* '''Animation keys''' (these determine the visual effect of how the unit is placed or updated):&lt;br /&gt;
** '''text''': (translatable) A floating text to display above the unit, such as a damage amount.&lt;br /&gt;
** '''male_text''', '''female_text''': {{DevFeature1.13|2}} (translatable) gender-specific versions of the above&lt;br /&gt;
** '''red''', '''green''', '''blue''': (default=0,0,0) the color of the text. Values vary from 0-255. You may find it convenient to use the {COLOR_HARM} or {COLOR_HEAL} macro instead. (Use {COLOR_HARM} or {COLOR_HEAL} instead of the whole red,green,blue= line.)&lt;br /&gt;
** '''animate''': (boolean yes|no, default yes) Determines whether to play any animations associated with the unstore. Currently this only affects the advancement animation (&amp;quot;levelout&amp;quot; and &amp;quot;levelin&amp;quot;, defaulting to a fade to white and back) if the unit ends up advancing.&lt;br /&gt;
* '''Side-effect keys''' (these directly modify the behaviour of the action):&lt;br /&gt;
** '''advance''': (default=yes) if yes the unit is advanced if it has enough XP. When modifying XP, make sure to do it from inside a [[EventWML#Multiplayer_safety|synchronized event]] or it may lead to OOS errors, especially when several advancement paths exist. Note that advance and post advance events are called, so infinite loops can happen.&lt;br /&gt;
** '''fire_event''' (yes|no, default no): Whether any advance/post advance events shall be fired if an advancement takes place. This also affects whether the unit placed event is fired.&lt;br /&gt;
&lt;br /&gt;
Units can be unstored with negative (or zero) hit points. This can be useful if modifying a unit in its last_breath event (as the unit's death is already the next step), but tends to look wrong in other cases. In particular, it is possible to have units with negative hit points in play. Such units are aberrations, subject to unusual behavior as the game compensates for them. (For example, such units are currently automatically hit&amp;amp;ndash;and killed&amp;amp;ndash;in combat.) The details of the unusual behavior are subject to change between stable releases without warning.&lt;br /&gt;
&lt;br /&gt;
=== [allow_recruit] ===&lt;br /&gt;
Allows a side to recruit units it couldn't previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that is being allowed to recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [allow_extra_recruit] ===&lt;br /&gt;
Allows a leader to recruit units it couldn't previously recruit.&lt;br /&gt;
These types add to the types the leader can recruit because of [side]recruit=.&lt;br /&gt;
* '''extra_recruit''': the types of units that the unit can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_recruit] ===&lt;br /&gt;
Prevents a side from recruiting units it could previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can no longer recruit. {{DevFeature1.13|0}} If omitted, all recruits for matching sides will be disallowed.&lt;br /&gt;
* '''side''': (default=1) the number of the side that may no longer recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_extra_recruit] ===&lt;br /&gt;
Prevents a leader from recruiting units it could previously recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the side can no longer recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [set_recruit] ===&lt;br /&gt;
Sets the units a side can recruit.&lt;br /&gt;
* '''recruit''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': The number of the side that is having its recruitment set. This can be a comma-separated list.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [set_extra_recruit] === &lt;br /&gt;
Sets the units a leader can recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the leader can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [modify_side] ===&lt;br /&gt;
Modifies some details of a given side in the middle of a scenario.  '''The following listed properties are the only properties that [modify_side] can affect!'''&lt;br /&gt;
* '''side''': (default=1) the number of the side that is to be changed. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* '''income''': the income given at the begining of each turn.&lt;br /&gt;
* '''recruit''': a list of unit types, replacing the side's current recruitment list.&lt;br /&gt;
* '''team_name''': the team in which the side plays the scenario.&lt;br /&gt;
* '''user_team_name''': a translatable string representing the team's description. This has no effect on alliances. Defaults to ''team_name''.&lt;br /&gt;
* '''side_name''': {{DevFeature1.13|?}} a translatable string representing the side leader's description.&lt;br /&gt;
* '''gold''': the amount of gold the side owns.&lt;br /&gt;
* '''village_gold''': the income setting per village for the side.&lt;br /&gt;
* '''controller''': the identifier string of the side's controller. Uses the same syntax of the ''controller'' key in the [[SideWML|[side]]] tag. warning: in multiplayer, changing the controller of a side might result in OOS during some events like, for example 'side_turn_end'; see [https://github.com/wesnoth/wesnoth/issues/2563 issue #2563].&lt;br /&gt;
* '''fog''': a boolean string (yes/no) describing the status of Fog for the side.&lt;br /&gt;
* '''shroud''': a boolean string describing the status of Shroud for the side.&lt;br /&gt;
* '''hidden''': a boolean string specifying whether side is shown in status table.&lt;br /&gt;
* '''color''': a team color range specification, name (e.g. &amp;quot;red&amp;quot;, &amp;quot;blue&amp;quot;), or number (e.g. &amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;) for this side. The default color range names, numbers, and definitions can be found in data/core/team_colors.cfg.&lt;br /&gt;
* '''[ai]''': sets/changes AI parameters for the side. Only parameters that are specified in the tag are changed, this does not reset others to their default values. Uses the same syntax as described in [[AiWML]].  Note that [modify_side][ai] works for all simple AI parameters and some, but not all, of the composite ones. If in doubt, use [http://wiki.wesnoth.org/AiWML#Adding_and_Deleting_Aspects_with_the_.5Bmodify_ai.5D_Tag [modify_ai]] instead, which always works. {{DevFeature1.13|?}} If this contains an '''ai_algorithm''', the AI parameters will be reset to those of the indicated AI before adding any additional parameters included in the tag. In other words, this allows replacing the AI config rather than appending to it.&lt;br /&gt;
* '''switch_ai''': replaces a side ai with a new AI from specified file(ignoring those AI parameters above). Path to file follows the usual WML convention.&lt;br /&gt;
* '''reset_maps''': If set to &amp;quot;yes&amp;quot;, then the shroud is spread to all hexes, covering the parts of the map that had already been explored by the side, including hexes currently seen. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if shroud is on, but this is evaluated after shroud= (and before shroud_data=).&lt;br /&gt;
* '''reset_view''': If set to &amp;quot;yes&amp;quot;, then the fog of war is spread to all hexes, covering the parts of the map that had already been seen this turn by the side, including hexes currently seen, excluding hexes affected by multi-turn {{tag|DirectActionsWML|lift_fog}}. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if fog is on, but this is evaluated after fog=.&lt;br /&gt;
* '''share_maps''': change the share_maps side attribute. Be sure to use shroud=yes for that side and have it as an ally&lt;br /&gt;
* '''share_view''': change the share_view side attribute. Be sure to use fog=yes for that side and have it as an ally&lt;br /&gt;
* '''share_vision''': change both the above at the same time&lt;br /&gt;
* '''shroud_data''': changes to the side's shroud, using the same format as when defining the [side].&lt;br /&gt;
* '''suppress_end_turn_confirmation''': Boolean value controlling whether or not a player is asked for confirmation when skipping a turn.&lt;br /&gt;
* '''scroll_to_leader''': Boolean value controlling whether or not the game view scrolls to the side leader at the start of their turn when present.&lt;br /&gt;
* '''flag''': Flag animation for villages owned by this side (see [[SideWML|[side]]]).&lt;br /&gt;
* '''flag_icon''': Flag icon used for this side in the status bar (see [[SideWML|[side]]]).&lt;br /&gt;
* '''village_support''': The number of unit levels this side is able to support (does not pay upkeep on) per village it controls.&lt;br /&gt;
* '''defeat_condition''' {{DevFeature1.13|0}}: When the side is considered defeated (see [[SideWML|[side]]]).&lt;br /&gt;
* '''[set_variable]''', '''[clear_variable]''' {{DevFeature1.15|3}} Sets or clears a variable within the side; uses the same syntax as [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] or [[InternalActionsWML#.5Bclear_variable.5D|[clear_variable]]] in ActionWML.&lt;br /&gt;
* '''[variables]''' {{DevFeature1.15|3}} The contents of this tag is merged into the side's variables.&lt;br /&gt;
&lt;br /&gt;
=== [modify_turns] ===&lt;br /&gt;
Modifies the turn limit in the middle of a scenario.&lt;br /&gt;
* '''value''': the new turn limit.&lt;br /&gt;
* '''add''': if used instead of ''value'', specifies the number of turns to add to the current limit (can be negative).&lt;br /&gt;
* '''current''': changes the current turn number after applying turn limit modifications, if any. It is not possible to change the turn number to exceed the turn limit (1 &amp;lt;= current turns &amp;lt;= max turns).&lt;br /&gt;
&lt;br /&gt;
=== [allow_end_turn] ===&lt;br /&gt;
Allows human players to end their turn through the user interface if they were previously affected by the '''[disallow_end_turn]''' action. This action doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_end_turn] ===&lt;br /&gt;
Disallows human players to end their turn through the user interface. This action doesn't require arguments.&lt;br /&gt;
* '''reason''' (translatable): {{DevFeature1.15|0}} Allows to optionally specify a reason.&lt;br /&gt;
&lt;br /&gt;
=== [capture_village] ===&lt;br /&gt;
Changes the ownership of a village.&lt;br /&gt;
* [[StandardLocationFilter]]: all village locations matching the filter are affected.&lt;br /&gt;
* '''side''': the side that takes control of the village. This side needs to have a leader (canrecruit=yes). If the side key is not given, the village will become neutral (unless [filter_side] is present, in which case that side fiter decides, see below).&lt;br /&gt;
* '''[filter_side]''' with [[StandardSideFilter]] tags and keys as arguments; if both this tag and inline side= are present it's an error. Otherwise, the first matching side gets ownership (or the village becomes neutral if none match).&lt;br /&gt;
* '''fire_event''' (boolean yes|no, default: no): Whether any capture events shall be fired.&lt;br /&gt;
&lt;br /&gt;
=== [kill] ===&lt;br /&gt;
Removes all units (including units in a recall list) that match the filter from the game.&lt;br /&gt;
* [[StandardUnitFilter]]: Selection criterion; do not use a [filter] tag.&lt;br /&gt;
* '''animate''' (default 'no'): if 'yes', displays the unit dying (fading away). {{DevFeature1.13|8}} If '''[secondary_unit]''' is given, also plays the victory animation of that unit.&lt;br /&gt;
* '''fire_event''' (default 'no'): if 'yes', triggers any appropriate 'die' events (See [[EventWML]]). Note that events are only fired for killed units that have been on the map (as opposed to recall list).&lt;br /&gt;
* '''[secondary_unit]''' with a [[StandardUnitFilter]] as argument. Do not use a [filter] tag. Has an effect only if fire_event=yes ({{DevFeature1.13|8}} or if it has a victory animation and animate=yes). The first on-map unit matching the filter becomes second_unit in any fired die and last breath events. If an on-map unit matches and if there are several units killed with a single [kill] tag, second_unit is this same unit for all of them. If no on-map unit matches or [secondary_unit] isn't present, the variable second_unit in each of the die and last breath events is always the same as the variable unit (the dying unit).&lt;br /&gt;
* '''[primary_attack]''', '''[secondary_attack]''' {{DevFeature1.13|8}} The attacks to use for matching the animation. Useful for example on the wose, whose death animation depends on the damage type it was killed by.&lt;br /&gt;
&lt;br /&gt;
=== [move_unit] ===&lt;br /&gt;
Moves a unit along a path on the map. The path can be specified exactly, or as a series of waypoints that the unit will pass through.&lt;br /&gt;
* [[StandardUnitFilter]] as argument; do not use a [filter] tag. All units matching the filter are moved. If the target location is occupied, the nearest free location is chosen.&lt;br /&gt;
* '''to_x''' (unsigned integer): The units are moved to this x coordinate. Can be a comma-separated list, in which case the unit follows this given path during the move.&lt;br /&gt;
* '''to_y''' (unsigned integer): The units are moved to this y coordinate. Can be a comma-separated list.&lt;br /&gt;
* '''dir''' (string): {{DevFeature1.15|0}} Performs a relative movement instead of an absolute movement. For example, dir=n,n,nw will move two spaces north and then one space to the northwest. This is used instead of '''to_x''' and '''to_y'''.&lt;br /&gt;
* '''to_location''': {{DevFeature1.15|0}} Moves matching units to locations placed in the map editor with the &amp;quot;New Location&amp;quot; button. Can be a comma-separated list. This is used instead of '''to_x''' and '''to_y'''.&lt;br /&gt;
* '''check_passability''' (boolean yes|no, default yes): Whether the terrain the unit is moved to should be checked for suiting the unit. (If it does not, a nearby suitable hex is chosen.)&lt;br /&gt;
* '''force_scroll''': Whether to scroll the map or not even when [[InterfaceActionsWML#.5Block_view.5D|[lock_view]]] is in effect or ''Follow Unit Actions'' is disabled in ''Advanced Preferences''. Defaults to using [[InterfaceActionsWML#.5Bmove_unit_fake.5D|[move_unit_fake]]]'s default value.&lt;br /&gt;
* '''clear_shroud''': {{DevFeature1.15|0}} (boolean yes|no, default no) Whether to remove shroud and fog after the unit was moved, but before events are fired. It will not clear all alongside the path, only around the target destination.&lt;br /&gt;
* '''fire_event''' (boolean yes|no, default no): Whether any according moveto events shall be fired. The target location ($x1, $y1 in the event) may not be the same location that the unit was tried to be moved to, if the original target location is occupied or impassable.&lt;br /&gt;
&lt;br /&gt;
=== [modify_ai] ===&lt;br /&gt;
Changes AI objects (aspects, goals, candidate actions or stages) for a specified side. See [[Modifying_AI_Components#The_.5Bmodify_ai.5D_Tag|Modifying AI Components]] for full description.&lt;br /&gt;
&lt;br /&gt;
* '''action''' (string): Takes values 'add', 'change', 'delete' or 'try_delete' to do just that for the AI object.&lt;br /&gt;
* '''path''' (string): Describes which AI object is to be modified.  &lt;br /&gt;
* '''[facet]''', '''[goal]''', '''[candidate_action]''' or '''[stage]''': Details about the AI object to be modified.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [modify_unit] ===&lt;br /&gt;
works similar to the MODIFY_UNIT macro.&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. All units matching this filter are modified. Matches on recall list units too.&lt;br /&gt;
* '''[object]''', '''[trait]''', {{DevFeature1.13|5}} '''[advancement]''' - The given modifications will be immediately applied to all units matching the filter. ([object] is described further below)&lt;br /&gt;
** '''delayed_variable_substitution''' {{DevFeature1.13|5}} (boolean yes|no, default no): If set to &amp;quot;yes&amp;quot;, the wml block contained in this [object], [trait], or [advancement] is not variable-substituted at execution time of the event containing this [modify_unit]. You need this for any effect that uses variable substitution or when using [effect][filter] with a $this_unit. {{DevFeature1.13|9}} This is no longer needed when adding ABILITY_TELEPORT, ABILITY_LEADERSHIP or SPECIAL_BACKSTAB.&lt;br /&gt;
** Do not use a '''[modifications]''' tag, as this may skip some of the special-case handling for newly added objects, traits and advancements.&lt;br /&gt;
* '''[effect]''' {{DevFeature1.13|6}} Applies the effect directly to the unit. See [[EffectWML]].&lt;br /&gt;
* '''[set_variable]''', '''[clear_variable]''' {{DevFeature1.15|3}} Sets or clears a variable within the unit; uses the same syntax as [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] or [[InternalActionsWML#.5Bclear_variable.5D|[clear_variable]]] in ActionWML.&lt;br /&gt;
* Accepts generally the syntax inside of wml unit variables created by [store_unit] which can be viewed in a savefile or by using the [[CommandMode|inspect command]]. Cannot remove things or add/alter unit animations. Subtags with the same name must be written in the correct order to match them with the tag they are supposed to modify. Note that keys will be processed in arbitrary order, which may cause problems if you use formulas that depend on other formulas. To work around this you may need to use the tag twice with the same filter.&lt;br /&gt;
example usage (see also the test scenario):&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
[modify_unit]&lt;br /&gt;
  [filter]&lt;br /&gt;
    x,y=38,6&lt;br /&gt;
  [/filter]&lt;br /&gt;
  hitpoints=10&lt;br /&gt;
  {TRAIT_HEALTHY}&lt;br /&gt;
[/modify_unit]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The unit which is currently modified is accessible via $this_unit, e.g. hitpoints = &amp;quot;$($this_unit.hitpoints / 2)&amp;quot; to set the hitpoints of all units to half of their particular maxima. This this_unit variable is independent from the this_unit variable available in the SUF used to determine which units to modify (first all matching units are gathered, and then all those are modified).&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Some some properties of the units are reset sometimes (for example when the unit advances or when [remove_object] is called), so it's usually better to change them with [object] ([object] inside [modify_unit]) than to change those properties directly via [modify_unit]. The following properties are _not_ reset in [remove_object] and are thus safe to use directly in [modify_unit]:&lt;br /&gt;
* '''side'''&lt;br /&gt;
* '''gender'''&lt;br /&gt;
* '''name'''&lt;br /&gt;
* '''canrecruit'''&lt;br /&gt;
* '''unrenamable'''&lt;br /&gt;
* '''extra_recruit'''&lt;br /&gt;
* '''[variables]'''&lt;br /&gt;
* '''facing'''&lt;br /&gt;
* '''goto_x, goto_y'''&lt;br /&gt;
* '''hitpoints'''&lt;br /&gt;
* '''experience'''&lt;br /&gt;
* '''moves'''&lt;br /&gt;
* '''[status]''' (not sure on this one)&lt;br /&gt;
* '''attacks_left'''&lt;br /&gt;
* '''role'''&lt;br /&gt;
&lt;br /&gt;
=== [transform_unit] ===&lt;br /&gt;
Transforms every unit on the map matching the filter to the given unit type. Keeps intact hit points, experience and status. If the unit is transformed to a non-living type (undead or mechanical), it will be also unpoisoned. Hit points will be changed if necessary to respect the transformed unit's maximum hit points.&lt;br /&gt;
* [[StandardUnitFilter]]: do not use a [filter] tag.&lt;br /&gt;
* '''transform_to''': the unit type in which all the units matching the filter will be transformed. If missing, the units will follow their normal advancement.&lt;br /&gt;
&lt;br /&gt;
=== [petrify] ===&lt;br /&gt;
&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are petrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [unpetrify] ===&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are unpetrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [object] ===&lt;br /&gt;
Gives some unit an object which modifies their stats in some way.&lt;br /&gt;
* '''id''': (Optional) allows the item to be removed later. By default, an object with a defined ID can only be picked up once per scenario, even if it is removed later or first_time_only=no is set for the event. You can remove this restriction by setting take_only_once=no. For filtering objects, it might be simpler to use a custom key such as item_id. The id string can contain only letters, numbers and underscores.&lt;br /&gt;
* '''take_only_once''': (default yes) {{DevFeature1.13|6}} If set to &amp;quot;no&amp;quot;, the object's ID does not prevent it from being taken more than once.&lt;br /&gt;
* '''delayed_variable_substitution''' (boolean yes|no, default no): If set to &amp;quot;yes&amp;quot;, the wml block contained in this [object] is not variable-substituted at execution time of the event where this [object] is within.  You need this for any effect that uses variable substitution or when using [effect][filter] with a $this_unit. {{DevFeature1.13|9}} This is no longer needed when adding ABILITY_TELEPORT, ABILITY_LEADERSHIP or SPECIAL_BACKSTAB.&lt;br /&gt;
* '''[effect]''': one or more effect elements may be listed.  See [[EffectWML]] for a description of [effect].&lt;br /&gt;
* '''duration''':&lt;br /&gt;
**if 'scenario', effects only last until the end of the scenario.&lt;br /&gt;
**if 'forever' or not set, effects never wear off.&lt;br /&gt;
** if 'turn', effects only last until the start of the unit's next turn (when the unit refreshes movement and attacks). (Like other start-of-turn behavior, objects with a duration of &amp;quot;turn&amp;quot; won't expire before turn 2.)&lt;br /&gt;
** {{DevFeature1.13|1}} if 'turn end' or 'turn_end', effects only last until the end of the unit's next turn (exactly like the slowed status).&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. The first unit found that matches the filter will be given the object. Only on-map units are considered. If no unit matches or no [filter] is supplied, it is tried to apply the object to the unit at the $x1,$y1 location of the event where this [object] is in. The case of no unit being at that spot is handled in the same way as no unit matching a given filter ([else] commands executed, cannot_use_message displayed). Note that units on the recall list will not be checked. To add an [object] to a unit on the recall list you have to use '''[modify_unit][object]'''.&lt;br /&gt;
* '''[then]''': a subtag that lets you execute actions if the filter conditions are met.  The most common action that should be inside here is a '''[remove_item]''' tag, but you could probably put any tags that otherwise work in a [then] tag.&lt;br /&gt;
* '''[else]''': a subtag that lets you execute actions if the filter conditions are *not* met.&lt;br /&gt;
* '''silent''': whether or not messages should be suppressed. Default is &amp;quot;no&amp;quot;. {{DevFeature1.13|2}} If no description is provided, this defaults to yes, but can still be overridden.&lt;br /&gt;
* '''image''': the displayed image of the object.&lt;br /&gt;
* '''name''': (translatable) displayed as a caption of the image.&lt;br /&gt;
&lt;br /&gt;
* '''description''': (translatable) displayed as a message of the image.&lt;br /&gt;
* '''cannot_use_message''': (translatable) displayed instead of '''description''' if no unit passes the filter test.&lt;br /&gt;
&lt;br /&gt;
=== [remove_object] ===&lt;br /&gt;
{{DevFeature1.13|6}}&lt;br /&gt;
&lt;br /&gt;
Removes an object from matching units.&lt;br /&gt;
&lt;br /&gt;
* [[StandardUnitFilter]]: All units matching the filter have matching objects removed. Use no [filter] tag.&lt;br /&gt;
* '''object_id''': The id of the object to be removed.&lt;br /&gt;
&lt;br /&gt;
Note that some unit properties are not restored ideally, e.g. current unit's health reversion might not work as expected (max_hitpoints will though). {{DevFeature1.15|0}} This was fixed.&lt;br /&gt;
&lt;br /&gt;
Note that remove_object worked the following way: Step1) remove thos objects from the unit wml, Step2) Rebuild the unit to make the changes effective. Step2 implies that changes done for example via [modify_unit] (or via the [store_unit] + [set_variable] + [unstore_unit] technique) will be reset if those changes change a property that is a property of the unit type. See the note under [modify_unit] to get a list of properties that can safely be changes via [modify_unit]&lt;br /&gt;
&lt;br /&gt;
=== [remove_trait] ===&lt;br /&gt;
{{DevFeature1.15|2}}&lt;br /&gt;
&lt;br /&gt;
* [[StandardUnitFilter]]: All units matching the filter have matching traits removed. Use no [filter] tag.&lt;br /&gt;
* '''trait_id''': The id of the object to be removed.&lt;br /&gt;
&lt;br /&gt;
=== [remove_shroud] ===&lt;br /&gt;
Removes some shroud from the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to remove shroud. This can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles for which shroud should be removed&lt;br /&gt;
&lt;br /&gt;
=== [place_shroud] ===&lt;br /&gt;
Places some shroud on the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to place shroud. This can be a comma-separated list. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles on which shroud should be placed&lt;br /&gt;
&lt;br /&gt;
=== [lift_fog] ===&lt;br /&gt;
Lifts the fog of war from parts of the map for a certain side (only relevant for sides that have fog=yes), allowing a player to witness what occurs there even if that player has no units within vision range.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the tiles from which fog should be lifted.&lt;br /&gt;
* '''multiturn''': ''yes/no, default:no''. The default (not multiturn) causes fog to be removed in the same way that normal vision works; the cleared tiles will remain cleared until fog is recalculated (which normally happens when a side ends its turn). When multiturn is set to &amp;quot;yes&amp;quot;, the cleared tiles remain clear until {{tag||reset_fog}} cancels the clearing. This allows tiles to remain clear for multiple turns, or to be refogged before the end of the current turn (without also refogging all tiles). Multiturn lifted fog is not shared with allies (even when share_vision=all).&lt;br /&gt;
&lt;br /&gt;
=== [reset_fog] ===&lt;br /&gt;
The primary use of this tag is to remove multiturn lifted fog (created by {{tag||lift_fog}}), which causes the fog to reset to what it would have been had WML not interfered. (That is, hexes that a side's units could not see at any point this turn will be re-fogged, while seen hexes remain defogged.)&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the fog reset will be restricted to these tiles.&lt;br /&gt;
* '''reset_view''': ''yes/no, default: no'' If set to &amp;quot;yes&amp;quot;, then in addition to removing multiturn fog, the side's current view is canceled (independent of the SLF). This means that all hexes will become fogged for the side unless multiturn fog exists outside the tiles selected by the SLF. Normally, one would want the currently seen hexes to become clear of fog; this is done automatically at the end of many events, and it can be done manually with {{tag|InterfaceActionsWML|redraw}}.&lt;br /&gt;
Omitting both the SSF and the SLF would cancel all earlier uses of [lift_fog].&lt;br /&gt;
Additionally setting reset_view=&amp;quot;yes&amp;quot; would cause the side's entire map to be fogged (unless an ally keeps hexes clear by sharing its view).&lt;br /&gt;
&lt;br /&gt;
=== [allow_undo] ===&lt;br /&gt;
Normally when an event with a handler fires, the player's undo stack is cleared, preventing all actions performed so far from being undone. Including this tag in the event handler prevents the stack from being cleared for this reason, allowing the player to undo actions. (However, the stack might still be cleared for other reasons, such as fog being cleared or combat occurring.) In the common cases, this means '''[allow_undo]''' allows the current action to be undone even though an event was handled. There is a less common case, though &amp;amp;mdash; specifically when handling a menu item, where there is no current action &amp;amp;mdash; and in this case, '''[allow_undo]''' means merely that earlier actions can still be undone.&lt;br /&gt;
* Using this tag in a menu item has an additional side effect in 1.11. Starting with version 1.11.1, executing a WML menu item normally counts as doing something as far as the &amp;quot;you have not started your turn yet&amp;quot; dialog is concerned. However, a menu item whose handler includes '''[allow_undo]''' will not count.&lt;br /&gt;
&lt;br /&gt;
The types of actions that can be undone are movement, recalling, and dismissing a unit from the recall list. If an action is undone, only the position (or existence) of the involved unit will be restored; any altered variables or changes to the game will remain changed after the action is undone.  It is up to the scenario designer to avoid abusing this command.&lt;br /&gt;
* Technically, if '''[allow_undo]''' is inside an '''[event]''' with ''first_time_only=yes'' (the default setting), and the user undoes the event, then the state of the game has changed in this way: the event will not fire a second time, even though the user undid the action the first time.&lt;br /&gt;
* Although recalling can be undone, recruitment can not be undone; this seems to apply even when the recruit's traits are not randomly-generated (tested on 1.12.6 and 1.14.4+dev).&lt;br /&gt;
&lt;br /&gt;
If an '''[event]''' uses both '''[allow_undo]''' and [[InternalActionsWML#.5Bfire_event.5D|'''[fire_event]''']] then the '''[allow_undo]''' must be after the '''[fire_event]'''.&lt;br /&gt;
&lt;br /&gt;
Due to a bug in 1.12 (https://gna.org/bugs/?23323) '''[allow_undo]''' should not be used in events that use one of the following things because it might cause OOS: &lt;br /&gt;
* [message] with [option]s&lt;br /&gt;
* [get_global_variable]&lt;br /&gt;
* wesnoth.synchronize_choice&lt;br /&gt;
&lt;br /&gt;
While in 1.13 using '''[allow_undo]''' together with those things won't give you a guaranteed OOS, there are some non-obvious situations where it will, for example assume the following event:&lt;br /&gt;
&lt;br /&gt;
   [event]&lt;br /&gt;
     name=&amp;quot;moveto&amp;quot;&lt;br /&gt;
     [message]&lt;br /&gt;
       message = &amp;quot;message&amp;quot;&lt;br /&gt;
       [option]&lt;br /&gt;
         label = &amp;quot;option 1&amp;quot;&lt;br /&gt;
         [command]&lt;br /&gt;
         [/command]&lt;br /&gt;
       [/option]&lt;br /&gt;
       [option]&lt;br /&gt;
         label = &amp;quot;option 2&amp;quot;&lt;br /&gt;
         [command]&lt;br /&gt;
         [/command]&lt;br /&gt;
       [/option]&lt;br /&gt;
     [/message]&lt;br /&gt;
     [allow_undo]&lt;br /&gt;
     [/allow_undo]&lt;br /&gt;
   [/event]&lt;br /&gt;
&lt;br /&gt;
It will cause OOS when the message is undone: since the event is already executed (erased) on one client only , the clients will disagree about how many choices happen during the next moveto action.&lt;br /&gt;
&lt;br /&gt;
=== [on_undo] ===&lt;br /&gt;
{{DevFeature1.13|2}}&lt;br /&gt;
Contains commands to execute when the player undoes the action which triggered the parent event.&lt;br /&gt;
*'''delayed_variable_substitution''' {{DevFeature1.13|5}}: ''yes/no, default no (always no before 1.13.5)'' As in [[EventWML]], specifies whether to perform variable substitution when the parent event is run, or when the contents are run. If delayed substitution is used, [[SyntaxWML#Automatically_Stored_Variables|automatically stored variables]] from the parent event context are available, but may occasionally have unexpected values. (In particular, $unit.x and $unit.y may not have the expected value when undoing a move event, though $x1 and $y1 should be correct.)&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
It is not clear where whether the actionwml in [on_undo] in executed before or after the action is undone. Also, specially for enter/leave_hex events the units position when executing the [on_undo] code is usually different than when executing the original event. The recommended way to work around these issues is to refer to the unit by id instead of position and store all other needed information variables as 'upvalues'. You can also move the actual undo code to an external event. For example&lt;br /&gt;
 [event]&lt;br /&gt;
   name=&amp;quot;undo_blah&amp;quot;&lt;br /&gt;
   first_time_only=no&lt;br /&gt;
   [store_unit]&lt;br /&gt;
     id=&amp;quot;$moved_unit_id&amp;quot;&lt;br /&gt;
   [/store_unit]&lt;br /&gt;
   ... do undo stuff stuff&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
 ... in some other event&lt;br /&gt;
   [on_undo]&lt;br /&gt;
     # store ''upvalues&lt;br /&gt;
     {VARIABLE moved_unit_id $unit.id}&lt;br /&gt;
     # call actual undo handler&lt;br /&gt;
     [fire_event]&lt;br /&gt;
       name = &amp;quot;undo_blah&amp;quot;&lt;br /&gt;
     [/fire_event]&lt;br /&gt;
   [on_undo]&lt;br /&gt;
&lt;br /&gt;
=== [on_redo] ===&lt;br /&gt;
{{DevFeature1.13|2}}&lt;br /&gt;
Same as [on_undo], except executes the commands on redo. Note that the parent event is not triggered again on a redo.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|8}} [on_redo] is deprecated and has no effect anymore.&lt;br /&gt;
&lt;br /&gt;
Note that [on_redo] is not guaranteed to be called when redoing an action, the engine might also decide to just fire the original events again.&lt;br /&gt;
&lt;br /&gt;
=== [cancel_action] ===&lt;br /&gt;
Although Wesnoth 1.12 does not have this tag, it is the default behavior of {{tag|EventWML|enter_hex}}/{{tag|EventWML|leave_hex}} events in that version.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|9}} In this version, [cancel_action] is recognised, but has no effect (a bug).&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|11}}&lt;br /&gt;
In an {{tag|EventWML|enter_hex}}/{{tag|EventWML|leave_hex}} event, interrupt the movement, leaving the unit where it is. This is intended to be used with an event that gives the player new information, to let the player choose whether to change their plans. For example, if the player has commanded a unit to move from (1,1) to (3,3) and attack a unit on (4,4); then a [cancel_action] inside an [enter_hex] event on (2,2) would make the unit stop on (2,2). A [cancel_action] inside an [enter_hex] on (3,3) would let the player choose whether to attack.&lt;br /&gt;
&lt;br /&gt;
=== [heal_unit] ===&lt;br /&gt;
Heal a unit. The variable '''$heal_amount''' will be set to the exact number of points healed (i.e can be less than the parameter '''amount''' if the unit is fully healed). $heal_amount contains only the number of hitpoints the first unit that was found got healed. When the variable is not needed, use {CLEAR_VARIABLE heal_amount} after this tag.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.17|0}} The '''$heal_amount''' variable is no longer set. Use the '''variable''' key instead.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] All matching on-map units are healed. If no filter is supplied, it is tried to take the unit at $x1, $y1.&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] all the units matching the filter ''and'' having the ''heals'' ability will have their animation played (if ''animate'' is set to yes) for each of the units healed.&lt;br /&gt;
*  '''amount''': (integer, default full) the maximum points the unit(s) will be healed. This can't be used to set the unit's hitpoints below 1 or above the unit's maximum hitpoints. If &amp;quot;full&amp;quot;, it fully heals the unit.&lt;br /&gt;
*  '''animate''': a boolean which indicate if the healing animations must be played. (default no)&lt;br /&gt;
*  '''moves''': (integer, default 0) The maximum current movement points the units will be &amp;quot;healed&amp;quot;. Can't set below 0 or above max_moves. If &amp;quot;full&amp;quot;, sets moves to max_moves.&lt;br /&gt;
* '''restore_attacks''': (boolean, default no) Whether the units' attacks_left should be reset to their max_attacks (usually 1).&lt;br /&gt;
* '''restore_statuses''': (boolean, default yes) Whether standard statuses should be reset to &amp;quot;no&amp;quot;. This affects poisoned, slowed, petrified and unhealable.&lt;br /&gt;
* '''variable''': {{DevFeature1.17|0}} creates an array with the given name; each item of the array has two fields, ''id='' (the ID of the unit being healed) and ''heal_amount='' (the amount of HPs the unit has been healed by).&lt;br /&gt;
&lt;br /&gt;
=== [harm_unit] ===&lt;br /&gt;
Harms every unit matching the filter, for the specific damage amount.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] all matching units will be harmed (required).&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] if present, the first matching unit will attack all the units matching the filter above.&lt;br /&gt;
*  '''amount''': the amount of damage that will be done (required).&lt;br /&gt;
*  '''alignment''': (default neutral) applies an alignment to the damage, this means that if alignment=chaotic, the damage will be increased at night and reduced at day.&lt;br /&gt;
*  '''damage_type''': if present, amount will be altered by unit resistance to the damage type specified.&lt;br /&gt;
*  '''kill''': (default yes) if yes, when a harmed unit goes to or below 0 HP, it is killed; if no its HP are set to 1.&lt;br /&gt;
*  '''fire_event''': (default no) if yes, when a unit is killed by harming, the corresponding events are fired.  If yes, also the corresponding advance and post advance events are fired.&lt;br /&gt;
*  '''animate''': (default no) if yes, scrolls to each unit before harming it and plays its defense (or attack, if it's the harmer) and death animations. Special values supported, other than the usual yes and no, are &amp;quot;attacker&amp;quot;, that means only the harmer will be animated, and &amp;quot;defender&amp;quot;, that means only the harmed units will be animated. If the supplied value is yes, attacker or defender also advancement animations are played.&lt;br /&gt;
*  '''[primary_attack], [secondary_attack]''': these set the weapon against which the harmed units will defend, and that the harming unit will use to attack, respectively (notice this is the opposite of '''[filter]''' and '''[filter_second]''' above). This allows for playing specific defense and attack animations. Both tags are expected to contain a [[FilterWML#Filtering_Weapons|Standard Weapon Filter]].&lt;br /&gt;
*  '''delay''': if animate=yes, sets the delay (in milliseconds, default 500) between each unit harming.&lt;br /&gt;
*  '''variable''': if present, the damage caused to the unit, altered by resistances, will be stored in a WML array with the given name, under the &amp;quot;harm_amount&amp;quot; key.&lt;br /&gt;
*  '''poisoned, slowed, petrified, unhealable''': (default no) if yes, every harmed unit that doesn't already have such status will have it set.&lt;br /&gt;
*  '''experience''': if yes, and there is a harmer, experience will be attributed like in regular combat.&lt;br /&gt;
*  '''resistance_multiplier''': the harmed unit's resistance is multiplied by the supplied value; this means that a value lower than 1 increases it, and a value greater than 1 decreases it. Default value is 1, that means no modification.&lt;br /&gt;
&lt;br /&gt;
=== [time_area] ===&lt;br /&gt;
How a day should progress in a given area. Everywhere not specified in a [time_area] tag is affected by the [time] tags in the [scenario] tag.&lt;br /&gt;
* [[StandardLocationFilter]]: the locations to affect. ''note: only for [event][time_area]s - at scenario toplevel [time_area] does not support [[StandardLocationFilter]], only location ranges''&lt;br /&gt;
* '''[time]''': one or more tags describing the new schedule, see [[TimeWML]].&lt;br /&gt;
* '''id''': an unique identifier assigned to a time_area. Optional, unless you want to remove the time_area later or reference it from a location filter elsewhere. Can be a comma-separated list when removing time_areas, see below.&lt;br /&gt;
* '''remove''': (boolean) yes/no value. Indicates whether the specified time_area should be removed. Requires an identifier. If no identifier is used, however, all time_areas are removed.&lt;br /&gt;
* '''current_time''': The time slot number (starting with zero) active at the creation of the area.&lt;br /&gt;
&lt;br /&gt;
''Example:'' (caves in parts of a map)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=wml&amp;gt;&lt;br /&gt;
[time_area]&lt;br /&gt;
    id = cave_area&lt;br /&gt;
    x = 1-2,4-5&lt;br /&gt;
    y = 1-2,1-2&lt;br /&gt;
    {UNDERGROUND}&lt;br /&gt;
[/time_area]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying an id allows the area to be referenced from location filters. Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=wml&amp;gt;&lt;br /&gt;
    [time_area]&lt;br /&gt;
        id = glyphs&lt;br /&gt;
        x = 9,14&lt;br /&gt;
        y = 11,3&lt;br /&gt;
    [/time_area]&lt;br /&gt;
    [event]&lt;br /&gt;
        name = moveto&lt;br /&gt;
        first_time_only=no&lt;br /&gt;
        [filter]&lt;br /&gt;
            side = 1&lt;br /&gt;
            [filter_location]&lt;br /&gt;
                area = glyphs&lt;br /&gt;
            [/filter_location]&lt;br /&gt;
        [/filter]&lt;br /&gt;
        # Do something, for example healing the unit&lt;br /&gt;
    [/event]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [remove_time_area] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|2}}&lt;br /&gt;
&lt;br /&gt;
This is a syntactic shortcut for [time_area] remove=.&lt;br /&gt;
* '''id''': Comma-separated list of time area ids to remove.&lt;br /&gt;
&lt;br /&gt;
=== [end_turn] ===&lt;br /&gt;
End the current side's turn. The current event is finished before the turn is ended. Also, if the current event (where the tag appears) has been fired by another event, that event (and the complete stack of other possible parent events) is ended before [end_turn] comes into affect. Also, events following the event stack that fired [end_turn] are not omitted (e.g. [end_turn] is used by a side turn event and a turn refresh event does something afterwards).&lt;br /&gt;
&lt;br /&gt;
=== [replace_map] ===&lt;br /&gt;
&lt;br /&gt;
Replaces the entire map.&lt;br /&gt;
* '''map_data''': Content of a wesnoth map file. (This key used to be just '''map='''.) Example:&lt;br /&gt;
 map_data=&amp;quot;{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}&amp;quot;&lt;br /&gt;
* '''map_file''': {{DevFeature1.13|?}} Path to a Wesnoth map file; can be used instead of '''map'''. The file will be loaded when the tag is executed, rather than being embedded wholesale in the preprocessed WML. Example:&lt;br /&gt;
 map_file=campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map&lt;br /&gt;
{{DevFeature1.15|3}} If the file is not found directly, it will be searched for in the [[BinaryPathWML|[binary_path]]]. Assuming a standard campaign or add-on layout, the example above can be replaced by:&lt;br /&gt;
 map_file=01_The_Elves_Besieged.map&lt;br /&gt;
* '''expand''': if 'yes', allows the map size to increase. The expansion direction is currently always bottom-right.&lt;br /&gt;
* '''shrink''': if 'yes', allows the map size to decrease. If the map size is reduced, any units that would no longer be on the map due to its coordinates no longer existing will be put into the recall list.&lt;br /&gt;
Note: When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages it that there are too many choices to make; should a unit lose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [replace_schedule] ===&lt;br /&gt;
Replace the time of day schedule of the entire scenario.&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
* '''current_time''': The time slot number (starting with zero) active at schedule replacement.&lt;br /&gt;
&lt;br /&gt;
=== [tunnel] ===&lt;br /&gt;
&lt;br /&gt;
Create a tunnel between some locations, later usable by units to move from source hex to target hex (using the movement cost of unit on the target terrain).&lt;br /&gt;
&lt;br /&gt;
'''Behavior Change as of Wesnoth 1.13.6:''' Vision is now possible (and enabled by default) through tunnels and allied units on the exit hex do not block a tunnel by default any more. This is done in order for moves through tunnels to be consistent with other moves. The previous behavior can still be accomplished by using the new optional keys listed below.&lt;br /&gt;
&lt;br /&gt;
* '''[filter]''': (required) [[StandardUnitFilter]] the units which can use the tunnel. Leave empty for &amp;quot;all units&amp;quot;.&lt;br /&gt;
* '''[source]''': (required) [[StandardLocationFilter]] the source hex(es).&lt;br /&gt;
* '''[target]''': (required) [[StandardLocationFilter]] the target hex(es).&lt;br /&gt;
* '''id''': (optional) identifier for the tunnel, to allow removing.&lt;br /&gt;
* '''remove''': (boolean, default: no)  If yes, removes all defined tunnels with the same ID (then only id= is necessary).&lt;br /&gt;
* '''bidirectional''': (boolean, default: yes) If yes, creates also a tunnel in the other direction. &lt;br /&gt;
* '''always_visible''': (boolean, default: no) If yes, the possible movement of enemies under fog can be seen.&lt;br /&gt;
* '''allow_vision''': (boolean, default: yes) {{DevFeature1.13|6}} If no, vision through a tunnel is not possible. Note that in that case the tunnel cannot be used if the tunnel exit is under shroud (which previously was ''always'' the case).&lt;br /&gt;
* '''pass_allied_units''': (boolean, default: yes) {{DevFeature1.13|6}} If no, allied (including own) units on the exit hex block a tunnel.&lt;br /&gt;
* '''delayed_variable_substitution''' (boolean, default: yes): If yes, the WML block contained in this [tunnel] is not variable-substituted at execution time of the event where this [tunnel] is within. Instead, variables are substituted when the tunnel is used by a unit. See [[EventWML#Nested_Events]]&lt;br /&gt;
&lt;br /&gt;
(Note: The tunnel tag can also be used inside the [[AbilitiesWML|[teleport]]] ability, without remove= and id=).&lt;br /&gt;
&lt;br /&gt;
=== [do_command] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Executes a command, specified using the same syntax as a [command] tag in [[ReplayWML]]. Not all [command]'s are valid: only these are accepted&lt;br /&gt;
&lt;br /&gt;
* [attack]&lt;br /&gt;
* [move]&lt;br /&gt;
* [recruit]&lt;br /&gt;
* [recall]&lt;br /&gt;
* [disband]&lt;br /&gt;
* [fire_event]&lt;br /&gt;
* [lua_ai] {{DevFeature1.13|12}} This has been removed and is replaced with [custom_command]&lt;br /&gt;
&lt;br /&gt;
The tags corresponding to player actions generally use the same codepath as if a player had ordered it. That means for example that only moves that player would be allowed to do are possible, and movement is interrupted when sighting enemy unit.&lt;br /&gt;
&lt;br /&gt;
One purpose of this tag is to allow scripting of noninteractive scenarios -- without a tag like this, this might require elaborate mechanisms to coerce ais in order to test these code paths.&lt;br /&gt;
&lt;br /&gt;
This command should be replay safe if it is either invoked in a synced context, ''or'' invoked in code that is never synced, like AI code, a select event, or a menu item with `synced = false`. However, if you use desynchronized logic ''during'' an event that is otherwise synced, invoking [do_command] based on that desynchronized logic will result in out-of-sync errors during the replay; in this case, you must explicitly synchronize which command to do using something like the lua function wesnoth.sync.evaluate_single.&lt;br /&gt;
&lt;br /&gt;
=== [put_to_recall_list] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Puts a unit to the recall list of its side.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': the unit(s) to get put to the recall list.&lt;br /&gt;
* '''heal''': (default=no) Whether the unit should be refreshed, similar to the unit moving to the recall list at the end of a scenario.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Useful Macros ==&lt;br /&gt;
There are some predefined macros that you find useful for direct actions. You can find a complete list along with a detailed explanation of how they work [https://www.wesnoth.org/macro-reference.html here].&lt;br /&gt;
* '''{MOVE_UNIT}''': Moves a unit to another location in the map and the player sees the movement (unlike [teleport])&lt;br /&gt;
* '''{FULL_HEAL}''': Brings a unit to full HP&lt;br /&gt;
* '''{LOYAL_UNIT}''': Create a loyal unit&lt;br /&gt;
* '''{MODIFY_TERRAIN_MASK}''': Modify an area of terrain&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaAPI/gui&amp;diff=69158</id>
		<title>LuaAPI/gui</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaAPI/gui&amp;diff=69158"/>
		<updated>2022-01-10T21:25:59Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Document gui.get_user_choice()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DevFeature1.15|0}}&lt;br /&gt;
&lt;br /&gt;
=== gui.show_menu ===&lt;br /&gt;
&lt;br /&gt;
* '''gui.show_menu'''(''items'', [''initial''], [''markup'']) &amp;amp;rarr; ''index''&lt;br /&gt;
&lt;br /&gt;
Shows a popup menu onscreen at the current mouse location. This could be used for example to produce a sort of submenu in a &amp;lt;tt&amp;gt;[set_menu_item]&amp;lt;/tt&amp;gt;. The items are specified as a Lua array of tables, each of which supports the following keys:&lt;br /&gt;
&lt;br /&gt;
* ''icon'': An icon to display in the leftmost column of the menu.&lt;br /&gt;
* ''image'': An image to display in the main column of the menu. If this is present, ''label'' is ignored.&lt;br /&gt;
* ''label'': A label to display in the main column of the menu.&lt;br /&gt;
* ''details'': A secondary label to display in the right column of the menu.&lt;br /&gt;
* ''tooltip'': Text to display when mousing over this option.&lt;br /&gt;
&lt;br /&gt;
The ''initial'' argument must be a valid index into the ''items'' array, or 0 to indicate that no element is initially selected (which is the default but typically not what you want).&lt;br /&gt;
&lt;br /&gt;
The ''markup'' argument specifies whether Pango markup will be parsed in the menuitems. It defaults to false.&lt;br /&gt;
&lt;br /&gt;
The ''initial'' and ''markup'' arguments can be passed in either order; the game will understand which is meant based on the type of the argument.&lt;br /&gt;
&lt;br /&gt;
This function returns the index of the selected item. If the user cancelled by clicking outside the menu's boundary, 0 is returned.&lt;br /&gt;
&lt;br /&gt;
=== gui.show_narration ===&lt;br /&gt;
&lt;br /&gt;
* '''gui.show_narration'''(''attributes'', [''options'', [''text_input_attributes'']]) &amp;amp;rarr; ''result_code'', [''entered_text'']&lt;br /&gt;
&lt;br /&gt;
Shows a message dialog, of the type used by the &amp;lt;tt&amp;gt;[message]&amp;lt;/tt&amp;gt; ActionWML tag. Unlike the &amp;lt;tt&amp;gt;[message]&amp;lt;/tt&amp;gt; tag, this is unsynced; if you need it synced, you must do it yourself. The first argument is a table describing the dialog with the following keys:&lt;br /&gt;
&lt;br /&gt;
* ''title'' - The title to show on the message. For example, the speaker's name.&lt;br /&gt;
* ''message'' - The message content.&lt;br /&gt;
* ''portrait'' - An image to show along with the message. By default, no image is shown.&lt;br /&gt;
* ''left_side'' - The default is true; set to false to show the image on the right.&lt;br /&gt;
* ''mirror'' - If true, the image will be flipped horizontally.&lt;br /&gt;
&lt;br /&gt;
The second argument is a list of options as a Lua array. Each option is either a (possibly-translatable) string or a config with [[DescriptionWML#WML_Format|DescriptionWML]] keys. The array itself can also have an optional '''default''' key which if present should be the index of the initially selected option (useful if you don't need full DescriptionWML but want to set a default). If present it overrides any defaults set in individual options.&lt;br /&gt;
&lt;br /&gt;
The third argument is a table describing the text input field with the following keys:&lt;br /&gt;
&lt;br /&gt;
* ''label'' - A label to show to the left of the text field.&lt;br /&gt;
* ''text'' - Initial contents of the text field.&lt;br /&gt;
* ''max_length'' - Maximum input length in characters (defaults to 256).&lt;br /&gt;
&lt;br /&gt;
You need at least one key for the text input to be shown. Both the second and third arguments are optional, but if you want text input with no options, you must pass nil for the second parameter.&lt;br /&gt;
&lt;br /&gt;
This function returns one or two values. The first value returned is the numeric result of the dialog:&lt;br /&gt;
&lt;br /&gt;
* If there are no options and no text input, the result is -2 if the user pressed Escape, or -1 if they closed by clicking or pressing Space.&lt;br /&gt;
* If there are options, the result is the index of the option chosen (starting from 1).&lt;br /&gt;
* If there is text input but no options, the first return value is 0.&lt;br /&gt;
&lt;br /&gt;
The second value returned is the text entered, if there was text input. Otherwise there is no second value (it is nil).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
gui.show_narration({&lt;br /&gt;
    title = &amp;quot;Make your choice:&amp;quot;,&lt;br /&gt;
    message = &amp;quot;Select an option and enter some text.&amp;quot;,&lt;br /&gt;
    portrait = &amp;quot;wesnoth-icon.png&amp;quot;,&lt;br /&gt;
}, {&lt;br /&gt;
    &amp;quot;The first choice is always the best!&amp;quot;,&lt;br /&gt;
    &amp;quot;Pick me! Second choices are better!&amp;quot;,&lt;br /&gt;
    &amp;quot;You know you want the third option!&amp;quot;,&lt;br /&gt;
}, {&lt;br /&gt;
    label = &amp;quot;Text:&amp;quot;,&lt;br /&gt;
    text = &amp;quot;?&amp;quot;,&lt;br /&gt;
    max_length = 16&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(You don't have to format it like that, of course.)&lt;br /&gt;
&lt;br /&gt;
=== gui.get_user_choice ===&lt;br /&gt;
&lt;br /&gt;
* '''gui.get_user_choice'''(''attributes'', ''options'')&lt;br /&gt;
&lt;br /&gt;
Shows a message dialog (like the one used by the &amp;lt;tt&amp;gt;[message]&amp;lt;/tt&amp;gt; tag) with a series of options and returns the index (1-based) of the chosen option, which can be stored as a Lua variable.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT NOTE: this function is broken in Wesnoth 1.16.0 and 1.16.1.''' If you wish to use it, you should also use wesnoth.current_version to check that your code is being run on Wesnoth 1.16.2 or higher.&lt;br /&gt;
&lt;br /&gt;
The first argument is a table of attributes which are directly passed to the underlying &amp;lt;tt&amp;gt;[message]&amp;lt;/tt&amp;gt; tag.&lt;br /&gt;
&lt;br /&gt;
The second argument is a table of options, which are used to construct a series of underlying &amp;lt;tt&amp;gt;[option]&amp;lt;/tt&amp;gt; tags. Most Lua data types are supported, but a few aren't:&lt;br /&gt;
* If the option is a ''table'' or a ''WML table'', these fields are supported:&lt;br /&gt;
** ''image'': icon shown in the first column;&lt;br /&gt;
** ''label'': text shown in the second column;&lt;br /&gt;
** ''description'': text shown in the third column (''message'' is also supported as an alias);&lt;br /&gt;
** ''default'': whether this is option is the one selected when the dialog is shown (boolean).&lt;br /&gt;
* If the option can be cast as string (''strings'', ''translatable strings'', ''numbers'', ''booleans''), it is used for the content of the description field, which means that the first two columns will be empty.&lt;br /&gt;
* If the option is a ''function'' or a ''thread'', it raises an &amp;quot;invalid data type&amp;quot; error.&lt;br /&gt;
&lt;br /&gt;
Example taken from the test scenario:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
local result = gui.get_user_choice(&lt;br /&gt;
    { speaker = &amp;quot;unit&amp;quot;, message = &amp;quot;Pick your poison&amp;quot; },&lt;br /&gt;
    { { image = &amp;quot;items/potion-red.png&amp;quot;,&lt;br /&gt;
        label = &amp;quot;Something red&amp;quot;,&lt;br /&gt;
        description = &amp;quot;Take a sip and enjoy&amp;quot; },&lt;br /&gt;
      { image = &amp;quot;items/potion-blue.png&amp;quot;,&lt;br /&gt;
        label = &amp;quot;Nice blue&amp;quot;,&lt;br /&gt;
        description = &amp;quot;Surely you’ll like that one&amp;quot;,&lt;br /&gt;
        default = true },&lt;br /&gt;
      { image = &amp;quot;items/potion-yellow.png&amp;quot;,&lt;br /&gt;
        label = &amp;quot;&amp;lt;span color='yellow'&amp;gt;Oh noes yellow&amp;lt;/span&amp;gt;&amp;quot;,&lt;br /&gt;
        description = &amp;quot;Oh I’m sure you’ll love that one&amp;quot; },&lt;br /&gt;
      { image = &amp;quot;scenery/well.png&amp;quot;,&lt;br /&gt;
        label = &amp;quot;A nice well&amp;quot;,&lt;br /&gt;
        description = &amp;quot;Grab a bucket and fetch some water&amp;quot; },&lt;br /&gt;
      { image = &amp;quot;items/holy-water.png&amp;quot;,&lt;br /&gt;
        label = &amp;quot;Oh nice bottle&amp;quot;,&lt;br /&gt;
        description = &amp;quot;Feel the divinity&amp;quot; },&lt;br /&gt;
      -- Should have an empty first column and a second column on two lines.&lt;br /&gt;
      { label = &amp;quot;Well a nice and black drink.\nToo dark too see?&amp;quot;,&lt;br /&gt;
        description = &amp;quot;Take a sip and pass the bottle along&amp;quot; }&lt;br /&gt;
    })&lt;br /&gt;
wesnoth.interface.add_chat_message(string.format(&amp;quot;User selected choice %d.&amp;quot;, result))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== gui.show_popup ===&lt;br /&gt;
&lt;br /&gt;
* '''gui.show_popup'''(''title'', ''message'', [''image''])&lt;br /&gt;
&lt;br /&gt;
Shows a simple popup dialog in the centre of the screen. Takes three arguments, which in order are:&lt;br /&gt;
&lt;br /&gt;
# A title string for the dialog&lt;br /&gt;
# The message content for the dialog.&lt;br /&gt;
# An image to show.&lt;br /&gt;
&lt;br /&gt;
Both the title and the message support Pango markup. The image is optional.&lt;br /&gt;
&lt;br /&gt;
=== gui.show_prompt ===&lt;br /&gt;
&lt;br /&gt;
* '''gui.show_prompt'''(''title'', ''message'', [''button''], [''markup'']) &amp;amp;rarr; ''result''&lt;br /&gt;
* '''gui.confirm'''([''title'',] ''message'') &amp;amp;rarr; ''result''&lt;br /&gt;
* '''gui.alert'''([''title''], ''message'')&lt;br /&gt;
&lt;br /&gt;
Shows a standard message box onscreen (similar to the quit confirmation message, for example). The button can be any arbitrary potentially-translatable string (in which case, there will be one button with that label), or it can be one of the following special string values:&lt;br /&gt;
&lt;br /&gt;
* ''ok'' or nil: A single OK button; this is the default&lt;br /&gt;
* ''cancel'': A single Cancel button&lt;br /&gt;
* ''close'': A single Close button&lt;br /&gt;
* ''ok_cancel'': Two buttons labelled OK and Cancel&lt;br /&gt;
* ''yes_no'': Two buttons labelled Yes and No&lt;br /&gt;
* an empty string: No buttons; the dialog automatically closes after a few seconds&lt;br /&gt;
&lt;br /&gt;
The alert and confirm functions are simpler wrappers for this function, using a single OK button and a pair of Yes/No buttons, respectively. Both confirm and show_prompt return false if No or Cancel was clicked, and true otherwise. The alert function returns nothing.&lt;br /&gt;
&lt;br /&gt;
=== gui.show_story ===&lt;br /&gt;
&lt;br /&gt;
* '''gui.show_story'''(''story_config'', ''default_title'')&lt;br /&gt;
&lt;br /&gt;
Shows the storyscreen. The passed config is identical to the contents of [[IntroWML|[story]]]. The second parameter is the default title used if a part does not specify one — unlike intro storyscreens, a Lua-invoked one does not default to the scenario name.&lt;br /&gt;
&lt;br /&gt;
=== gui.show_dialog ===&lt;br /&gt;
&lt;br /&gt;
* '''gui.show_dialog'''(''dialog definition'', ''preshow'', ''postshow'') &amp;amp;rarr; ''retval''&lt;br /&gt;
&lt;br /&gt;
Displays a dialog box described by a WML table and returns an integer&lt;br /&gt;
* if the dialog was dismissed by a button click, the integer value associated to the button via the '''return_value''' keyword.&lt;br /&gt;
* if the dialog was closed with the enter key, -1.&lt;br /&gt;
* if the dialog was closed with the escape key, -2.&lt;br /&gt;
&lt;br /&gt;
The dialog box is equivalent to the '''[resolution]''' section of a GUI window as described in [https://devdocs.wesnoth.org/GUIToolkitWML.html GUIToolkit] and must therefore contain at least the following children: '''[tooltip]''', '''[helptip]''', and '''[grid]'''. The [grid] must contain nested [row], [column] and [grid] tags which describe the layout of the window. (More information can be found in [https://devdocs.wesnoth.org/GUILayout.html Layout]; suffice to say that the basic structure is grid -&amp;gt; row -&amp;gt; column -&amp;gt; widget, where the widget is considered to be in a cell defined by the row and column of the grid. A list of widgets can be found at [https://devdocs.wesnoth.org/group__GUIWidgetWML.html Widgets].)&lt;br /&gt;
&lt;br /&gt;
Two optional functions can be passed as second and third arguments; the first one is called once the dialog is created and before it is shown; the second one is called once the dialog is closed. These functions are helpful in setting the initial values of the fields and in recovering the final user values. These functions take a single parameter, which is the [[LuaAPI/types/widget|widget userdata]] representing the window.&lt;br /&gt;
&lt;br /&gt;
For in-game dialogs that offer the player a choice and/or can change the game state, this function should be called in conjunction with [[LuaAPI/wesnoth/sync#evaluate_single|wesnoth.sync.evaluate_single]], in order to ensure that only one client displays the dialog and that the other ones recover the same input values from this single client. Though this is especially important in multiplayer scenario, failing to do it in a single-player scenario will cause the replay to break, so it should be done in either case.&lt;br /&gt;
&lt;br /&gt;
See [[LuaAPI/gui/example|here]] for a fully-working example of a custom dialog.&lt;br /&gt;
&lt;br /&gt;
=== gui.add_widget_definition ===&lt;br /&gt;
&lt;br /&gt;
* '''gui.add_widget_definition'''(''widget_type'', ''definition_id'', ''wml_content'')&lt;br /&gt;
&lt;br /&gt;
Creates a new WML widget definition for the specified widget type, which can be referenced from dialog WML in the '''definition''' key.&lt;br /&gt;
&lt;br /&gt;
=== gui.widget ===&lt;br /&gt;
&lt;br /&gt;
A [[LuaAPI/gui/widget|submodule]] containing functions for working with widgets in custom dialogs.&lt;br /&gt;
&lt;br /&gt;
=== gui.show_help ===&lt;br /&gt;
&lt;br /&gt;
* '''gui.show_help'''([''topic''])&lt;br /&gt;
&lt;br /&gt;
Show the in-game help, optionally opening a specified topic directly.&lt;br /&gt;
&lt;br /&gt;
=== gui.show_inspector ===&lt;br /&gt;
&lt;br /&gt;
* {{LuaGameOnly}} '''gui.show_inspector'''()&lt;br /&gt;
&lt;br /&gt;
Show the gamestate inspector.&lt;br /&gt;
&lt;br /&gt;
=== gui.show_lua_console ===&lt;br /&gt;
&lt;br /&gt;
* '''gui.show_lua_console'''()&lt;br /&gt;
&lt;br /&gt;
Shows the Lua console. This works even if debug mode is not enabled.&lt;br /&gt;
&lt;br /&gt;
[[Category:Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Time&amp;diff=68071</id>
		<title>LuaWML/Time</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Time&amp;diff=68071"/>
		<updated>2021-06-17T21:05:37Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* wesnoth.get_time_of_day */ Added sound and mask fields to returned table&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:LuaMove}}&lt;br /&gt;
&lt;br /&gt;
[[LuaWML]] functions revolving around Time of Day schedule functionality, including time areas.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_time_of_day ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_time_of_day([''for_turn''], [ {''x'', ''y'', [''consider_illuminates'']} ])'''&lt;br /&gt;
&lt;br /&gt;
Returns schedule information. First parameter (optional) is the turn number for which to return the information, if unspecified: the current turn ($turn_number). Second argument is an optional table. If present, first and second fields must be valid on-map coordinates and all current time_areas in the scenario are taken into account (if a time area happens to contain the passed hex). If the table isn't present, the scenario main schedule is returned. The table has an optional third parameter (boolean). If true (default: false), time of day modifying units and terrain (such as Mages of Light or lava) are taken into account (if the passed hex happens to be affected). The units' placement being considered is always the current one.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.get_time_of_day(2, { 37, 3, true })&lt;br /&gt;
&lt;br /&gt;
The function returns a table with these named fields:&lt;br /&gt;
* '''id''': string (as in [time])&lt;br /&gt;
* '''lawful_bonus''': integer (as in [time])&lt;br /&gt;
* '''bonus_modified''': integer (bonus change by units)&lt;br /&gt;
* '''image''': string (tod image in sidebar)&lt;br /&gt;
* '''name''': translatable string&lt;br /&gt;
* '''red, green, blue''': integers (color adjustment for this time)&lt;br /&gt;
* {{DevFeature1.15|14}} '''sound''': string (sound played, as in [time])&lt;br /&gt;
* {{DevFeature1.15|14}} '''mask''': string (image displayed over hexes, as in [time])&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.add_time_area ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.add_time_area(''cfg'')'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Creates a new time area. This takes a WML table containing the same information normally used by the [[DirectActionsWML#.5Btime_area.5D|[time_area]]] tag.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|2}} Since 1.13.2, commas in the id attribute of the WML table are no longer handled specially for this function, allowing the creation of time areas with commas in their ids (but why would anyone want to do that, really).&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.remove_time_area ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.remove_time_area(''id'')'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Removes a time area. This requires the time area to have been assigned an id at creation time.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|2}} Since 1.13.2, commas in the id are no longer handled specially for this function, requiring you to use a loop to remove multiple time areas instead.&lt;br /&gt;
&lt;br /&gt;
 for i, id in ipairs({'foo', 'bar', 'baz'}) do&lt;br /&gt;
     wesnoth.remove_time_area(id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_max_liminal_bonus ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_max_liminal_bonus()'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.15|4}} Returns the maximum attack bonus that liminal units can get in the current scenario.&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=65689</id>
		<title>LuaWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=65689"/>
		<updated>2020-06-16T15:08:44Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* Time of day schedule */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
== The '''[lua]''' tag ==&lt;br /&gt;
&lt;br /&gt;
This tag is a part of [[ActionWML]], thus can be used inside [event] and at other places where [[ActionWML]] can be used. It makes it possible to write actions with the [http://www.lua.org Lua 5.3] language.&lt;br /&gt;
&lt;br /&gt;
It is also possible to put this tag inside a [scenario] [[ScenarioWML]], those tags will be executed immediately when the lua engine loads which is even before the scenario preload event is fired.&lt;br /&gt;
&lt;br /&gt;
[lua] is now also allowed in [era], [modification] and [resource], those [lua] tags are then copied into the [scenario]/[multiplayer] when it is played just like [event]s inside [era] or [modification]&lt;br /&gt;
&lt;br /&gt;
The tag supports only the '''code''' key, which is a string containing the Lua scripts. Since Lua makes usage of the quotes and the { and } symbols, it is certainly wise to enclose the script between stronger quotes, as they prevent the preprocessor from performing macro expansion and tokenization.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; wesnoth.message &amp;quot;Hello World!&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
 [/lua]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Lua kernel can also be accessed from the [[CommandMode|command mode]]:&lt;br /&gt;
&lt;br /&gt;
 :lua local u = wesnoth.get_units({ id = &amp;quot;Konrad&amp;quot; })[1]; u.moves = 5&lt;br /&gt;
&lt;br /&gt;
The '''[args]''' sub-tag can be used to pass a WML object to the script via its variadic local variable &amp;quot;'''...'''&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; local t = ...; wesnoth.message(tostring(t.text)) &amp;gt;&amp;gt;&lt;br /&gt;
     [args]&lt;br /&gt;
         text = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/args]&lt;br /&gt;
 [/lua]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Global environment ==&lt;br /&gt;
&lt;br /&gt;
All the Lua scripts of a scenario share the same global environment (aka Lua state). Unlike other parts of the configurable gamestate the Lua state is not stored in savefiles, thus [lua] tags in [scenario] are executed not only before the scenario starts but also each time the game is loaded. Funtions defined in [lua] tags in [scenario] can be used in all [lua] tags in [event]s.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             function narrator(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
     [event]&lt;br /&gt;
         name = turn 1&lt;br /&gt;
         [lua]&lt;br /&gt;
             code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
             [args]&lt;br /&gt;
                 sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
             [/args]&lt;br /&gt;
         [/lua]&lt;br /&gt;
         [lua]&lt;br /&gt;
             code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
             [args]&lt;br /&gt;
                 sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
             [/args]&lt;br /&gt;
         [/lua]&lt;br /&gt;
     [/event]&lt;br /&gt;
     ...&lt;br /&gt;
 [/scenario]&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above, the redundant structure could be hidden behind macros. But it may be better to simply define a new WML tag.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             -- The function is now placed in the wesnoth.wml_actions table&lt;br /&gt;
             -- The tag is [narrator], same as the function name&lt;br /&gt;
             function wesnoth.wml_actions.narrator(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         name = turn 1&lt;br /&gt;
         [narrator]&lt;br /&gt;
             sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
         [/narrator]&lt;br /&gt;
         [narrator]&lt;br /&gt;
             sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
         [/narrator]&lt;br /&gt;
     [/event]&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The global environment is not preserved over save/load cycles. Therefore, storing values in the global environment is generally a bad idea. The only time assigning global variables (including function definitions) makes sense is in a [lua] block directly in [scenario] or during a [[EventWML#Predefined 'name' Key Values|preload]] event, as this event is always run. Therefore, helper functions defined at that time will be available to all the later scripts.&lt;br /&gt;
&lt;br /&gt;
The global environment initially contains the following modules: [http://www.lua.org/manual/5.3/manual.html#6.1 basic] (no name), [http://www.lua.org/manual/5.3/manual.html#6.4 string], [http://www.lua.org/manual/5.3/manual.html#6.6 table], and [http://www.lua.org/manual/5.3/manual.html#6.7 math]. A '''wesnoth''' module is also available, it provides access to the [[#Interface to the C++ engine|C++ engine]]. Additionally, the functions clock, date, time and difftime from the [http://www.lua.org/manual/5.3/manual.html#6.9 os] library (keep in mind that they aren't multiplayer- and replay-safe), as well as traceback from the [http://www.lua.org/manual/5.3/manual.html#6.10 debug] library are also available.&lt;br /&gt;
&lt;br /&gt;
At the start of a script, the variadic local variable '''...''' (three dots) is a proxy table representing [[#Encoding WML objects into Lua tables|WML data]]. This table is the content of the '''[args]''' sub-tag of the '''[lua]''' tag, if any.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following WML event is taken from Wesnoth' tutorial. It will serve as an example to present how Lua scripts are embedded into Wesnoth. The event is fired whenever a unit from side 1 (that is, the hero controlled by the user) moves to a tile that is not the one set in the WML variable ''target_hex''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
 # General catch for them moving to the wrong place.&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [if]&lt;br /&gt;
         [variable]&lt;br /&gt;
             name=target_hex.is_set&lt;br /&gt;
             equals=yes&lt;br /&gt;
         [/variable]&lt;br /&gt;
         [then]&lt;br /&gt;
             [if]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=x1&lt;br /&gt;
                     equals=$target_hex.x&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=y1&lt;br /&gt;
                     equals=$target_hex.y&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [then]&lt;br /&gt;
                 [/then]&lt;br /&gt;
                 [else]&lt;br /&gt;
                     [redraw][/redraw]&lt;br /&gt;
                     [message]&lt;br /&gt;
                         speaker=narrator&lt;br /&gt;
                         message=_ &amp;quot;*Oops!&lt;br /&gt;
 You moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot; +&lt;br /&gt;
                         _ &amp;quot;&lt;br /&gt;
 *Left click or press spacebar to continue...&amp;quot;&lt;br /&gt;
                     [/message]&lt;br /&gt;
                 [/else]&lt;br /&gt;
             [/if]&lt;br /&gt;
         [/then]&lt;br /&gt;
     [/if]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A Lua script that performs the same action is presented below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
&lt;br /&gt;
             local event_data = wesnoth.current.event_context&lt;br /&gt;
             if wml.variables[&amp;quot;target_hex.is_set&amp;quot;] and&lt;br /&gt;
                (event_data.x1 ~= wml.variables[&amp;quot;target_hex.x&amp;quot;] or event_data.y1 ~= wml.variables[&amp;quot;target_hex.y&amp;quot;])&lt;br /&gt;
             then&lt;br /&gt;
                 W.redraw()&lt;br /&gt;
                 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a more detailed explanation of the Lua code. Its first line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
local event_data = wesnoth.current.event_context&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
puts the event data into the ''event_data'' local variable. Since it is a ''moveto'' event, the ''event_data'' table contains the destination of the unit in the ''x1'' and ''y1'' fields.&lt;br /&gt;
&lt;br /&gt;
The next two lines then test&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
if wml.variables[&amp;quot;target_hex.is_set&amp;quot;] and&lt;br /&gt;
    (event_data.x1 ~= wml.variables[&amp;quot;target_hex.x&amp;quot;] or event_data.y1 ~= wml.variables[&amp;quot;target_hex.y&amp;quot;])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
whether the variable ''wml.variables[&amp;quot;target_hex&amp;quot;]'' matches the event parameters. Since ''wml.variables'' is not a local variable, it is taken from the global environment. Usually, variables from the global environment are not persistent but the wesnoth engine maps the variable wml.variables to the storage of WML variables.&lt;br /&gt;
&lt;br /&gt;
Without using wml.variables, the conditional would have been written&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
if wesnoth.get_variable(&amp;quot;target_hex.is_set&amp;quot;) and&lt;br /&gt;
    (event_data.x1 ~= wesnoth.get_variable(&amp;quot;target_hex.x&amp;quot;) or event_data.y1 ~= wesnoth.get_variable(&amp;quot;target_hex.y&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The body of the conditional then performs the [[InterfaceActionsWML#Other interface tags|[redraw]]] action.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
W.redraw()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This short syntax is made possible by a line of the prelude that makes ''W'' a proxy for performing WML actions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
 [scenario]&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             W = H.set_wml_action_metatable {}&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
     ...&lt;br /&gt;
 [/scenario]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Without this shortcut, the first statement would have been written&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
wesnoth.fire(&amp;quot;redraw&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
wesnoth.wml_actions.redraw {}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally the script displays a message by&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ''narrator_says'' function is defined in the prelude too, since the construct behind it occurs several times in the tutorial. In plain WML, macros would have been used instead. The definition of the function is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
function narrator_says(m)&lt;br /&gt;
    W.message { speaker=&amp;quot;narrator&amp;quot;,&lt;br /&gt;
                message = m .. _ &amp;quot;\n*Left click or press spacebar to continue...&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function fires a [[InterfaceActionsWML#.5Bmessage.5D|[message]]] action and passes a WML object containing the usual two fields to it. The second field is initialized by concatenating the function argument with another string. Both strings are prefixed by the ''_'' symbol to mark them as translatable. (Note that ''_'' is just a unary function, not a keyword.) Again, this is made possible by a specific line of the prelude:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
_ = wesnoth.textdomain &amp;quot;wesnoth-tutorial&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A longer translation of the tutorial is available at [https://gna.org/patch/download.php?file_id=5483].&lt;br /&gt;
&lt;br /&gt;
== Interface to the engine and helper functions ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;div class=&amp;quot;navtemplate&amp;quot; style=&amp;quot;width: auto; max-width: 75%; margin: 0 auto; border: 1px solid #c60; border-left-width: 8px&amp;quot;&amp;gt;&amp;lt;div style=&amp;quot;float:left;position:relative;top:-14px;left:-6px&amp;quot;&amp;gt;https://raw.github.com/wesnoth/wesnoth/master/data/core/images/items/bones.png&amp;lt;/div&amp;gt;&amp;lt;p style=&amp;quot;margin:0&amp;quot;&amp;gt;&amp;lt;strong&amp;gt;This section is in the process of being moved.&amp;lt;/strong&amp;gt; The information here remains accurate as of 1.14.0, but for 1.15.0 and later, [[LuaAPI]] is planned to be the definitive source.&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Functionalities of the game engine are available through the functions contained in the '''wesnoth''' global table. Some of these functions return proxy tables. Writes to fields marked &amp;quot;read-only&amp;quot; are ignored. The '''__cfg''' fields return plain tables; in particular, writes do not modify the original object, and reads return the values from the time the dump was performed.&lt;br /&gt;
&lt;br /&gt;
Some helper functions are provided by the '''lua/helper.lua''' library. They are stored inside a table that is returned when loading the library with [[LuaWML:Files#wesnoth.require|wesnoth.require]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
helper = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WML variables ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_all_vars|wesnoth.get_all_vars]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.wml_matches_filter|wesnoth.wml_matches_filter]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Variables#helper.set_wml_var_metatable|helper.set_wml_var_metatable]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_child|helper.get_child]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_nth_child|helper.get_nth_child]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Variables#helper.child_count|helper.child_count]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Variables#helper.child_range|helper.child_range]]&lt;br /&gt;
* [[LuaWML:Variables#helper.child_array|helper.child_array]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_array|helper.get_variable_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_proxy_array|helper.get_variable_proxy_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.set_variable_array|helper.set_variable_array]]&lt;br /&gt;
&lt;br /&gt;
=== Events and WML actions ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire|wesnoth.fire]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.wml_actions|wesnoth.wml_actions]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.wml_actions|wesnoth.wml_conditionals]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Events#wesnoth.game_events|wesnoth.game_events]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.persistent_tags|wesnoth.persistent_tags]] {{DevFeature1.13|12}}&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire_event|wesnoth.fire_event]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire_event_by_id|wesnoth.fire_event_by_id]] {{DevFeature1.13|6}}&lt;br /&gt;
* [[LuaWML:Events#wesnoth.add_event_handler|wesnoth.add_event_handler]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Events#wesnoth.remove_event_handler|wesnoth.remove_event_handler]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Events#wesnoth.eval_conditional|wesnoth.eval_conditional]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.tovconfig|wesnoth.tovconfig]]&lt;br /&gt;
* [[LuaWML:Events#helper.set_wml_action_metatable|helper.set_wml_action_metatable]]&lt;br /&gt;
* [[LuaWML:Events#helper.wml_error|helper.wml_error]]&lt;br /&gt;
* [[LuaWML:Events#helper.literal|helper.literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.parsed|helper.parsed]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_literal|helper.shallow_literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_parsed|helper.shallow_parsed]]&lt;br /&gt;
* [[LuaWML:Events#on_event.lua|on_event.on_event]] {{DevFeature1.13|6}}&lt;br /&gt;
&lt;br /&gt;
=== User interface ===&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_viewing_side|wesnoth.get_viewing_side]] {{DevFeature1.13|?}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.message|wesnoth.message]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.clear_messages|wesnoth.clear_messages]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.textdomain|wesnoth.textdomain]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.delay|wesnoth.delay]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.float_label|wesnoth.float_label]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_unit|wesnoth.select_hex]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_unit|wesnoth.select_unit]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.highlight_hex|wesnoth.highlight_hex]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.deselect_hex|wesnoth.deselect_hex]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.scroll_to_tile|wesnoth.scroll_to_tile]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.lock_view|wesnoth.lock_view]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.view_locked|wesnoth.view_locked]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.play_sound|wesnoth.play_sound]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_music|wesnoth.set_music]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.music_list|wesnoth.music_list]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.sound_volume|wesnoth.sound_volume]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_message_dialog|wesnoth.show_message_dialog]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_popup_dialog|wesnoth.show_popup_dialog]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_story|wesnoth.show_story]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_message_box|wesnoth.show_message_box]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_menu|wesnoth.show_menu]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_message_box|wesnoth.alert]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_message_box|wesnoth.confirm]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_dialog|wesnoth.show_dialog]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_value|wesnoth.set_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_dialog_value|wesnoth.get_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_active|wesnoth.set_dialog_active]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_callback|wesnoth.set_dialog_callback]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_markup|wesnoth.set_dialog_markup]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_focus|wesnoth.set_dialog_focus]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_visible|wesnoth.set_dialog_visible]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_canvas|wesnoth.set_dialog_canvas]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.add_dialog_tree_node|wesnoth.add_dialog_tree_node]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.remove_dialog_item|wesnoth.remove_dialog_item]] {{DevFeature1.13|1}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_displayed_unit|wesnoth.get_displayed_unit]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.theme_items|wesnoth.theme_items]]&lt;br /&gt;
* [[LuaWML:Display#helper.get_user_choice|helper.get_user_choice]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.is_skipping_messages|wesnoth.is_skipping_messages]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.skip_messages|wesnoth.skip_messages]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.log|wesnoth.log]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.zoom|wesnoth.zoom]] {{DevFeature1.13|8}}&lt;br /&gt;
&lt;br /&gt;
=== Map and terrains ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_map_size|wesnoth.get_map_size]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain|wesnoth.get_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.set_terrain|wesnoth.set_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain_info|wesnoth.get_terrain_info]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_selected_tile|wesnoth.get_selected_tile]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_locations|wesnoth.get_locations]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_villages|wesnoth.get_villages]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.match_location|wesnoth.match_location]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_tile_overlay|wesnoth.add_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_tile_overlay|wesnoth.remove_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_fog|wesnoth.add_fog]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_fog|wesnoth.remove_fog]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_sound_source|wesnoth.add_sound_source]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_sound_source|wesnoth.remove_sound_source]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_sound_source|wesnoth.get_sound_source]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.map.get_direction|wesnoth.map.get_direction]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.map.get_relative_dir|wesnoth.map.get_relative_dir]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.map.rotate_right_around_center|wesnoth.map.rotate_right_around_center]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.map.get_adjacent_tiles|wesnoth.map.get_adjacent_tiles]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.map.tiles_adjacent|wesnoth.map.tiles_adjacent]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.map.distance_between|wesnoth.map.distance_between]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.label|wesnoth.label]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.special_locations|wesnoth.special_locations]] {{DevFeature1.13|12}}&lt;br /&gt;
* [[LuaWML:Tiles#items.place_image|items.place_image]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_halo|items.place_halo]]&lt;br /&gt;
* [[LuaWML:Tiles#items.remove|items.remove]]&lt;br /&gt;
&lt;br /&gt;
=== Time of day schedule ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Time#wesnoth.get_time_of_day|wesnoth.get_time_of_day]]&lt;br /&gt;
* [[LuaWML:Time#wesnoth.add_time_area|wesnoth.add_time_area]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Time#wesnoth.remove_time_area|wesnoth.remove_time_area]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Time#wesnoth.get_max_liminal_bonus|wesnoth.get_max_liminal_bonus]] {{DevFeature1.15|4}}&lt;br /&gt;
&lt;br /&gt;
=== Units ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_units|wesnoth.get_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit|wesnoth.get_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.match_unit|wesnoth.match_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_unit|wesnoth.put_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.erase_unit|wesnoth.erase_unit]] {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_recall_units|wesnoth.get_recall_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_recall_unit|wesnoth.put_recall_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.create_unit|wesnoth.create_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.copy_unit|wesnoth.copy_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.extract_unit|wesnoth.extract_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_modification|wesnoth.add_modification]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.remove_modifications|wesnoth.remove_modifications]] {{DevFeature1.13|?}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_resistance|wesnoth.unit_resistance]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_defense|wesnoth.unit_defense]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_movement_cost|wesnoth.unit_movement_cost]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_vision_cost|wesnoth.unit_vision_cost]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_jamming_cost|wesnoth.unit_jamming_cost]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_ability|wesnoth.unit_ability]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_types|wesnoth.unit_types]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.races|wesnoth.races]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_traits|wesnoth.get_traits]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.advance_unit|wesnoth.advance_unit]] {{DevFeature1.13|?}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_known_unit|wesnoth.add_known_unit]] {{DevFeature1.13|?}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.simulate_combat|wesnoth.simulate_combat]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.transform_unit|wesnoth.transform_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.create_animator|wesnoth.create_animator]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.effects|wesnoth.effects]] {{DevFeature1.13|2}}&lt;br /&gt;
&lt;br /&gt;
=== Sides ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.sides|wesnoth.sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_sides|wesnoth.get_sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_village_owner|wesnoth.get_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.set_village_owner|wesnoth.set_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.is_enemy|wesnoth.is_enemy]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.match_side|wesnoth.match_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_starting_location|wesnoth.get_starting_location]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.set_side_id|wesnoth.set_side_id]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.place_shroud|wesnoth.place_shroud]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.remove_shroud|wesnoth.remove_shroud]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.is_fogged|wesnoth.is_fogged]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.is_shrouded|wesnoth.is_shrouded]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.switch_ai|wesnoth.switch_ai]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.append_ai|wesnoth.append_ai]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.add_ai_component|wesnoth.add_ai_component]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.change_ai_component|wesnoth.change_ai_component]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.delete_ai_component|wesnoth.delete_ai_component]] {{DevFeature1.13|7}}&lt;br /&gt;
* [[LuaWML:Sides#helper.all_teams|helper.all_teams]]&lt;br /&gt;
* [[LuaWML:Sides#helper.get_side_variable|helper.get_side_variable]] {{DevFeature1.13|?}}&lt;br /&gt;
* [[LuaWML:Sides#helper.set_side_variable|helper.set_side_variable]] {{DevFeature1.13|?}}&lt;br /&gt;
&lt;br /&gt;
=== Pathfinder ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_path|wesnoth.find_path]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_vacant_tile|wesnoth.find_vacant_tile]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_reach|wesnoth.find_reach]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_cost_map|wesnoth.find_cost_map]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.distance_between|helper.distance_between]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.adjacent_tiles|helper.adjacent_tiles]]&lt;br /&gt;
&lt;br /&gt;
=== Lua files ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Files#wesnoth.dofile|wesnoth.dofile]]&lt;br /&gt;
* [[LuaWML:Files#wesnoth.require|wesnoth.require]]&lt;br /&gt;
* [[LuaWML:Files#wesnoth.have_file|wesnoth.have_file]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Files#wesnoth.read_file|wesnoth.read_file]] {{DevFeature1.13|5}}&lt;br /&gt;
&lt;br /&gt;
=== Location sets ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Location_set#location_set.create|location_set.create]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_pairs|location_set.of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_wml_var|location_set.of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:empty|location_set:empty]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:size|location_set:size]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:clear|location_set:clear]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:get|location_set:get]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:insert|location_set:insert]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:remove|location_set:remove]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_pairs|location_set:of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_wml_var|location_set:of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_pairs|location_set:to_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_stable_pairs|location_set:to_stable_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_wml_var|location_set:to_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union|location_set:union]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter|location_set:inter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:iter|location_set:iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:stable_iter|location_set:stable_iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:filter|location_set:filter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union_merge|location_set:union_merge]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter_merge|location_set:inter_merge]]&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.game_config|wesnoth.game_config]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_era|wesnoth.get_era]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.current|wesnoth.current]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.synchronize_choice|wesnoth.synchronize_choice]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.synchronize_choices|wesnoth.synchronize_choices]] {{DevFeature1.13|?}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.unsynced|wesnoth.unsynced]] {{DevFeature1.13|?}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_image_size|wesnoth.get_image_size]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compare_versions|wesnoth.compare_versions]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.have_file|wesnoth.have_file]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.debug|wesnoth.debug]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_time_stamp|wesnoth.get_time_stamp]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.random|wesnoth.random]]  {{DevFeature1.13|2}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.eval_formula|wesnoth.eval_formula]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compile_formula|wesnoth.compile_formula]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.name_generator|wesnoth.name_generator]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.set_next_scenario|wesnoth.set_next_scenario]] {{DevFeature1.13|5}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.format|wesnoth.format]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.format_conjunct_list|wesnoth.format_conjunct_list]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.format_disjunct_list|wesnoth.format_disjunct_list]] {{DevFeature1.13|8}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.wesnoth.end_turn|wesnoth.end_turn]] {{DevFeature1.13|?}}&lt;br /&gt;
* [[LuaWML:Misc#wml.tag|wml.tag]]&lt;br /&gt;
* [[LuaWML:Misc#helper.modify_unit|helper.modify_unit]]&lt;br /&gt;
* [[LuaWML:Misc#helper.move_unit_fake|helper.move_unit_fake]]&lt;br /&gt;
* [[LuaWML:Misc#helper.rand|helper.rand]]&lt;br /&gt;
* [[LuaWML:Misc#helper.round|helper.round]]&lt;br /&gt;
* [[LuaWML:Misc#helper.shuffle|helper.shuffle]]&lt;br /&gt;
&lt;br /&gt;
=== Functions that should not be used ===&lt;br /&gt;
&lt;br /&gt;
If you take a look at Wesnoth's own lua files, you might find some undocumented functions use in the implementations of WML tags. Where possible, you should avoid using them, as they might be changed or removed with no compatibility for further releases. Instead, use the corresponding wml tags (in lua you can use &amp;lt;tt&amp;gt;wesnoth.wml_actions.tag_name(cfg)&amp;lt;/tt&amp;gt;, though keep in mind that this won't substitute variables in the config).&lt;br /&gt;
&lt;br /&gt;
If uncertain whether an undocumented feature is safe to use, ask on the forums, Discord, or IRC. It may turn out that someone simply forgot to add it to the wiki.&lt;br /&gt;
&lt;br /&gt;
* wesnoth.redraw&lt;br /&gt;
* wesnoth.set_menu_item&lt;br /&gt;
* wesnoth.clear_menu_item&lt;br /&gt;
* wesnoth.modify_ai&lt;br /&gt;
* wesnoth.print&lt;br /&gt;
* wesnoth.end_level&lt;br /&gt;
&lt;br /&gt;
== Encoding WML objects into Lua tables ==&lt;br /&gt;
&lt;br /&gt;
Function [[LuaWML:Events#wesnoth.fire|wesnoth.fire]] expects a table representing a WML object as its second argument (if needed). Function [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]] allows to modify whole WML objects, again by passing it a table. Function [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]] transforms a WML object into a table, if its second argument is not set to ''true''. All these tables have the same format.&lt;br /&gt;
&lt;br /&gt;
Scalar fields are transformed into WML attributes. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    a_bool = true,&lt;br /&gt;
    an_int = 42,&lt;br /&gt;
    a_float = 1.25,&lt;br /&gt;
    a_string = &amp;quot;scout&amp;quot;,&lt;br /&gt;
    a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
[dummy]&lt;br /&gt;
    a_bool = &amp;quot;yes&amp;quot;&lt;br /&gt;
    an_int = 42&lt;br /&gt;
    a_float = 1.25&lt;br /&gt;
    a_string = &amp;quot;scout&amp;quot;&lt;br /&gt;
    a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
[/dummy]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
WML child objects are not stored as Lua named fields, since several of them can have the same tag. Moreover, their tags can conflict with the attribute keys. So child objects are stored as pairs string + table in the unnamed fields in definition order. This means that for every subtag appearing in the wml code there is an additional table &amp;quot;layer&amp;quot; in the corresponding WML table of the form &amp;lt;code&amp;gt;{[1] = &amp;quot;tag_name&amp;quot;, [2] = {}}&amp;lt;/code&amp;gt; which is equivalent to &amp;lt;code&amp;gt;{&amp;quot;tag_name&amp;quot;, {}}&amp;lt;/code&amp;gt;. [1] etc are the unnamed fields (as opposed to wml attributes). The table under [2] in this subtable then holds the wml attributes from inside the wml subtag. So every subtag other than the toplevel tag corresponds to two nested tables each. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    foo = 42,&lt;br /&gt;
    { &amp;quot;bar&amp;quot;, { v = 1, w = 2 } },&lt;br /&gt;
    { &amp;quot;foo&amp;quot;, { x = false } },&lt;br /&gt;
    { &amp;quot;bar&amp;quot;, { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
    { &amp;quot;foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } } }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
[dummy]&lt;br /&gt;
    foo = 42&lt;br /&gt;
    [bar]&lt;br /&gt;
        v = 1&lt;br /&gt;
        w = 2&lt;br /&gt;
    [/bar]&lt;br /&gt;
    [foo]&lt;br /&gt;
        x = no&lt;br /&gt;
    [/foo]&lt;br /&gt;
    [bar]&lt;br /&gt;
        y = foo&lt;br /&gt;
    [bar]&lt;br /&gt;
    [foobar]&lt;br /&gt;
        z = 5&lt;br /&gt;
        [barfoo]&lt;br /&gt;
        [/barfoo]&lt;br /&gt;
    [/foobar]&lt;br /&gt;
[/dummy]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both tables above are also equivalent to this WML table, where all unnamed fields are displayed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    foo = 42,&lt;br /&gt;
    [1] = { [1] = &amp;quot;bar&amp;quot;, [2] = { v = 1, w = 2 } },&lt;br /&gt;
    [2] = { [1] = &amp;quot;foo&amp;quot;, [2] = { x = false } },&lt;br /&gt;
    [3] = { [1] = &amp;quot;bar&amp;quot;, [2] = { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
    [4] = { [1] = &amp;quot;foobar&amp;quot;, [2] = { z = 5, [1] = { [1] = &amp;quot;barfoo&amp;quot;, [2] = {} } } }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So assuming ''cfg'' contains the above WML object, the following accesses are possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=lua&amp;gt;&lt;br /&gt;
a_int = cfg.foo        -- &amp;quot;dummy.foo&amp;quot;, 42&lt;br /&gt;
a_string = cfg[3][2].y -- &amp;quot;dummy.bar[1].y&amp;quot;, &amp;quot;foo&amp;quot;&lt;br /&gt;
a_table = cfg[4][2]    -- &amp;quot;dummy.foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For creating valid wml table in lua it is usully easier to use ''T = helper.set_wml_tag_metatable {}'' asuming you did that you can create the above wml document with&lt;br /&gt;
&amp;lt;syntaxhighlight lang=lua&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    foo = 42,&lt;br /&gt;
    T.bar {&lt;br /&gt;
         v = 1,&lt;br /&gt;
         w = 1,&lt;br /&gt;
    },&lt;br /&gt;
    T.foo {&lt;br /&gt;
        x = false,&lt;br /&gt;
    },&lt;br /&gt;
    T.bar {&lt;br /&gt;
         y = &amp;quot;foo&amp;quot;,&lt;br /&gt;
    },&lt;br /&gt;
    T.foobar {&lt;br /&gt;
         z = 5,&lt;br /&gt;
         T.barfoo {&lt;br /&gt;
         },&lt;br /&gt;
    },&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Consider using the [[LuaAPI/wml#wml.get_child|wml.get_child]] and [[LuaAPI/wml#wml.child_range|wml.child_range]] helper functions to ease the access to subtags.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|5}} As a convenience, attributes with array values (tables with only integer keys) are concatenated into a string when converting a Lua table into WML. For example, the following Lua code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=lua&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    x = {1, 2, 3, 4},&lt;br /&gt;
    y = {7, 8, 9, 10}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
produces the following WML table:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=wml&amp;gt;&lt;br /&gt;
[dummy]&lt;br /&gt;
    x=1,2,3,4&lt;br /&gt;
    y=7,8,9,10&lt;br /&gt;
[/dummy]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Functions registered in [[LuaWML:Events#wesnoth.wml_actions|wesnoth.wml_actions]] and other similar tables that provide hooks that the engine calls will receive their data either in lua tables encoding a WML object or as a [[LuaAPI/wml#wml.tovconfig|WML vconfig userdata]], which has the same structure but is read-only. Accessing fields or children on a vconfig performs variable substitution on the fly. Its '''__parsed''' and '''__literal''' fields provide translations to plain, writable tables. '''__literal''' returns the original text of the data (including dollar symbols in attributes and '''[insert_tag]''' children), while '''__parsed''' performs a full variable substitution.&lt;br /&gt;
&lt;br /&gt;
For instance, if you cannot stand any longer the fact that '''first_time_only''' is set to yes by default for the '''[event]''' tag, you can redefine it. But we have to be careful not to cause variable substitution, since the engine would perform a second variable substitution afterwards.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=lua&amp;gt;&lt;br /&gt;
local old_event_handler = wesnoth.wml_actions.event&lt;br /&gt;
function wesnoth.wml_actions.event(cfg)&lt;br /&gt;
    -- Get the plain text from the user.&lt;br /&gt;
    local new_cfg = helper.literal(cfg)&lt;br /&gt;
    -- The expression below is equivalent to cfg.__parsed.first_time_only,&lt;br /&gt;
    -- only faster. It is needed, since the first_time_only attribute may&lt;br /&gt;
    -- reference variables.&lt;br /&gt;
    local first = cfg.first_time_only&lt;br /&gt;
    -- Modify the default behavior of first_time_only.&lt;br /&gt;
    if first == nil then first = false end&lt;br /&gt;
    new_cfg.first_time_only = first&lt;br /&gt;
    -- Call the engine handler.&lt;br /&gt;
    old_event_handler(new_cfg)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Note: The above example will only affect nested events. Toplevel events will still default to ''first_time_only=yes''.)&lt;br /&gt;
(Note2: You should not do that since it will break other addons that rely on the first_time_only=no default value.)&lt;br /&gt;
&amp;lt;!-- This should probably be replaced with a better example. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''pairs''' and '''ipairs''' also work on vconfig objects (contrary to the above statement). However, '''pairs''' works a little differently than on plain configs (tables) - it returns only string keys (attributes in WML terms) and not integer keys (tags in WML terms).&lt;br /&gt;
&lt;br /&gt;
Another approach for handling userdata and tables in the same way, would be to convert the former into the latter beforehand. The [[LuaAPI/wml#wml.parsed|wml.parsed]] and [[LuaAPI/wml#wml.literal|wml.literal]] helpers take care of this for you.&lt;br /&gt;
&lt;br /&gt;
The vconfig userdata provides two other special fields: '''__shallow_parsed''' and '''__shallow_literal'''. They return a table corresponding to the WML userdata with variable substitution performed on the attributes (or not). [insert_tag] tags have also been parsed, so the number of children is faithful. But contrarily to '''__parsed''' and '''__literal''', the process is not recursive: all the children are still WML userdata and variable substitution can still happen for them. These shallow translators are meant as optimized versions of the deep ones, when only the toplevel attributes need to be writable.&lt;br /&gt;
&lt;br /&gt;
== Skeleton of a lua tag ==&lt;br /&gt;
&lt;br /&gt;
The following [lua] tag is a skeleton for a prelude enabling Lua in your WML events. It creates a table ''H'' containing the functions from helper.lua . It sets up a table ''T'' so be used for easier creation of valid WML tables. It also sets up a table ''V'' so that any access to it is redirected to the persistent WML storage. Finally, it loads a textdomain to be accessed through the ''_'' variable. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
[scenario]&lt;br /&gt;
    [lua]&lt;br /&gt;
        code = &amp;lt;&amp;lt;&lt;br /&gt;
            H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
            T = wml.tag&lt;br /&gt;
            V = wml.variables&lt;br /&gt;
            local _ = wesnoth.textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            -- Define your global constants here.&lt;br /&gt;
            -- ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
            -- Define your global functions here.&lt;br /&gt;
            -- ...&lt;br /&gt;
        &amp;gt;&amp;gt;&lt;br /&gt;
    [/lua]&lt;br /&gt;
    ... &lt;br /&gt;
[/scenario]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It may be worth putting the whole Lua script above inside a separate file and having the [lua] tag load it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='wml'&amp;gt;&lt;br /&gt;
[scenario]&lt;br /&gt;
    [lua]&lt;br /&gt;
        code = &amp;lt;&amp;lt; wesnoth.dofile &amp;quot;~add-ons/Whatever/file.lua&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
    [/lua]&lt;br /&gt;
    ...&lt;br /&gt;
[/scenario]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remarks on Random Numbers ==&lt;br /&gt;
&lt;br /&gt;
The math.random function is not safe for replays and multiplayer games, since the random values will be different each time and on all the clients. Instead, the Lua code should use the [[LuaWML:Misc#wesnoth.random|wesnoth.random]] function to synchronize random values. It has the same interface as math.random but is multiplayer-safe.&lt;br /&gt;
&lt;br /&gt;
Also available is [[LuaWML:Misc#helper.rand|helper.rand()]], which takes the same argument in the same format as [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] rand=.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
 local random_variable = helper.rand(&amp;quot;1,2,3&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Random Lua table iteration ==&lt;br /&gt;
&lt;br /&gt;
Table iteration order ('''pairs''') is not strictly defined in Lua. If your code depends on the order of iteration, different clients may have different data in a multiplayer game. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
  local table = { [&amp;quot;Mage&amp;quot;] = true, [&amp;quot;Wose&amp;quot;] = true }&lt;br /&gt;
  local concat = &amp;quot;&amp;quot;&lt;br /&gt;
  local bad_usage = next(table) -- wrong, leads to OOS&lt;br /&gt;
  for k, _ in pairs(table) do -- wrong, leads to OOS&lt;br /&gt;
    concat = concat .. k&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To avoid the problem, sort the table keys before iterating. Or alternatively, use Lua &amp;quot;arrays&amp;quot; and the '''ipairs''' function, which have a strictly defined order and never lead to OOS. Example of correct code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang='lua'&amp;gt;&lt;br /&gt;
  local array = { &amp;quot;Mage&amp;quot;, &amp;quot;Wose&amp;quot; }&lt;br /&gt;
  local good_usage = table[1] -- correct&lt;br /&gt;
  local concat = &amp;quot;&amp;quot;&lt;br /&gt;
  for _, v in ipairs(array) do -- correct&lt;br /&gt;
    concat = concat .. v&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference|*]]&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Time&amp;diff=65688</id>
		<title>LuaWML/Time</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Time&amp;diff=65688"/>
		<updated>2020-06-16T15:07:50Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[LuaWML]] functions revolving around Time of Day schedule functionality, including time areas.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_time_of_day ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_time_of_day([''for_turn''], [ {''x'', ''y'', [''consider_illuminates'']} ])'''&lt;br /&gt;
&lt;br /&gt;
Returns schedule information. First parameter (optional) is the turn number for which to return the information, if unspecified: the current turn ($turn_number). Second argument is an optional table. If present, first and second fields must be valid on-map coordinates and all current time_areas in the scenario are taken into account (if a time area happens to contain the passed hex). If the table isn't present, the scenario main schedule is returned. The table has an optional third parameter (boolean). If true (default: false), time of day modifying units and terrain (such as Mages of Light or lava) are taken into account (if the passed hex happens to be affected). The units' placement being considered is always the current one.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.get_time_of_day(2, { 37, 3, true })&lt;br /&gt;
&lt;br /&gt;
The function returns a table with these named fields:&lt;br /&gt;
* '''id''': string (as in [time])&lt;br /&gt;
* '''lawful_bonus''': integer (as in [time])&lt;br /&gt;
* '''bonus_modified''': integer (bonus change by units)&lt;br /&gt;
* '''image''': string (tod image in sidebar)&lt;br /&gt;
* '''name''': translatable string&lt;br /&gt;
* '''red, green, blue''': integers (color adjustment for this time)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.add_time_area ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.add_time_area(''cfg'')'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Creates a new time area. This takes a WML table containing the same information normally used by the [[DirectActionsWML#.5Btime_area.5D|[time_area]]] tag.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|2}} Since 1.13.2, commas in the id attribute of the WML table are no longer handled specially for this function, allowing the creation of time areas with commas in their ids (but why would anyone want to do that, really).&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.remove_time_area ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.remove_time_area(''id'')'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Removes a time area. This requires the time area to have been assigned an id at creation time.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|2}} Since 1.13.2, commas in the id are no longer handled specially for this function, requiring you to use a loop to remove multiple time areas instead.&lt;br /&gt;
&lt;br /&gt;
 for i, id in ipairs({'foo', 'bar', 'baz'}) do&lt;br /&gt;
     wesnoth.remove_time_area(id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_max_liminal_bonus ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_max_liminal_bonus()'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.15|4}} Returns the maximum attack bonus that liminal units can get in the current scenario.&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=Maintenance_tools&amp;diff=59983</id>
		<title>Maintenance tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=Maintenance_tools&amp;diff=59983"/>
		<updated>2018-10-12T18:57:10Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* GUI.pyw */ Updated description&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;floatright&amp;quot;&amp;gt; __TOC__ &amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Wesnoth source code distribution includes a couple of tools intended to help authors maintain campaigns, faction &amp;amp; unit packs, and other WML resources. These&lt;br /&gt;
are:&lt;br /&gt;
 &lt;br /&gt;
; wmlscope: a cross-reference lister, useful for finding unresolved macro and resource-file references.&lt;br /&gt;
&lt;br /&gt;
; wmllint: a utility for sanity-checking WML syntax and porting your old WML to the current version of WML.  &lt;br /&gt;
&lt;br /&gt;
; wmlindent: a utility for reindenting WML to a uniform style.&lt;br /&gt;
&lt;br /&gt;
; GUI.pyw: a graphical interface&lt;br /&gt;
&lt;br /&gt;
== General Information ==&lt;br /&gt;
&lt;br /&gt;
You will need a Python 3 interpreter on your system to use these tools.  Linux, *BSD, and Mac OS/X should already have Python 3 installed; for Windows it's a free download&lt;br /&gt;
from http://www.python.org.  You will also need to know how to run command-line tools on your system.&lt;br /&gt;
&lt;br /&gt;
If you're working with ubuntu you might have to install the package wesnoth-1.10-tools (or the convenient version).&lt;br /&gt;
 sudo apt-get install wesnoth-1.10-tools&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All three tools will require you to supply a &amp;lt;i&amp;gt;directory list&amp;lt;/i&amp;gt;.  This is a set of directories containing the WML files you want to work on.&lt;br /&gt;
&lt;br /&gt;
This page is intended as ducementation for users.  A developer's-eye discussion of the design constraints on these tools, and their limitations, can be found here [https://mail.gna.org/public/wesnoth-dev/2010-02/msg00078.html].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Note to Windows Users:&amp;lt;/u&amp;gt; This means you have to run it from the '''Command Line'''. The command line may be reached by hitting Start, then Run, then &amp;quot;cmd&amp;quot; or &amp;quot;command&amp;quot; depending on your version of Windows.&lt;br /&gt;
&lt;br /&gt;
Example uses:&lt;br /&gt;
 python wmllint path\to\files&lt;br /&gt;
 python wmlindent path\to\files&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
 &amp;quot;C:\Program Files\Python3.6\python.exe&amp;quot; data\tools\wmllint --dryrun data\core data\{multiplayer,themes} data\campaigns &lt;br /&gt;
(You have to specify the full directory path to the executable if you don't have your environment variables set up correctly).&lt;br /&gt;
The first thing you type is the path to your python executable, followed by a space. The second thing you type is the path to the desired script to run, followed by a space. The third thing you type is the path to the folder (or file) to be processed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''A convenient way of running wmllint''' on Linux (Debian Lenny) and Windows (Xp) in comparison, '''Linux''':&lt;br /&gt;
&lt;br /&gt;
Assuming we're working with wesnoth 1.9 or more advanced versions (1.10 in this case).&lt;br /&gt;
 python3 /usr/share/games/wesnoth/1.10/data/tools/wmllint --dryrun /usr/share/games/wesnoth/1.10/data/core ~/.local/share/wesnoth/1.10/data/add-ons/A_Simple_Campaign 1&amp;gt;wmllint-run.log 2&amp;gt;wmllint-err.log&lt;br /&gt;
I have these commands inside of a file named&lt;br /&gt;
 wmllint_dryrun_ASC.sh&lt;br /&gt;
and execute it by opening a shell (=terminal, console, command window, bash,...), navigating into the directory with that file and typing&lt;br /&gt;
 bash wmllint_dryrun_ASC.sh&lt;br /&gt;
The python3 command should be automatically known on Debian. The path to the script tells the python interpreter what to execute. --dryrun: A wmllint option, see below. The path to the core files is needed to let wmllint know about e.g. defined core units, followed by the path to the add-on that shall be checked; the last two commands cause the result of the wmllint usage to be written into those files in the same directory as the script.&lt;br /&gt;
'''Windows''', this is logically exactly the same as the Linux shell script above, so if you are on a Mac you can probably conclude how you need to adapt the paths:&lt;br /&gt;
 E:\Python34\python.exe E:\Programme\Wesnoth_1.8_svn\data\tools\wmllint --dryrun E:\Programme\Wesnoth_1.8_svn\data\core E:\Programme\Wesnoth_1.8_svn\userdata\data\add-ons\A_Simple_Campaign 1&amp;gt;wmllint-run.log 2&amp;gt;wmllint-err.log&lt;br /&gt;
This is the content of a .txt file, whose extension I rename to .bat and double-click onto it. Opening a command window is not needed this way.&lt;br /&gt;
Since python isn't natively installed on windows and I don't have environment variables set, the full path to python.exe is given. If your directories contain spaces it may help to include the path in quotes:&lt;br /&gt;
 &amp;quot;C:\Programs\Battle for Wesnoth 1.8\data\tools\wmllint&amp;quot;&lt;br /&gt;
Remember that you do not need to enter all of the commands/paths at once. If it doesn't work, start with only &amp;quot;python&amp;quot; or &amp;quot;C:\Python34\python.exe&amp;quot; or the like and interpret the error messages that you get. If you get an &amp;quot;unknown command&amp;quot;, python isn't installed or environment variables aren't set correctly. After that, you can add the later commands one by one.&lt;br /&gt;
&lt;br /&gt;
== wmlscope ==&lt;br /&gt;
&lt;br /&gt;
The main use for &amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; is to find WML macro references without definitions and references to resource files (sounds and images) that don't exist.  These are difficult to spot from in-game because they usually result in silence or a missing image rather than actual broken game logic.  They may happen because of typos in your WML, or because the name of a macro or the location of a resource file changed between versions of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; also checks macro invocations for consistency.  It will complain&lt;br /&gt;
if a macro is called with the wrong number of arguments.  In most cases it can deduce information about the type of the literal expected to be passed to a given macro argument by looking at the name of the formal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table class=&amp;quot;wikitable&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Meanining&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Formals requiring this type&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Literals of this type&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;side&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a single side number&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;SIDE, *_SIDE, SIDE[0-9]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric or &amp;quot;global&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;numeric&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric integer literal&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;SIDE, X, Y, RED, GREEN, BLUE, TURN, PROB, LAYER, TIME, *_SIDE, *NUMBER, *AMOUNT, *COST, *RADIUS, *_X, *_Y, *_INCREMENT, *_FACTOR, *_TIME, *_SIZE, DURATION&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;\-?[0-9]+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;percentage&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a percentage&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*PERCENTAGE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric or 0\.[0-9]+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;position&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a single x,y coordinate&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;POSITION, *_POSITION, BASE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;-?[0-9]+,-?[0-9]+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;span&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of coordinates or coordinate ranges&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*_SPAN&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric, position or ([0-9]+\-[0-9]+,?|[0-9]+,?)+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;alliance&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of side numbers&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;SIDES, *_SIDES&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a span, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;range&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;an attack range&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;RANGE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;quot;melee&amp;quot; or &amp;quot;ranged&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;alignment&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;an alignment keyword&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;ALIGN&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;quot;lawful&amp;quot; or &amp;quot;neutral&amp;quot; or &amp;quot;chaotic&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;types&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of unit types&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;TYPES&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname, name, or anything that contains spaces and matches no other type&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;terrain_pattern&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of terrain codes to filter&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;ADJACENT*, TERRAINLIST*, *TERRAIN_PATTERN, RESTRICTING&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a terrain_code or name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;terrain_code&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a single terrain code, perhaps with overlay&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;TERRAIN*, *TERRAIN&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname or (\*|[A-Z][a-z]+)\^([A-Z][a-z\\|/]+\Z)?&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;shortname&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a terrain code or a short, capitalized variable name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[A-Z][a-z][a-z]?&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a name or identifier&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;NAME, VAR, IMAGESTEM, ID, FLAG, *_NAME, *_ID, NAMESPACE, BUILDER, *_VAR&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;anything without spaces that matches no other type&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;optional_string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a string value (may be empty)&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;ID_STRING, NAME_STRING, DESCRIPTION, IPF&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a string, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a nonempty string not matching any of the preceding types&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;STRING, TYPE, TEXT, *_STRING, *_TYPE, *_TEXT&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname, a name, a stringliteral, or anything that contains spaces and matches no other type&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;stringliteral&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a string in doublequotes or a translated string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;quot;.*&amp;quot; or _.* but not _[a-z].*&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;image&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;an image path, perhaps with [[ImagePathFunctionWML|image path functions]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*IMAGE, PROFILE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[A-Za-z0-9{}.][A-Za-z0-9_/+{}.-]*\.(png|jpg)(?=(~.*)?)&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;sound&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a music or sound filename&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;MUSIC, SOUND&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;string ending with &amp;quot;.wav&amp;quot; or &amp;quot;.ogg&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;filter&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[FilterWML|WML filter]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;FILTER&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;any non-quoted string containing &amp;quot;=&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;WML&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;arbitrary WML fragment&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;WML, *_WML&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;any non-quoted string containing &amp;quot;=&amp;quot;, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;affix&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a prefix, suffix, or infix for a variable name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;AFFIX, *AFFIX, POSTFIX, ROTATION&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname or name, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;any&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;anything&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*VALUE, [ARS][0-9]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;anything&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the actual argument is a macro call {.*}, then it matches any formal  Otherwise, if the formal has an identifiable type, &amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; will complain if the actual literal does not match it.&lt;br /&gt;
&lt;br /&gt;
The argument type check only works in macro calls that fit on a single line.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; has many options for changing the reports it generates; the more advanced ones are intended for Wesnoth developers.  Invocations for the most commonly useful reports it generates are included in &amp;lt;i&amp;gt;data/tools/Makefile&amp;lt;/i&amp;gt; of the source distribution. Here are some of those reports:&lt;br /&gt;
&lt;br /&gt;
; make unresolved: Report on unresolved macro calls and resource references; also report macro argument-type mismatches.  (This is what you are most likely to want to do). &lt;br /&gt;
&lt;br /&gt;
; make all: Report all macro and resource file references, not just unresolved ones.&lt;br /&gt;
&lt;br /&gt;
; make collisions: Report on duplicate resource files.&lt;br /&gt;
&lt;br /&gt;
For more advanced users, or those who want to understand what the canned Makefile invocations are doing, here is a summary of &amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt;'s options. Some of the more advanced options will require you to understand &lt;br /&gt;
[http://docs.python.org/lib/re-syntax.html Python regular expressions].&lt;br /&gt;
&lt;br /&gt;
; -h, --help:                 Emit a help message and quit&lt;br /&gt;
; -c, --crossreference:       Report resolved macro references (implies -w 1)&lt;br /&gt;
; -C, --collisions:           Report duplicate resource files   &lt;br /&gt;
; -d, --deflist:              Make definition list.  (This one is for campaign server maintainers.)&lt;br /&gt;
; -e &amp;lt;i&amp;gt;regexp&amp;lt;/i&amp;gt;, --exclude &amp;lt;i&amp;gt;regexp&amp;lt;/i&amp;gt;:   Ignore files matching the specified regular expression. &lt;br /&gt;
; -f &amp;lt;i&amp;gt;dir&amp;lt;/i&amp;gt;, --from &amp;lt;i&amp;gt;dir&amp;lt;/i&amp;gt;:         Report only on macros defined under &amp;lt;i&amp;gt;dir&amp;lt;/i&amp;gt;&lt;br /&gt;
; -l, --listfiles:            List files that will be processed&lt;br /&gt;
; -r &amp;lt;i&amp;gt;ddd&amp;lt;/i&amp;gt;, --refcount=&amp;lt;i&amp;gt;ddd&amp;lt;/i&amp;gt;:     Report only on macros with references in exactly &amp;lt;i&amp;gt;ddd&amp;lt;/i&amp;gt; files.&lt;br /&gt;
; -u, --unresolved:           Report unresolved macro references&lt;br /&gt;
; -w, --warnlevel:            Set to 1 to warn of duplicate macro definitions&lt;br /&gt;
; --force-used reg:          Ignore reference count 0 on names matching regexp&lt;br /&gt;
; --extracthelp:              Extract help from macro definition comments.&lt;br /&gt;
&lt;br /&gt;
== wmllint ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; is a tool for migrating your WML to the current version.  It handles two problems: &lt;br /&gt;
&lt;br /&gt;
* Resource files and macro names may change between versions of the game. &amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; knows about these changes and will tweak your WML to fit where it can.&lt;br /&gt;
&lt;br /&gt;
* Between 1.2.x and 1.3.1 the terrain-coding system used in map files underwent a major change. It changed again in a minor way between 1.3.1 and 1.3.2.  &amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; will translate your maps for you, unless you use custom terrains in which case you will have to do it by hand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; also performs various sanity-checking operations, reporting:&lt;br /&gt;
&lt;br /&gt;
* unbalanced tags&lt;br /&gt;
* strings that need a translation mark and do not have them&lt;br /&gt;
* strings that have a translation mark and should not&lt;br /&gt;
* translatable strings containing macro references &lt;br /&gt;
* filter references by description= (id= in 1.5) not matched by an actual unit&lt;br /&gt;
* abilities or traits without matching special notes, or vice-versa&lt;br /&gt;
* consistency between recruit= and recruitment_pattern= instances&lt;br /&gt;
* double space after punctuation in translatable strings.&lt;br /&gt;
* unknown races or movement types in units&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; takes a directory-path argument specifying the WML directories to work on.  It will modify any cfg and map files under those directories that need to be changed.  Here is a summary of its options:&lt;br /&gt;
&lt;br /&gt;
; -h, --help:                 Emit a help message and quit.&lt;br /&gt;
; -d, --dryrun:               List changes but don't perform them.&lt;br /&gt;
; -v, --verbose:              Set verbosity; more details below.&lt;br /&gt;
; -c, --clean:                Clean up -bak files.&lt;br /&gt;
; -D, --diff:                 Show diffs between unconverted and unconverted files.&lt;br /&gt;
; -r, --revert:               Revert the conversion from the -bak files.&lt;br /&gt;
; -n, --nolift:               Suppress lifting, do sanity checks only &lt;br /&gt;
&lt;br /&gt;
The verbosity option works like this:&lt;br /&gt;
&lt;br /&gt;
; -v:          lists changes.&lt;br /&gt;
; -v -v:       warns of maps already converted.&lt;br /&gt;
; -v -v -v:    names each file before it's processed.&lt;br /&gt;
; -v -v -v -v: shows verbose parse details (developers only).&lt;br /&gt;
&lt;br /&gt;
The recommended procedure is this:&lt;br /&gt;
&lt;br /&gt;
# Run it with --dryrun first to see what it will do.&lt;br /&gt;
# If the messages look good, run without --dryrun; the old content will be left in backup files with a -bak extension.&lt;br /&gt;
# Eyeball the changes with the --diff option.&lt;br /&gt;
# Use wmlscope, with a directory path including the Wesnoth mainline WML, to check that you have no unresolved references.&lt;br /&gt;
# Test the conversion.&lt;br /&gt;
# Use either --clean to remove the -bak files or --revert to undo the conversion.&lt;br /&gt;
&lt;br /&gt;
Additionally, wmllint tries to locate a spell checker on your system and spell-checks storyline and message strings.  It will work automatically with either aspell, myspell, or ispell provided you have the &amp;lt;tt&amp;gt;enchant.py&amp;lt;/tt&amp;gt; Python library installed.&lt;br /&gt;
&lt;br /&gt;
== wmlindent ==&lt;br /&gt;
&lt;br /&gt;
Call with no arguments to filter WML on standard input to reindented WML on&lt;br /&gt;
standard output.  If arguments are specified, they are taken to be files to be&lt;br /&gt;
re-indented in place; interrupting will be safe, as each reindenting&lt;br /&gt;
will be done to a copy that is atomically renamed when it's done. This&lt;br /&gt;
code never modifies anything but blank lines and leading and trailing whitespace on non-blank lines.&lt;br /&gt;
&lt;br /&gt;
The indent unit is four spaces.  Absence of an option to change this is&lt;br /&gt;
deliberate; the purpose of this tool is to prevent style wars, not encourage&lt;br /&gt;
them.&lt;br /&gt;
&lt;br /&gt;
If you don't apply this tool to your own WML, the mainline-campaign maintainers &lt;br /&gt;
will do it when and if your code is accepted into the tree.&lt;br /&gt;
&lt;br /&gt;
Note: This tool does not include a parser.  It will produce bad results on WML&lt;br /&gt;
that is syntactically unbalanced.  Unbalanced double quotes that aren't part&lt;br /&gt;
of a multiline literal will also confuse it.  You will receive warnings&lt;br /&gt;
if there's an indent open at end of file or if a closer occurs with&lt;br /&gt;
indent already zero; these two conditions strongly suggest unbalanced WML.&lt;br /&gt;
&lt;br /&gt;
== GUI.pyw ==&lt;br /&gt;
&lt;br /&gt;
Starting from version 1.11.15 and 1.13.0, a GUI (written in Tkinter, plus the themed widgets ttk) is available in the same directory as the other tools. To use it, you need to have a version of Python equal to or greater than 3.1.0 (the 3.0.x series doesn't include the ttk widgets, and as such is unsuitable for this script).&lt;br /&gt;
&lt;br /&gt;
If you're on Linux, be sure to have installed the ''python3-tk'' module, '''or the application won't run at all'''. To install it in a Debian-based distro (like Ubuntu), type this line in a Terminal:&lt;br /&gt;
 sudo apt install python3-tk&lt;br /&gt;
&lt;br /&gt;
To start it, just double click on the GUI.pyw file. The interface is pretty much self-explanatory, and allows you to run wmllint, wmlscope, wmlindent and wmlxgettext, modify their options, select an add-on and save the tools' output as a text file.&lt;br /&gt;
&lt;br /&gt;
[[Category:Create]]&lt;br /&gt;
[[Category:Tools]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Misc&amp;diff=56729</id>
		<title>LuaWML/Misc</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Misc&amp;diff=56729"/>
		<updated>2015-08-31T08:40:16Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* wesnoth.random */ Added DevFeature; math.rand -&amp;gt; math.random&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes miscellaneous [[LuaWML]] objects and helpers.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.game_config ====&lt;br /&gt;
&lt;br /&gt;
Contrarily to the other values of the ''wesnoth'' table, ''game_config'' is simply a proxy table. Its fields offer an interface to the global settings of Wesnoth:&lt;br /&gt;
&lt;br /&gt;
* '''version''': string (read only)&lt;br /&gt;
* '''base_income''': integer (read/write)&lt;br /&gt;
* '''village_income''': integer (read/write)&lt;br /&gt;
* '''poison_amount''': integer (read/write)&lt;br /&gt;
* '''rest_heal_amount''': integer (read/write)&lt;br /&gt;
* '''recall_cost''': integer (read/write)&lt;br /&gt;
* '''kill_experience''': integer (read/write)&lt;br /&gt;
* '''last_turn''': integer (read/write) turn limit, maximum number of turns&lt;br /&gt;
* '''debug''': boolean (read only)&lt;br /&gt;
* '''mp_debug''': boolean (read only)&lt;br /&gt;
* '''campaign_type''': string (read only) Indicates what type of game this is, e.g. &amp;quot;multiplayer&amp;quot;&lt;br /&gt;
* '''mp_settings''': table. In a multiplayer game, this is a proxy table which gives read only access to all MP-only configuration options which appear as attributes of [multiplayer] tag in a save game file:&lt;br /&gt;
** '''active_mods''': string (read only) A list of all active modifications&lt;br /&gt;
** '''hash''': string (read only) A hash of mp data&lt;br /&gt;
** '''mp_campaign''': string (read only) Name of mp campaign&lt;br /&gt;
** '''mp_scenario''': string (read only) ID of this mp scenario&lt;br /&gt;
** '''mp_scenario_name''': string (read only) Name of this mp scenario&lt;br /&gt;
** '''scenario''': string (read only) MP lobby title &lt;br /&gt;
** '''difficulty_define''': string (read only) The campaign difficulty string for an mp campaign&lt;br /&gt;
** '''mp_village_gold''': integer (read only) &lt;br /&gt;
** '''mp_village_support''': integer (read only) &lt;br /&gt;
** '''mp_num_turns''': integer (read only) &lt;br /&gt;
** '''mp_era''': string (read only) The id of the chosen era&lt;br /&gt;
** '''mp_eras''': string (read only) A list of all era ids&lt;br /&gt;
** '''mp_fog''': boolean (read only) &lt;br /&gt;
** '''mp_shroud''': boolean (read only) &lt;br /&gt;
** '''mp_random_start_time''': boolean (read only) &lt;br /&gt;
** '''experience_modifier''': integer (read only) &lt;br /&gt;
** '''mp_use_map_settings''': boolean (read only) &lt;br /&gt;
** '''mp_countdown''': boolean (read only) Whether the timer is enabled&lt;br /&gt;
** '''mp_countdown_action_bonus''': integer (read only) &lt;br /&gt;
** '''mp_countdown_init_time''': integer (read only) &lt;br /&gt;
** '''mp_countdown_reservoir_time''': integer (read only)  &lt;br /&gt;
** '''mp_countdown_turn_bonus''': integer (read only)  &lt;br /&gt;
** '''observer''': boolean (read only) &lt;br /&gt;
** '''shuffle_sides''': boolean (read only) &lt;br /&gt;
** '''savegame''': boolean (read only) Whether this is a reloaded game&lt;br /&gt;
** '''side_users''': string (read only) List of how sides are assigned to users (at game start)&lt;br /&gt;
* '''era''': table. A proxy table for the entire era tag corresponding to the current era. Its id will always match wesnoth.game_config.mp_settings.mp_era&lt;br /&gt;
Note: wesnoth.game_config.mp_settings, and wesnoth.game_config.era, will only exist if wesnoth.game_config.campaign_type == &amp;quot;multiplayer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 -- Poison a bit weak? Let's boost it!&lt;br /&gt;
 wesnoth.game_config.poison_amount = 15&lt;br /&gt;
&lt;br /&gt;
 -- Warn users when they use bad settings:&lt;br /&gt;
 if (wesnoth.game_config.mp_settings.shuffle_sides) then&lt;br /&gt;
    wesnoth.message(&amp;quot;Warning: This scenario is not intended to be played with shuffle sides!&amp;quot;)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 -- Collect basic info about the current era:&lt;br /&gt;
 local era = wesnoth.game_config.era&lt;br /&gt;
 local helper = wesnoth.require(&amp;quot;lua/helper.lua&amp;quot;)&lt;br /&gt;
 local count = 0&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;era_name&amp;quot;, era.name)&lt;br /&gt;
 for multiplayer_side in helper.child_range(era, &amp;quot;multiplayer_side&amp;quot;) do&lt;br /&gt;
     count = count + 1&lt;br /&gt;
     wesnoth.set_variable(&amp;quot;faction&amp;quot; .. tostring(count) .. &amp;quot;_name&amp;quot;, multiplayer_side.name)&lt;br /&gt;
     wesnoth.set_variable(&amp;quot;faction&amp;quot; .. tostring(count) .. &amp;quot;_recruit&amp;quot;, multiplayer_side.recruit)&lt;br /&gt;
 end&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;num_factions&amp;quot;, count)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_era ====&lt;br /&gt;
A function which takes one argument, an era id, and returns the entire era tag corresponding to that id. For a list of valid era ids, use wesnoth.game_config.mp_settings.mp_eras.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.current ====&lt;br /&gt;
&lt;br /&gt;
As with ''game_config'', ''current'' is a proxy table. Its fields are getter for game-related properties:&lt;br /&gt;
&lt;br /&gt;
* '''side''': integer (read only)&lt;br /&gt;
* '''turn''': integer (read only)&lt;br /&gt;
* '''event_context''': WML table with attributes ''name'', ''x1'', ''y1'', ''x2'', ''y2'', and children ''weapon'', ''second_weapon'', describing the trigger for the current event. {{DevFeature1.13|2}} ''unit_x'', ''unit_y'' contain the location of the primary unit involved in the event. Currently the only case where this cam be different from ''x1'' and ''y1'' are enter_hex and exit_hex events.&lt;br /&gt;
* '''synced_state''' {{DevFeature1.13|0}} whether the current code runs in a synced contex, this returns a string, the possible values are:&lt;br /&gt;
** '''synced''' the current code runs on all mp clients, this is the normal context, in which all gamestatechaning actions should take place.&lt;br /&gt;
** '''unsynced''' for example during '''select''' events or during the calculation of a  wesnoth.theme_items, don't change the gamestate in this context because the current code only runs on one machine, so changign the gamestate here will cause OOS. Typical things to do here are UI related things, or entering the synced state via '''[do_command]'''&lt;br /&gt;
** '''local_choice''' the current code was invoked by wesnoth.synchronize_choice and runs only on one local client to calculate the return value for wesnoth.synchronize_choice. You cannot enter the synced context with '''[do_command]''' now.&lt;br /&gt;
** '''preload''' we are currently running a preload event or an even earlier event, this behaves similar to '''local_choice'''&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Turn %d, side %d is playing.&amp;quot;, wesnoth.current.turn, wesnoth.current.side))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.synchronize_choice ====&lt;br /&gt;
&lt;br /&gt;
Recovers a WML table that was computed on one client only or was stored in a replay. The actual computation is performed by the function passed as the first argument, assuming that the client is the side currently playing. For all the other clients, the function will not be called. An optional second function can be passed; if present, it will be used instead of the first one when the client happens to be an AI (hence not enable to interact with a user interface).&lt;br /&gt;
&lt;br /&gt;
 local result = wesnoth.synchronize_choice(&lt;br /&gt;
   function()&lt;br /&gt;
     -- Called only on the client handling the current side, if it is a human.&lt;br /&gt;
     local choice = 0&lt;br /&gt;
     wesnoth.show_dialog(&lt;br /&gt;
       some_dialog_cfg, nil,&lt;br /&gt;
       function()&lt;br /&gt;
         choice = wesnoth.get_dialog_value &amp;quot;some_list&amp;quot;&lt;br /&gt;
       end)&lt;br /&gt;
     return { value = choice }&lt;br /&gt;
   end,&lt;br /&gt;
   function()&lt;br /&gt;
     -- Called only on the client handling the current side, if it is an AI.&lt;br /&gt;
     return { value = math.random(some_list_size) }&lt;br /&gt;
   end)&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Selected item: %d&amp;quot;, result.value))&lt;br /&gt;
&lt;br /&gt;
Note: The return value must be a valid WML table - the same kind of thing you could store to a WML variable, and not, for instance, a proxy unit, anything else that uses metatables, or a lua table with another table as the value of a string attribute. Unlike other lua functions, wesnoth.synchronize_choice will NOT throw an error if the table is invalid, but will silently strip out the contents of any invalid subtag.&lt;br /&gt;
&lt;br /&gt;
When wesnoth is running in debug mode (e.g. --debug flag on command line) synchronize_choice will chat a &amp;quot;Lua Warning&amp;quot; if it finds that the table returned was partially invalid.&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}} This function now accepts a third (array) argument which allows to decide on which sides the action is executed. If a third argument is passed this function also returns table. If mutiple sides are passed in a mp game, the function wil be executed simultaneously so one side don't have to wait unti the other side decides. Example:&lt;br /&gt;
 [event]&lt;br /&gt;
   name = &amp;quot;start&amp;quot;&lt;br /&gt;
   [lua]&lt;br /&gt;
   code = &amp;lt;&amp;lt;&lt;br /&gt;
     wesnoth.set_variable(&amp;quot;input1&amp;quot;,nil)&lt;br /&gt;
     local result = wesnoth.synchronize_choice(&lt;br /&gt;
     function()&lt;br /&gt;
       local option1 = T.option { message = &amp;quot;No&amp;quot;, T.command { T.set_variable { name = &amp;quot;input1&amp;quot;, value = &amp;quot;No&amp;quot;}}}&lt;br /&gt;
       local option2 = T.option { message = &amp;quot;Yes&amp;quot;, T.command { T.set_variable { name = &amp;quot;input1&amp;quot;, value = &amp;quot;Yes&amp;quot;}}}&lt;br /&gt;
       wesnoth.fire(T.message{ message =  &amp;quot;Are you sure you want to play this game?&amp;quot;, option1, option2})&lt;br /&gt;
       return { value = wesnoth.get_variable(&amp;quot;input1&amp;quot;) }&lt;br /&gt;
     end,&lt;br /&gt;
     function()&lt;br /&gt;
       return { value = math.random(30) }&lt;br /&gt;
     end, {1,2})&lt;br /&gt;
     wesnoth.set_variable(&amp;quot;input1&amp;quot;,nil)&lt;br /&gt;
     wesnoth.message(&amp;quot;Player 1 wants to play: &amp;quot; .. result[1].value)&lt;br /&gt;
     wesnoth.message(&amp;quot;Player 2 wants to play: &amp;quot; .. result[2].value)&lt;br /&gt;
   &amp;gt;&amp;gt;&lt;br /&gt;
   [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
if a third parameter is passed and the side is a null controlled side, an empty config will be returned for this side.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_image_size ====&lt;br /&gt;
&lt;br /&gt;
Returns the width and height of an image.&lt;br /&gt;
&lt;br /&gt;
 local w, h = wesnoth.get_image_size &amp;quot;units/transport/galleon.png&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.compare_versions ====&lt;br /&gt;
&lt;br /&gt;
Takes two versions strings and an operator, returns whether the comparison yields true.&lt;br /&gt;
Follows the same rules like the #ifver preprocessor statement.&lt;br /&gt;
&lt;br /&gt;
 local function version_is_sufficient(required)&lt;br /&gt;
  if not wesnoth.compare_versions then return false end&lt;br /&gt;
  return wesnoth.compare_versions(wesnoth.game_config.version, &amp;quot;&amp;gt;=&amp;quot;, required)&lt;br /&gt;
 end&lt;br /&gt;
 local required = &amp;quot;1.9.6&amp;quot;&lt;br /&gt;
 if not version_is_sufficient(required) then wesnoth.message(string.format(&lt;br /&gt;
  &amp;quot;Your BfW version is insufficient, please get BfW %s or greater!&amp;quot;, required)) end&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.have_file ====&lt;br /&gt;
&lt;br /&gt;
Checks if the file (not necessarily a Lua file) or the directory passed as argument exists. Returns true if the file exists, false otherwise. Follows the same rules like the #ifhave preprocessor statement.&lt;br /&gt;
&lt;br /&gt;
 -- Does the user have installed the UMC Music Book 1?&lt;br /&gt;
 local umc_music = wesnoth.have_file( &amp;quot;~add-ons/UMC_Music_Book_1/_main.cfg&amp;quot; )&lt;br /&gt;
 -- and if we want to check for the folder?&lt;br /&gt;
 local music_folder = wesnoth.have_file( &amp;quot;~add-ons/UMC_Music_Book_1/&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.debug ====&lt;br /&gt;
&lt;br /&gt;
Takes a userdata with metatable wml object or a wml table and dumps its content into a pretty string.&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;number&amp;quot;, 100)&lt;br /&gt;
 local vconfig = wesnoth.tovconfig({ key = &amp;quot;$number&amp;quot;, another_key = true,&lt;br /&gt;
     {&amp;quot;a_subtag&amp;quot;, { a_key_in_the_subtag = &amp;quot;foo&amp;quot; }}&lt;br /&gt;
 })&lt;br /&gt;
 wesnoth.message(wesnoth.debug(vconfig))&lt;br /&gt;
 wesnoth.message(wesnoth.debug(vconfig.__literal))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_time_stamp ====&lt;br /&gt;
&lt;br /&gt;
This function retrieves the current time stamp, that is the amount of milliseconds passed from when the SDL library was initialized. It takes no arguments and returns an integer.&lt;br /&gt;
'''WARNING:''' this function uses the same code as [set_variable] time=stamp, and so it is MP-unsafe. It is provided only for benchmark purposes and AI development, although it should work inside wesnoth.synchronize_choice() as well.&lt;br /&gt;
 local stamp = wesnoth.get_time_stamp()&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.random ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|2}} This function returns a random number generated by the synced random generator which is also used by [set_variable]rand= (and thus also by helper.rand). This function has the same interface as math.random so it can take 0, 1 or 2 arguments.&lt;br /&gt;
&lt;br /&gt;
==== helper.set_wml_tag_metatable ====&lt;br /&gt;
&lt;br /&gt;
Sets the metable of a table so that it can be used to create subtags with less brackets. Returns the table. The fields of the table are simple wrappers around table constructors.&lt;br /&gt;
&lt;br /&gt;
 T = helper.set_wml_tag_metatable {}&lt;br /&gt;
 W.event { name = &amp;quot;new turn&amp;quot;, T.message { speaker = &amp;quot;narrator&amp;quot;, message = &amp;quot;?&amp;quot; } }&lt;br /&gt;
&lt;br /&gt;
==== helper.modify_unit ====&lt;br /&gt;
&lt;br /&gt;
Modifies all the units satisfying the given filter (argument 1) with some WML attributes/objects (argument 2). This is a Lua implementation of the [http://www.wesnoth.org/macro-reference.xhtml MODIFY_UNIT] macro.&lt;br /&gt;
&lt;br /&gt;
 helper.modify_unit({ id=&amp;quot;Delfador&amp;quot; }, { moves=0 })&lt;br /&gt;
&lt;br /&gt;
==== helper.move_unit_fake ====&lt;br /&gt;
&lt;br /&gt;
Fakes the move of a unit satisfying the given filter (argument 1) to the given position (argument 2). This is a Lua implementation of the [http://www.wesnoth.org/macro-reference.xhtml MOVE_UNIT] macro.&lt;br /&gt;
&lt;br /&gt;
 helper.move_unit_fake({ id=&amp;quot;Delfador&amp;quot; }, 14, 8)&lt;br /&gt;
&lt;br /&gt;
==== helper.rand ====&lt;br /&gt;
&lt;br /&gt;
(A shortcut to set_variable's rand= since math.rand is an OOS magnet and therefore disabled.) Pass a string like you would to set_variable's rand=.&lt;br /&gt;
&lt;br /&gt;
create a random unit at (1, 1) on side=1 :&lt;br /&gt;
 wesnoth.put_unit(1, 1, { type = helper.rand(&amp;quot;Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Scout&amp;quot;) })&lt;br /&gt;
&lt;br /&gt;
==== helper.round ====&lt;br /&gt;
&lt;br /&gt;
Unlike other languages (Python, Perl, Javascript, ...), Lua does not include a round function. This helper function allows rounding numbers, following the &amp;quot;round half away from zero method&amp;quot;, see Wikipedia [[http://en.wikipedia.org/wiki/Rounding_numbers#Round_half_away_from_zero]]. Returns the number rounded to the nearest integer.&lt;br /&gt;
&lt;br /&gt;
 -- this number will be rounded up&lt;br /&gt;
 helper.round(345.67) -- returns 346&lt;br /&gt;
 -- this one will be rounded down&lt;br /&gt;
 helper.round(543.21) -- returns 543&lt;br /&gt;
 -- an integer stays integer&lt;br /&gt;
 helper.round(123) -- returns 123&lt;br /&gt;
 -- works also for negative numbers&lt;br /&gt;
 helper.round(-369.84) -- returns -370&lt;br /&gt;
 helper.round(-246.42) -- returns -246&lt;br /&gt;
&lt;br /&gt;
==== helper.shuffle ====&lt;br /&gt;
&lt;br /&gt;
This function randomly sorts in place the elements of the table passed as argument, following the Fisher-Yates algorithm. It returns no value.&lt;br /&gt;
'''WARNING:''' this function uses Lua's math.random(), and so it is '''not''' MP-safe. It is provided mainly for AI development, although it should work inside wesnoth.synchronize_choice() as well.&lt;br /&gt;
&lt;br /&gt;
 local locs = wesnoth.get_locations( { terrain=&amp;quot;G*&amp;quot; } )&lt;br /&gt;
 helper.shuffle( locs )&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
This function now uses the synced RNG by default and should not cause OOS anymore. It is also possible now to pass a different random generator as a second argument; a random generator is a function that takes two integers &amp;lt;i&amp;gt;a&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;b&amp;lt;/i&amp;gt; and returns a random integer in the range [&amp;lt;i&amp;gt;a&amp;lt;/i&amp;gt;,&amp;lt;i&amp;gt;b&amp;lt;/i&amp;gt;]. For example, math.random can be passed to get the 1.12 behavior:&lt;br /&gt;
&lt;br /&gt;
 local locs = wesnoth.get_locations( { terrain=&amp;quot;G*&amp;quot; } )&lt;br /&gt;
 helper.shuffle( locs, math.random )&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=CampaignWML&amp;diff=56652</id>
		<title>CampaignWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=CampaignWML&amp;diff=56652"/>
		<updated>2015-08-09T09:11:07Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* The [campaign] Tag */ Documented ENABLE_NIGHTBLADE&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&lt;br /&gt;
Dacyn and/or Invisible Philosopher -- please be careful&lt;br /&gt;
you don't reduce the signal-to-noise ratio on the WML pages&lt;br /&gt;
when editing!  Eg. knowing that a tag is translatable is _important_&lt;br /&gt;
for the 29 translations we have in progress. -- ott&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This page describes how the campaign is displayed in the &amp;quot;Campaign&amp;quot; menu, and how it starts.&lt;br /&gt;
&lt;br /&gt;
==The [campaign] Tag==&lt;br /&gt;
&lt;br /&gt;
The following keys and tags are recognized in '''[campaign]''' tags:&lt;br /&gt;
* '''id''': the internal campaign identifier used to classify saved games&lt;br /&gt;
* '''icon''': the image displayed in the campaign selection menu&lt;br /&gt;
* '''name''': (translatable) name displayed in the campaign selection menu&lt;br /&gt;
* '''abbrev''': (translatable) abbreviation used as a prefix for savefile names made from this campaign&lt;br /&gt;
* '''image''': the image shown in the information pane when this campaign is selected in the campaign selection menu (typically a transparent, 350×350 pixels portrait)&lt;br /&gt;
* '''description''': (translatable) text shown in the information pane when this campaign is selected in the campaign selection menu&lt;br /&gt;
* '''type''': campaign's type to specify if it should be visible in singleplayer, multiplayer or both. Possible values are &amp;quot;sp&amp;quot;, &amp;quot;mp&amp;quot; and &amp;quot;hybrid&amp;quot;. Defaults to &amp;quot;sp&amp;quot;.&lt;br /&gt;
* '''define'''='''''CAMPAIGN_SYMBOL''''' when this campaign is started, the preprocessor symbol '''''CAMPAIGN_SYMBOL''''' will be defined. See '''#ifdef''' in [[PreprocessorRef]] for how this can be used to isolate parts of the campaign file from other campaigns. Only the tags '''[campaign]''' and '''[binary_path]''' (see [[BinaryPathWML]]) should go outside of '''#ifdef ''CAMPAIGN_SYMBOL'''''. This symbol will be defined ''before'' any .cfg is preprocessed. Important note: starting with 1.7.13, [binary_path] does no longer need to be outside of the '''#ifdef ''CAMPAIGN_SYMBOL''''' block to make custom binary data available, which could easily cause overwrites. E.g. icon=data/add-ons/whatever/something.png is supposed to work. This seems to have been a bug since at least BfW 1.0 which means that practically all available examples of user made add-ons are wrong in this aspect.&lt;br /&gt;
* '''extra_defines''': a comma(''',''') separated list of preprocessor symbols. Those symbols will be defined ''before'' any .cfg is preprocessed. Currently supported extra_defines are:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
;ENABLE_ARMAGEDDON_DRAKE&lt;br /&gt;
:allows the advancement ''Inferno Drake'' -&amp;gt; ''Armageddon Drake''&lt;br /&gt;
;ENABLE_DWARVISH_ARCANISTER&lt;br /&gt;
:allows the advancement ''Dwarvish Runemaster'' -&amp;gt; ''Dwarvish Arcanister''&lt;br /&gt;
;ENABLE_DWARVISH_RUNESMITH&lt;br /&gt;
:allows the advancement ''Dwarvish Fighter'' -&amp;gt; ''Dwarvish Runesmith''&lt;br /&gt;
;DISABLE_GRAND_MARSHAL&lt;br /&gt;
:disallows the advancement ''General'' -&amp;gt; ''Grand Marshal''&lt;br /&gt;
;ENABLE_ANCIENT_LICH&lt;br /&gt;
:allows the advancement ''Lich'' -&amp;gt; ''Ancient Lich''&lt;br /&gt;
;ENABLE_DEATH_KNIGHT&lt;br /&gt;
:allows the advancement ''Revenant'' -&amp;gt; ''Death Knight'&lt;br /&gt;
;ENABLE_TROLL_SHAMAN&lt;br /&gt;
:allows the advancement ''Troll Whelp'' -&amp;gt; ''Troll Shaman''&lt;br /&gt;
;ENABLE_WOLF_ADVANCEMENT&lt;br /&gt;
:allows the advancements ''Wolf'' -&amp;gt; ''Great Wolf'' -&amp;gt; ''Direwolf''&lt;br /&gt;
;ENABLE_NIGHTBLADE {{DevFeature1.13|0}}&lt;br /&gt;
:allows the advancement ''Orcish Slayer'' -&amp;gt; ''Orcish Nightblade''&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
* '''difficulties''': a comma(''',''') separated list of preprocessor symbols, exactly one of which will be stored depending on the difficulty setting chosen when the campaign is started. The symbols '''EASY''', '''NORMAL''', and '''HARD''' are usually used, and there are several macros in utils.cfg (see [http://www.wesnoth.org/macro-reference.xhtml#file:utils.cfg| Macro Reference]) which check for these values to set WML keys to different values depending on difficulty.  If you use different difficulty symbols, you may need to define your own versions of these macros.&lt;br /&gt;
* '''difficulty_descriptions''': the menu of difficulties; this is a list of descriptions (see [[DescriptionWML]]) that correspond to different difficulty levels. Since each description is a menu option for a difficulty level, this must provide the same number of descriptions as there are levels in the ''difficulties'' list.&lt;br /&gt;
* '''allow_difficulty_change''': Allows difficulty switching during an ongoing campaign. Default:yes&lt;br /&gt;
* '''first_scenario''': the ID of the first scenario in the campaign; see ''id'' in [[ScenarioWML]]&lt;br /&gt;
* '''rank''': a number that determines the order of campaigns in the campaign selection menu.  Lower ''rank'' campaigns appear earlier, with unranked campaigns at the end. Currently the mainline campaigns use multiples of 10 from 0 to 399, with 0-99 for Novice campaigns, 100-199 for Intermediate campaigns, and 200-399 for Expert campaigns; if you specify this, it should not be less than 400.  (Note: This replaces an older convention that topped out at 50.)&lt;br /&gt;
* '''[about]''': inserts your own credits into the game's list of credits. See below for syntax.&lt;br /&gt;
* '''end_credits''': Whether to display the credits screen at the end of the campaign. Defaults to ''yes''.&lt;br /&gt;
* '''end_text''': (translatable) Text that is shown centered in a black screen at the end of a campaign. Defaults to &amp;quot;The End&amp;quot;.&lt;br /&gt;
* '''end_text_duration''': Delay, in milliseconds, before displaying the game credits at the end of a campaign. In other words, for how much time '''end_text''' is displayed on screen. Defaults to 3500.&lt;br /&gt;
&lt;br /&gt;
The following keys are additionally recognized in multiplayer:&lt;br /&gt;
* '''min_players''': Minimum number of players campaign supports. Defaults to 2.&lt;br /&gt;
* '''max_players''': Maximum number of players campaign supports. Defaults to '''min_players'''.&lt;br /&gt;
* '''allow_era_choice''': Whether to hide era selection and use a default one when creating a game. Defaults to ''yes''.&lt;br /&gt;
* '''require_campaign''': Whether clients are required to have this campaign installed beforehand to be allowed join a game using this campaign. Possible values 'yes' (the default) and 'no'.&lt;br /&gt;
&lt;br /&gt;
== Campaign credits ==&lt;br /&gt;
&lt;br /&gt;
The campaign's name automatically is inserted at the top of the rolling credits followed by title/text key pairs.  There can be any number of '''[about]''' tags inside a '''[campaign]''' tag, but none of them will display credits if there is no &amp;quot;id&amp;quot; key present inside [campaign] (see above). The '''[about]''' tag has the following keys:&lt;br /&gt;
* '''title''': (translatable) large text used to start a new subsection (writers, artists, units, balancing) in the rolling credits&lt;br /&gt;
* '''text''': (translatable, but you probably won't want to make it such) smaller text which is displayed before the contributor names&lt;br /&gt;
* '''[entry]''': Contains information about a single contributor. Only the ''name'' key will be used in-game, the other three keys are for display on the [[Credits]] page ('''note:''' the values of these keys will only display on the Credits page for mainline campaigns; they will not display for UMC campaigns)&lt;br /&gt;
** '''name''': The name of the contributor&lt;br /&gt;
** '''comment''': Optional short note about what that person did&lt;br /&gt;
** '''email''': Optional email address&lt;br /&gt;
** '''wikiuser''': Optional, the user name on the wiki&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[PreprocessorRef]]&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
* [[PblWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Units&amp;diff=56488</id>
		<title>LuaWML/Units</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Units&amp;diff=56488"/>
		<updated>2015-07-18T19:37:02Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added unit.level (read only)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions for handling units.&lt;br /&gt;
&lt;br /&gt;
A unit is a proxy table with the following fields:&lt;br /&gt;
* '''x''', '''y''': integers (read only, read/write if the unit is not on the map)&lt;br /&gt;
* '''side''': integer (read/write)&lt;br /&gt;
* '''id''': string (read only)&lt;br /&gt;
* '''type''': string (read only)&lt;br /&gt;
* '''name''': translatable string (read only)&lt;br /&gt;
* '''max_hitpoints''', '''experience''', '''max_experience''', '''max_moves''': integers (read only)&lt;br /&gt;
* '''max_attacks''': integer (read only)&lt;br /&gt;
* '''attacks_left''': integer (read/write) Setting below 0 is limited to 0.&lt;br /&gt;
* '''extra_recruit''': table (read/write)&lt;br /&gt;
* '''advances_to''': table (read/write)&lt;br /&gt;
* '''hitpoints''', '''experience''': integer (read/write)&lt;br /&gt;
* '''moves''': integer (read/write)&lt;br /&gt;
* '''level''': {{DevFeature1.13|2}} integer (read only)&lt;br /&gt;
* '''resting''': boolean (read/write)&lt;br /&gt;
* '''hidden''': boolean (read/write)&lt;br /&gt;
* '''petrified''', '''canrecruit''': booleans (read only)&lt;br /&gt;
* '''role''', '''facing''': strings (read/write)&lt;br /&gt;
* '''status''': proxy associative table (read only, read/write fields)&lt;br /&gt;
* '''image_mods''': string (read only)&lt;br /&gt;
* '''variables''': proxy associative table (read only, read/write fields, including ''variables.__cfg''), only toplevel named fields are proxied&lt;br /&gt;
* '''attacks''': {{DevFeature1.13|0}}an object to access the units attacks, you can use the attacks index or the attacks name to index an attack. every attack has the following members:&lt;br /&gt;
** '''description''': translatable string (read/write)&lt;br /&gt;
** '''name''': string (read)&lt;br /&gt;
** '''type''': string (read/write)&lt;br /&gt;
** '''range''': string (read/write)&lt;br /&gt;
** '''damage''': number(read/write)&lt;br /&gt;
** '''number''': number(read/write)&lt;br /&gt;
** '''movement_used''': number(read/write)&lt;br /&gt;
** '''attack_weight''': number(read/write)&lt;br /&gt;
** '''defense_weight''':  number(read/write)&lt;br /&gt;
** '''specials''' wml table(read/write)&lt;br /&gt;
* '''valid''': string or nil (read only)&lt;br /&gt;
* '''advancements''': {{DevFeature1.13|2}} an array of wml tables (read/write)&lt;br /&gt;
* '''__cfg''': WML table (dump)&lt;br /&gt;
The metatable of these proxy tables appears as '''&amp;quot;unit&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
A unit can be either visible on the map ([[#wesnoth.get_units]], [[#wesnoth.put_unit]]), or on a recall list ([[#wesnoth.get_recall_units]], [[#wesnoth.put_recall_unit]]), or private to the Lua code ([[#wesnoth.create_unit]], [[#wesnoth.copy_unit]], [[#wesnoth.extract_unit]]). The Lua code has complete control over the private units; they will not be modified unless accessed through the proxy unit. Units on the map and on the recall lists, however, can be modified by the user, the engine, WML, independently of the Lua code. In particular, if a unit is killed, any further use of the proxy unit will cause an error. For units on the map, the proxy unit is valid as long as there is a unit on the map that has the same &amp;quot;underlying_id&amp;quot; WML field as the original one. The behavior is similar for units on the recall lists. The ''valid'' field reflects the unit availability by returning '''&amp;quot;map&amp;quot;''', '''&amp;quot;recall&amp;quot;''', '''&amp;quot;private&amp;quot;''', or ''nil''. The latter value is used for units that were removed (e.g. killed). In that case, the ''valid'' field is the only one that can be read without causing an error.&lt;br /&gt;
&lt;br /&gt;
The term &amp;quot;proxy&amp;quot;, here in particular &amp;quot;proxy unit&amp;quot;, means that the variable retrieved in the lua code (with get_units for example) is an accessor (reference) to the C++ object which represents that unit. This is very different from unit variables obtained by [store_unit] in wml. The fields marked as &amp;quot;writable&amp;quot; above can be modified without the need to use put_unit afterwards. This same reason explains that modifications to the unit from outside the lua code (like [kill] invalidating the proxy unit) have immediate effect on the lua code's proxy unit variable (with the exception of private proxy units).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_units ====&lt;br /&gt;
&lt;br /&gt;
Returns an array of all the units on the map matching the WML filter passed as the first argument. See [[StandardUnitFilter]] for details about filters.&lt;br /&gt;
&lt;br /&gt;
 local leaders_on_side_two = get_units { side = 2, canrecruit = true }&lt;br /&gt;
 local name_of_leader = leaders_on_side_two[1].name&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_unit ====&lt;br /&gt;
&lt;br /&gt;
Returns the unit at the given location or with the given underlying ID.&lt;br /&gt;
&lt;br /&gt;
 local args = ...&lt;br /&gt;
 local unit = wesnoth.get_unit(args.x1, args.y1)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.match_unit ====&lt;br /&gt;
&lt;br /&gt;
Returns true if the given unit matches the WML filter passed as the second argument.&lt;br /&gt;
&lt;br /&gt;
 assert(unit.canrecruit == wesnoth.match_unit(unit, { canrecruit = true }))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.put_unit ====&lt;br /&gt;
&lt;br /&gt;
Places a unit on the map. This unit is described either by a WML table or by a proxy unit. Coordinates can be passed as the first two arguments, otherwise the table is expected to have two fields '''x''' and '''y''', which indicate where the unit will be placed. If the function is called with coordinates only, the unit on the map at the given coordinates is removed instead.&lt;br /&gt;
&lt;br /&gt;
 -- create a unit with random traits, then erase it&lt;br /&gt;
 wesnoth.put_unit(17, 42, { type = &amp;quot;Elvish Lady&amp;quot; })&lt;br /&gt;
 wesnoth.put_unit(17, 42)&lt;br /&gt;
&lt;br /&gt;
When the argument is a proxy unit, no duplicate is created. In particular, if the unit was private or on a recall list, it no longer is; and if the unit was on the map, it has been moved to the new location. Note: passing a WML table is just a shortcut for calling [[#wesnoth.create_unit]] and then putting the resulting unit on the map.&lt;br /&gt;
&lt;br /&gt;
 -- move the leader back to the top-left corner&lt;br /&gt;
 wesnoth.put_unit(1, 1, wesnoth.get_units({ canrecruit = true })[1])&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_recall_units ====&lt;br /&gt;
&lt;br /&gt;
Returns an array of all the units on the recall lists matching the WML filter passed as the first argument.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.put_recall_unit ====&lt;br /&gt;
&lt;br /&gt;
Places a unit on a recall list. This unit is described either by a WML table or by a proxy unit. The side of the recall list is given by the second argument, or by the side of the unit if missing.&lt;br /&gt;
&lt;br /&gt;
 -- put the unit at location 17,42 on the recall list for side 2&lt;br /&gt;
 wesnoth.put_recall_unit(wesnoth.get_units({ x= 17, y = 42 })[1], 2)&lt;br /&gt;
&lt;br /&gt;
When the argument is a proxy unit, no duplicate is created. In particular, if the unit was private or on the map, it no longer is. Note: passing a WML table is just a shortcut for calling [[#wesnoth.create_unit]] and then putting the resulting unit on a recall list.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.create_unit ====&lt;br /&gt;
&lt;br /&gt;
Creates a private unit from a WML table.&lt;br /&gt;
&lt;br /&gt;
 local u = wesnoth.create_unit { type = &amp;quot;White Mage&amp;quot;, gender = &amp;quot;female&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.copy_unit ====&lt;br /&gt;
&lt;br /&gt;
Creates a private unit from another unit.&lt;br /&gt;
&lt;br /&gt;
 -- extract a unit from the map&lt;br /&gt;
 local u = wesnoth.copy_unit(wesnoth.get_units({ type = &amp;quot;Thug&amp;quot; })[1])&lt;br /&gt;
 wesnoth.put_unit(u.x, u.y)&lt;br /&gt;
 -- u is still valid at this point&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.extract_unit ====&lt;br /&gt;
&lt;br /&gt;
Removes a unit from the map or from a recall list and makes it private.&lt;br /&gt;
&lt;br /&gt;
 -- remove all the units from the recall list of side 1 and put them in a WML container&lt;br /&gt;
 local l = {}&lt;br /&gt;
 for i,u in ipairs(wesnoth.get_recall_units { side = 1 }) do&lt;br /&gt;
     wesnoth.extract_unit(u)&lt;br /&gt;
     table.insert(l, u.__cfg)&lt;br /&gt;
 end&lt;br /&gt;
 helper.set_variable_array(&amp;quot;player_recall_list&amp;quot;, l)&lt;br /&gt;
&lt;br /&gt;
Note: if the unit is on the map, it is just a shortcut for calling [[#wesnoth.copy_unit]] and then [[#wesnoth.put_unit]] without a unit. It is, however, the only way for removing a unit from a recall list without putting it on the map.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.advance_unit ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}} Advances the unit (and shows the advance unit dialog if needed) if the unit has enough xp. This function should be called after modifying the units experience directly. A similar function is called by wesnoth internally after unit combat. The second argument is a boodean value that specifies whether the advancement should be animated. The third agrument is a boodean value that specifies whether advancement related events should be fired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This function only works for units on the map.&lt;br /&gt;
&lt;br /&gt;
This function can also trigger multiple advancements if the unit has enough xp.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.add_modification ====&lt;br /&gt;
&lt;br /&gt;
Modifies a given unit. It needs to be a proxy unit. The second argument is the type of the modification (either trait, object, or advance). The option &amp;quot;advance&amp;quot; applies effects as if the unit would advance (e.g. AMLA effects). The third argument is a WML table describing the effect, so mostly containing '''[effect]''' children. See [[EffectWML]] for details about effects.&lt;br /&gt;
&lt;br /&gt;
 local u = wesnoth.get_units { canrecruit = true }[1]&lt;br /&gt;
 wesnoth.add_modification(u, &amp;quot;object&amp;quot;, { { &amp;quot;effect&amp;quot;, { apply_to = &amp;quot;image_mod&amp;quot;, replace = &amp;quot;RC(red&amp;gt;blue)&amp;quot; } } })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.unit_resistance ====&lt;br /&gt;
&lt;br /&gt;
Returns the resistance of a unit against an attack type. (Note: it is a WML resistance. So the higher it is, the weaker the unit is.) The third argument indicates whether the unit is the attacker. Last arguments are the coordinates of an optional map location (for the purpose of taking abilities into account).&lt;br /&gt;
&lt;br /&gt;
 local fire_resistance = 100 - wesnoth.unit_resistance(u, &amp;quot;fire&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.unit_defense ====&lt;br /&gt;
&lt;br /&gt;
Returns the defense of a unit on a particular terrain. (Note: it is a WML defense. So the higher it is, the weaker the unit is.)&lt;br /&gt;
&lt;br /&gt;
 local flat_defense = 100 - wesnoth.unit_defense(u, &amp;quot;Gt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.unit_movement_cost ====&lt;br /&gt;
&lt;br /&gt;
Returns the movement cost of a unit on a particular terrain.&lt;br /&gt;
&lt;br /&gt;
 local move_cost = wesnoth.unit_movement_cost(u, &amp;quot;Gt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.unit_ability ====&lt;br /&gt;
&lt;br /&gt;
Returns true if the unit is currently under effect by an ability with this given TAG NAME. This means that the ability could be owned by the unit itself, or by an adjacent unit.&lt;br /&gt;
&lt;br /&gt;
 function has_teleport(u)&lt;br /&gt;
     return wesnoth.unit_ability(u, &amp;quot;teleport&amp;quot;)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.unit_types ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but a table indexed by unit type ids. Its elements are proxy tables with these fields:&lt;br /&gt;
&lt;br /&gt;
* '''id''': string&lt;br /&gt;
* '''name''': translatable string (read only)&lt;br /&gt;
* '''max_moves''', '''max_experience''', '''max_hitpoints''', '''level''', '''cost''': integers (read only)&lt;br /&gt;
* '''__cfg''': WML table (dump)&lt;br /&gt;
&lt;br /&gt;
The metatable of these proxy tables appears as '''&amp;quot;unit type&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
 local lich_cost = wesnoth.unit_types[&amp;quot;Ancient Lich&amp;quot;].cost&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.races ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but a table indexed by race ids. Its elements are proxy tables for all races the engine knows about.&lt;br /&gt;
known fields of each element:&lt;br /&gt;
* '''id''': string&lt;br /&gt;
* '''description''', '''name''', '''plural_name''' (translatable strings)&lt;br /&gt;
* '''num_traits''' (integer)&lt;br /&gt;
* '''ignore_global_traits''' (boolean)&lt;br /&gt;
* '''undead_variation''' (string)&lt;br /&gt;
(all read only)&lt;br /&gt;
* '''__cfg''': WML table (dump)&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message(tostring(wesnoth.races[&amp;quot;lizard&amp;quot;].name))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_traits ====&lt;br /&gt;
&lt;br /&gt;
Returns a table with named fields (trait id strings) holding the wml tables defining the traits. arguments: none. All global traits the engine knows about, race-specific traits are not included.&lt;br /&gt;
Known fields and subtags of each element are the ones which were given in the wml definition of the [[SingleUnitWML|trait]].&lt;br /&gt;
 wesnoth.message(tostring(wesnoth.get_traits().strong.male_name))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.simulate_combat ====&lt;br /&gt;
&lt;br /&gt;
Computes the hitpoint distribution and status chance after a combat between two units.  The first unit is the attacker; it does not have to be on the map, though its location should be meaningful. The second unit is the defender; it has to be on the map.&lt;br /&gt;
&lt;br /&gt;
Optional integers can be passed after each unit to select a particular weapon, otherwise the &amp;quot;best&amp;quot; one is selected.  When giving the weapon, the parameter is the weapon number (integer, starting at 1) and not an element from the table returned by helper.child_range(att, &amp;quot;attack&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
 local function display_stats(n, t)&lt;br /&gt;
     wesnoth.message(string.format(&lt;br /&gt;
         &amp;quot;Chance for the %s\n  to be slowed: %f,\n  to be poisoned: %f,\n  to die: %f.\nAverage HP: %f.&amp;quot;,&lt;br /&gt;
         n, t.slowed, t.poisoned, t.hp_chance[0], t.average_hp))&lt;br /&gt;
 end&lt;br /&gt;
 local att_stats, def_stats = wesnoth.simulate_combat(att, att_weapon, def, def_weapon)&lt;br /&gt;
 display_stats(&amp;quot;attacker&amp;quot;, att_stats)&lt;br /&gt;
 display_stats(&amp;quot;defender&amp;quot;, def_stats)&lt;br /&gt;
&lt;br /&gt;
Returns 2 additional tables which contain information about the weapons and the effect of single hits with these keys: num_blows, damage, chance_to_hit, poisons, slows, petrifies, plagues, plague_type, backstabs, rounds, firststrike, drains, drain_constant, drain_percent, attack_num, name. &lt;br /&gt;
Name is the wml name not the description. If there is no weapon, then name will be nil&lt;br /&gt;
&lt;br /&gt;
 local att_stats, def_stats, att_weapon, def_weapon = wesnoth.simulate_combat(attacker, att_weapon_number, defender)&lt;br /&gt;
 wesnoth.message(string.format(&lt;br /&gt;
     &amp;quot;The attack %s should be countered with %s, which does %d damage, has %d%% chance to hit and forces %d attack rounds due to its berserk ability.&amp;quot;,&lt;br /&gt;
     att_weapon.name, def_weapon.name or &amp;quot;no weapon&amp;quot;, def_weapon.damage, def_weapon.chance_to_hit, def_weapon.rounds))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.transform_unit ====&lt;br /&gt;
&lt;br /&gt;
Changes the type of a unit and adjust attributes accordingly. Note that hit points are only changed if necessary to accommodate the new maximum hit points. Poison is automatically removed if the transformed unit is immune.&lt;br /&gt;
&lt;br /&gt;
 local ev = wesnoth.current.event_context&lt;br /&gt;
 local u = wesnoth.get_units{x=ev.x1, y=ev.y1}[1]&lt;br /&gt;
 wesnoth.transform_unit(u, &amp;quot;Spearman&amp;quot;)&lt;br /&gt;
 -- If a full heal is desired:&lt;br /&gt;
 u.hitpoints = u.max_hitpoints&lt;br /&gt;
 u.status.poisoned = false&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56452</id>
		<title>ImagePathFunctions</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56452"/>
		<updated>2015-06-28T13:34:34Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* Negative Function */ Added missing version notes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Image Path Functions provide a simple method for WML coders to alter the way their specified images will be displayed in the game. All of the function parameters are included at the end of an image path and should not contain any spaces or special characters (other than those specified here).&lt;br /&gt;
&lt;br /&gt;
If you need to practice it without having to reload all WML, you can use an add-on named ''Image loading tester'' from the 1.10 add-on server.&lt;br /&gt;
&lt;br /&gt;
== Team-Color Function ==&lt;br /&gt;
In Wesnoth version 1.2, the only Image Path Function was '''~TC()''', which took two comma-separated parameters: the team number and the source color palette. The valid values for both of these parameters are defined in the file ''data/team-colors.cfg''&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~TC(''' ''team number'' ''',''' ''source color palette'' ''')'''&lt;br /&gt;
*''team number'' - this is the first parameter, a number 1-9 signifying the team number of a unit. Number 1 typically means the red team, 2 typically means the blue team, and so on (unless the scenario color settings for any side have been altered).&lt;br /&gt;
*''source color palette'' - the second parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
&lt;br /&gt;
== Re-Color Function ==&lt;br /&gt;
May be used to change some colors in an image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~RC(''' ''source color palette'' '''&amp;gt;''' ''color range ID'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''color range ID'' - this is the second parameter, signifying the ID of a color range defined in the file ''data/core/team-colors.cfg'' (or it may be a custom ID for a color range defined locally).  &lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
In the following example, the magenta regions in an elvish captain's image are turned  a healthy shade of green:&lt;br /&gt;
&lt;br /&gt;
  [message]&lt;br /&gt;
      speaker=narrator&lt;br /&gt;
      image=units/elves-wood/captain.png~RC(magenta&amp;gt;green)&lt;br /&gt;
      message=_ &amp;quot;Now I am on the green team.&amp;quot;&lt;br /&gt;
  [/message]&lt;br /&gt;
&lt;br /&gt;
The IDs of the color ranges may be the lowercased English name of the palette's base color (e.g. 'red', 'brown', etc.). They may also be numeric color indices from the palette WML included with the game, but this is not recommended.&lt;br /&gt;
&lt;br /&gt;
== Palette-switch Function ==&lt;br /&gt;
May be used to change colors in an image following the specifications of a source and target (new) palette.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~PAL(''' ''source color palette'' '''&amp;gt;''' ''target color palette'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, such as magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''target color palette'' - the new palette to take the place of the source colors in the image.&lt;br /&gt;
&lt;br /&gt;
== Flip Function ==&lt;br /&gt;
May be used to flip an image horizontally and/or vertically.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~FL(''' ''optional argument list'' ''')'''&lt;br /&gt;
*''vertical'' - if the string &amp;quot;vert&amp;quot; is found anywhere in the argument list, the image will be flipped vertically.&lt;br /&gt;
*''horizontal'' - if the string &amp;quot;horiz&amp;quot; is found anywhere in the argument list, the image will be flipped horizantally.&lt;br /&gt;
*if the argument list is empty, the image will only be flipped horizontally.&lt;br /&gt;
&lt;br /&gt;
== Rotate Function ==&lt;br /&gt;
May be used to rotate an image by a multiple of 90 degrees.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~ROTATE(''' ''degrees'' ''')'''&lt;br /&gt;
* ''degrees'' - The number of degrees by which the image will be rotated. This must be a multiple of 90. Positive numbers indicate clockwise rotation, while negative numbers indicate counter-clockwise. (Zero indicates no rotation.)&lt;br /&gt;
If the number of degrees is omitted, a quarter turn (90 degrees) clockwise is assumed.&lt;br /&gt;
&lt;br /&gt;
== Greyscale Function ==&lt;br /&gt;
May be used to greyscale the image (turn to black and white)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~GS( )'''&lt;br /&gt;
&lt;br /&gt;
== Black and White Function ==&lt;br /&gt;
{{devfeature1.13|1}}&lt;br /&gt;
May be used to convert the image to pure black and white, without grey pixels. &lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BW(threshold)'''&lt;br /&gt;
* ''threshold'': a value between 0 and 255 (both limits included). All pixels are converted as greyscale first, and if their average value is greater than the threshold they become white, otherwise they become black.&lt;br /&gt;
&lt;br /&gt;
== Sepia Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
May be used to give to the image a sepia tint (like in old pictures).&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~SEPIA()'''&lt;br /&gt;
&lt;br /&gt;
== Negative Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
Also known as ''invert'', it negates all the RGB values of the image, giving it an effect similar to a photographic negative.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~NEG( )'''&lt;br /&gt;
&lt;br /&gt;
Inverts the image, giving it an effect like a photographic negative.&lt;br /&gt;
&lt;br /&gt;
{{devfeature1.13|1}} '''~NEG(''' ''threshold'' ''')'''&lt;br /&gt;
&lt;br /&gt;
If a channel has a value greater than the threshold, the channel will be inverted, performing an effect known as ''solarization''.&lt;br /&gt;
Threshold must be between -1 and 255, with -1 equivalent to full inversion and 255 as no-op value.&lt;br /&gt;
&lt;br /&gt;
{{devfeature1.13|1}} '''~NEG(''' ''threshold_red, threshold_green, threshold_blue'' ''')'''&lt;br /&gt;
&lt;br /&gt;
If a channel has a value greater than the corresponding threshold, the channel will be inverted.&lt;br /&gt;
Each threshold must be between -1 and 255, with -1 equivalent to full inversion and 255 as no-op value.&lt;br /&gt;
&lt;br /&gt;
== Channel Swap Function ==&lt;br /&gt;
{{devfeature1.13|1}}&lt;br /&gt;
May be used to swap the RGBA channels of an image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~SWAP(''' ''r, g, b'' ''')'''&lt;br /&gt;
'''~SWAP(''' ''r, g, b, a'' ''')'''&lt;br /&gt;
* ''r'', ''g'', ''b'', ''a'': each of these arguments may have a value equal to ''red'', ''green'', ''blue'' or ''alpha''. The RGBA channels of the original image will be exchanged accordingly (for example, &amp;lt;tt&amp;gt;~SWAP(blue,green,red)&amp;lt;/tt&amp;gt; swaps the blue and red channels).&lt;br /&gt;
&lt;br /&gt;
== Crop Function ==&lt;br /&gt;
Extracts a rectangular section of an image file.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~CROP(x,y,width,height)'''&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates for the rectangular section extracted. Must be greater or equal than zero, and inside the image's bounds.&lt;br /&gt;
* ''width'': width of the selected region. Must be less than or equal to the original image's width, and must not be negative.&lt;br /&gt;
* ''height'': height of the selected region. Must be less than or equal to the original image's height, and must not be negative.&lt;br /&gt;
&lt;br /&gt;
== Blit Function ==&lt;br /&gt;
Blit the parameter image on the main image. Example: peasant.png~BLIT(hat.png,30,10)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLIT(src,x,y)'''&lt;br /&gt;
* ''src'': an image file used as source for the blit, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to blit. Must be greater or equal than zero. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
== Mask Function ==&lt;br /&gt;
Remove parts of the main image using the parameter image as a mask. Example: grass.png~MASK(circle.png) will give a circle of grass.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~MASK(mask,x,y)'''&lt;br /&gt;
* ''mask'': an image file used as mask, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to put the mask. Parts ouside of the mask are considered transparent. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
Only the alpha channel of the mask is used and each alpha value will be the maximum alpha of the resulting image. This means that the fully-transparent parts of the mask will erase the corresponding parts of the image, but also that a semi-transparent mask will create a semi-transparent image. &lt;br /&gt;
&lt;br /&gt;
== Color-shift function ==&lt;br /&gt;
Performs simple per-channel color shifts by adding the arguments to the respective color channels.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
''Multi-channel:'' '''~CS(r,g,b)'''&lt;br /&gt;
''Single-channel:'' '''~R(v)''', '''~G(v)''', '''~B(v)'''&lt;br /&gt;
&lt;br /&gt;
The multichannel syntax assumes all arguments are set to zero initially, so one can use, e.g. ~CS(2,4) to add +2 and +4 units to the red and green channels respectively, leaving the blue channel intact. Arguments may be negative to diminish a channel's value; this can be used to change an image's brightness. Checks for out-of-range arguments or results (less than 0 or greater than 255) are made, so the resultant values are truncated if necessary.&lt;br /&gt;
&lt;br /&gt;
The single channel syntax behaves exactly the same, except that only single-channel modifications are made per function. However, one can stack them to produce the same behavior as ~CS(), e.g. ~R(r)~G(g)~B(b), but that tends to be just a performance loss.&lt;br /&gt;
&lt;br /&gt;
== Color-blend function ==&lt;br /&gt;
Blends the image with the given color to produce a more controlled tinting effect than color-shifting, independently of the image's contents.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLEND(r,g,b,o)'''&lt;br /&gt;
&lt;br /&gt;
The color is defined by the ''r'', ''g'', and ''b'' parameters (integers ranging from 0 to 255). The ''o'' (opacity) parameter controls the amount by which the given color will be blended into the image, and may be specified either as a factor from 0.0 to 1.0, or percentage up to 100%. Thus, ~BLEND(r,g,b,0.5) and ~BLEND(r,g,b,50%) are equivalent.&lt;br /&gt;
&lt;br /&gt;
== Lightmap color-shift function ==&lt;br /&gt;
Performs per-pixel and per-channel color shifts using another image (a &amp;quot;lightmap&amp;quot;) as source, allowing to create textured light effects.&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~L(lightmap)'''&lt;br /&gt;
&lt;br /&gt;
For each pixel of the original image, it checks the RGB values from the corresponding pixel of the lightmap, slightly transform them, then add these values to the original pixel.&lt;br /&gt;
&lt;br /&gt;
The transformation involved is done to convert the (0,255) spectrum to (-255,255), allowing to add or subtract color. The formula is (x-128)*2, which means that 0 gives -256, 128 gives 0 and 255 gives 254. So, the no-effect lightmap is a fully gray image (RGB = 128,128,128) and any non-gray pixel will shift the colors of the original.&lt;br /&gt;
&lt;br /&gt;
Note that the lightmap will be scaled to the same dimensions as the original image.&lt;br /&gt;
&lt;br /&gt;
== Image-scaling function ==&lt;br /&gt;
Scales a graphic up or down.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~SCALE( ''new_width'', ''new_height'' )&lt;br /&gt;
&lt;br /&gt;
The ''new_width'' and ''new_height'' parameters are taken as the image's original width or height, respectively, if one of them happens to be zero. Negative values are treated in the same way, but an error is printed in stderr.&lt;br /&gt;
&lt;br /&gt;
== Opacity modifying function ==&lt;br /&gt;
Changes an image's opacity at render time.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~O( ''factor or percentage%'' )'''&lt;br /&gt;
&lt;br /&gt;
If the argument includes the percentage symbol (''%''), it will be treated as a percentage of full (real) opacity; an image will be displayed at its native opacity with ~O(100%).&lt;br /&gt;
&lt;br /&gt;
Without the percentage symbol, the argument is assumed to be a factor by which the image's native opacity should be multiplied. Thus, ~O(0.5) and ~O(50%) are equivalent forms of specifying to reduce an image's opacity by half.&lt;br /&gt;
&lt;br /&gt;
== Blurring function ==&lt;br /&gt;
Blurs a graphic at render time using the same algorithm used for in-game dialogs.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BL( ''radius'' )'''&lt;br /&gt;
&lt;br /&gt;
== Overlay function ==&lt;br /&gt;
Puts a time-of-day overlay on the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~LIGHTEN()'''&lt;br /&gt;
&lt;br /&gt;
'''~DARKEN()'''&lt;br /&gt;
&lt;br /&gt;
== Background coloring function ==&lt;br /&gt;
Sets the color of all the (semi-)transparent pixels of the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BG(r,g,b)'''&lt;br /&gt;
&lt;br /&gt;
== Null function ==&lt;br /&gt;
Does nothing.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~NOP()'''&lt;br /&gt;
&lt;br /&gt;
== XBRZ function ==&lt;br /&gt;
Scales functions using the XBRZ algorithm. You may scale things up either 2x, 3x, 4x, or 5x. The scaling tries to preserve the pixel art nature.&lt;br /&gt;
&lt;br /&gt;
'''~XBRZ(n)'''&lt;br /&gt;
&lt;br /&gt;
== SCALE_SHARP function ==&lt;br /&gt;
Scales functions using a nearest neighbor algorithm. Specify width and height. (It has the same syntax as ~SCALE.)&lt;br /&gt;
&lt;br /&gt;
'''~SCALE_SHARP(200,300)'''&lt;br /&gt;
&lt;br /&gt;
== PLOT_ALPHA ==&lt;br /&gt;
At each pixel, the color is replaced with a grey-tone reflecting the alpha value at that pixel, and the new image is fully opaque. Useful for plotting the alpha to help debug an IPF or inspect a sprite.&lt;br /&gt;
&lt;br /&gt;
'''~PLOT_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== WIPE_ALPHA ==&lt;br /&gt;
At each pixel, the alpha value is discarded and the pixel is made fully opaque. Useful again for diagnostics.&lt;br /&gt;
&lt;br /&gt;
'''~WIPE_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== ADJUST_ALPHA ==&lt;br /&gt;
&lt;br /&gt;
Scales the alpha value at each pixel down by a fixed factor. The argument is either a %, or an integer from 0 to 255, in which case it is divided by 255 and reinterpretted as a %.&lt;br /&gt;
&lt;br /&gt;
'''~ADJUST_ALPHA(n)'''.&lt;br /&gt;
&lt;br /&gt;
== Precedence of Functions  ==&lt;br /&gt;
&lt;br /&gt;
All functions are applied in left-to-right order, with the exception of RC(), TC() and PAL() which are applied always before any other functions. Standard team coloring for a unit is applied after all custom RC(), TC() and PAL() functions but before any other functions.&lt;br /&gt;
That is, stuff like &amp;quot;units/elves-wood/fighter.png~CROP(20,20,40,40)~CROP(10,10,10,10)&amp;quot; would result in taking a crop to a 40x40 rectangle whose top-left corner is x=20, y=20; and then taking a crop from ''that'' rectangle with x=10, y=10, w=10, h=10. The result is the area x=30, y=30, w=10, h=10 from the original graphic.&lt;br /&gt;
&lt;br /&gt;
[[Category:WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56425</id>
		<title>ImagePathFunctions</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56425"/>
		<updated>2015-06-06T09:54:23Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added ~SWAP() function&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Image Path Functions provide a simple method for WML coders to alter the way their specified images will be displayed in the game. All of the function parameters are included at the end of an image path and should not contain any spaces or special characters (other than those specified here).&lt;br /&gt;
&lt;br /&gt;
If you need to practice it without having to reload all WML, you can use an add-on named ''Image loading tester'' from the 1.10 add-on server.&lt;br /&gt;
&lt;br /&gt;
== Team-Color Function ==&lt;br /&gt;
In Wesnoth version 1.2, the only Image Path Function was '''~TC()''', which took two comma-separated parameters: the team number and the source color palette. The valid values for both of these parameters are defined in the file ''data/team-colors.cfg''&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~TC(''' ''team number'' ''',''' ''source color palette'' ''')'''&lt;br /&gt;
*''team number'' - this is the first parameter, a number 1-9 signifying the team number of a unit. Number 1 typically means the red team, 2 typically means the blue team, and so on (unless the scenario color settings for any side have been altered).&lt;br /&gt;
*''source color palette'' - the second parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
&lt;br /&gt;
== Re-Color Function ==&lt;br /&gt;
May be used to change some colors in an image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~RC(''' ''source color palette'' '''&amp;gt;''' ''color range ID'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''color range ID'' - this is the second parameter, signifying the ID of a color range defined in the file ''data/core/team-colors.cfg'' (or it may be a custom ID for a color range defined locally).  &lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
In the following example, the magenta regions in an elvish captain's image are turned  a healthy shade of green:&lt;br /&gt;
&lt;br /&gt;
  [message]&lt;br /&gt;
      speaker=narrator&lt;br /&gt;
      image=units/elves-wood/captain.png~RC(magenta&amp;gt;green)&lt;br /&gt;
      message=_ &amp;quot;Now I am on the green team.&amp;quot;&lt;br /&gt;
  [/message]&lt;br /&gt;
&lt;br /&gt;
The IDs of the color ranges may be the lowercased English name of the palette's base color (e.g. 'red', 'brown', etc.). They may also be numeric color indices from the palette WML included with the game, but this is not recommended.&lt;br /&gt;
&lt;br /&gt;
== Palette-switch Function ==&lt;br /&gt;
May be used to change colors in an image following the specifications of a source and target (new) palette.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~PAL(''' ''source color palette'' '''&amp;gt;''' ''target color palette'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, such as magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''target color palette'' - the new palette to take the place of the source colors in the image.&lt;br /&gt;
&lt;br /&gt;
== Flip Function ==&lt;br /&gt;
May be used to flip an image horizontally and/or vertically.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~FL(''' ''optional argument list'' ''')'''&lt;br /&gt;
*''vertical'' - if the string &amp;quot;vert&amp;quot; is found anywhere in the argument list, the image will be flipped vertically.&lt;br /&gt;
*''horizontal'' - if the string &amp;quot;horiz&amp;quot; is found anywhere in the argument list, the image will be flipped horizantally.&lt;br /&gt;
*if the argument list is empty, the image will only be flipped horizontally.&lt;br /&gt;
&lt;br /&gt;
== Rotate Function ==&lt;br /&gt;
May be used to rotate an image by a multiple of 90 degrees.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~ROTATE(''' ''degrees'' ''')'''&lt;br /&gt;
* ''degrees'' - The number of degrees by which the image will be rotated. This must be a multiple of 90. Positive numbers indicate clockwise rotation, while negative numbers indicate counter-clockwise. (Zero indicates no rotation.)&lt;br /&gt;
If the number of degrees is omitted, a quarter turn (90 degrees) clockwise is assumed.&lt;br /&gt;
&lt;br /&gt;
== Greyscale Function ==&lt;br /&gt;
May be used to greyscale the image (turn to black and white)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~GS( )'''&lt;br /&gt;
&lt;br /&gt;
== Black and White Function ==&lt;br /&gt;
{{devfeature1.13|1}}&lt;br /&gt;
May be used to convert the image to pure black and white, without grey pixels. &lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BW(threshold)'''&lt;br /&gt;
* ''threshold'': a value between 0 and 255 (both limits included). All pixels are converted as greyscale first, and if their average value is greater than the threshold they become white, otherwise they become black.&lt;br /&gt;
&lt;br /&gt;
== Sepia Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
May be used to give to the image a sepia tint (like in old pictures).&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~SEPIA()'''&lt;br /&gt;
&lt;br /&gt;
== Negative Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
Also known as ''invert'', it negates all the RGB values of the image, giving it an effect similar to a photographic negative.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~NEG( )'''&lt;br /&gt;
&lt;br /&gt;
Inverts the image, giving it an effect like a photographic negative.&lt;br /&gt;
&lt;br /&gt;
'''~NEG(''' ''threshold'' ''')'''&lt;br /&gt;
&lt;br /&gt;
If a channel has a value greater than the threshold, the channel will be inverted, performing an effect known as ''solarization''.&lt;br /&gt;
Threshold must be between -1 and 255, with -1 equivalent to full inversion and 255 as no-op value.&lt;br /&gt;
&lt;br /&gt;
'''~NEG(''' ''threshold_red, threshold_green, threshold_blue'' ''')'''&lt;br /&gt;
&lt;br /&gt;
If a channel has a value greater than the corresponding threshold, the channel will be inverted.&lt;br /&gt;
Each threshold must be between -1 and 255, with -1 equivalent to full inversion and 255 as no-op value.&lt;br /&gt;
&lt;br /&gt;
== Channel Swap Function ==&lt;br /&gt;
{{devfeature1.13|1}}&lt;br /&gt;
May be used to swap the RGBA channels of an image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~SWAP(''' ''r, g, b'' ''')'''&lt;br /&gt;
'''~SWAP(''' ''r, g, b, a'' ''')'''&lt;br /&gt;
* ''r'', ''g'', ''b'', ''a'': each of these arguments may have a value equal to ''red'', ''green'', ''blue'' or ''alpha''. The RGBA channels of the original image will be exchanged accordingly (for example, &amp;lt;tt&amp;gt;~SWAP(blue,green,red)&amp;lt;/tt&amp;gt; swaps the blue and red channels).&lt;br /&gt;
&lt;br /&gt;
== Crop Function ==&lt;br /&gt;
Extracts a rectangular section of an image file.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~CROP(x,y,width,height)'''&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates for the rectangular section extracted. Must be greater or equal than zero, and inside the image's bounds.&lt;br /&gt;
* ''width'': width of the selected region. Must be less than or equal to the original image's width, and must not be negative.&lt;br /&gt;
* ''height'': height of the selected region. Must be less than or equal to the original image's height, and must not be negative.&lt;br /&gt;
&lt;br /&gt;
== Blit Function ==&lt;br /&gt;
Blit the parameter image on the main image. Example: peasant.png~BLIT(hat.png,30,10)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLIT(src,x,y)'''&lt;br /&gt;
* ''src'': an image file used as source for the blit, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to blit. Must be greater or equal than zero. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
== Mask Function ==&lt;br /&gt;
Remove parts of the main image using the parameter image as a mask. Example: grass.png~MASK(circle.png) will give a circle of grass.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~MASK(mask,x,y)'''&lt;br /&gt;
* ''mask'': an image file used as mask, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to put the mask. Parts ouside of the mask are considered transparent. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
Only the alpha channel of the mask is used and each alpha value will be the maximum alpha of the resulting image. This means that the fully-transparent parts of the mask will erase the corresponding parts of the image, but also that a semi-transparent mask will create a semi-transparent image. &lt;br /&gt;
&lt;br /&gt;
== Color-shift function ==&lt;br /&gt;
Performs simple per-channel color shifts by adding the arguments to the respective color channels.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
''Multi-channel:'' '''~CS(r,g,b)'''&lt;br /&gt;
''Single-channel:'' '''~R(v)''', '''~G(v)''', '''~B(v)'''&lt;br /&gt;
&lt;br /&gt;
The multichannel syntax assumes all arguments are set to zero initially, so one can use, e.g. ~CS(2,4) to add +2 and +4 units to the red and green channels respectively, leaving the blue channel intact. Arguments may be negative to diminish a channel's value; this can be used to change an image's brightness. Checks for out-of-range arguments or results (less than 0 or greater than 255) are made, so the resultant values are truncated if necessary.&lt;br /&gt;
&lt;br /&gt;
The single channel syntax behaves exactly the same, except that only single-channel modifications are made per function. However, one can stack them to produce the same behavior as ~CS(), e.g. ~R(r)~G(g)~B(b), but that tends to be just a performance loss.&lt;br /&gt;
&lt;br /&gt;
== Color-blend function ==&lt;br /&gt;
Blends the image with the given color to produce a more controlled tinting effect than color-shifting, independently of the image's contents.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLEND(r,g,b,o)'''&lt;br /&gt;
&lt;br /&gt;
The color is defined by the ''r'', ''g'', and ''b'' parameters (integers ranging from 0 to 255). The ''o'' (opacity) parameter controls the amount by which the given color will be blended into the image, and may be specified either as a factor from 0.0 to 1.0, or percentage up to 100%. Thus, ~BLEND(r,g,b,0.5) and ~BLEND(r,g,b,50%) are equivalent.&lt;br /&gt;
&lt;br /&gt;
== Lightmap color-shift function ==&lt;br /&gt;
Performs per-pixel and per-channel color shifts using another image (a &amp;quot;lightmap&amp;quot;) as source, allowing to create textured light effects.&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~L(lightmap)'''&lt;br /&gt;
&lt;br /&gt;
For each pixel of the original image, it checks the RGB values from the corresponding pixel of the lightmap, slightly transform them, then add these values to the original pixel.&lt;br /&gt;
&lt;br /&gt;
The transformation involved is done to convert the (0,255) spectrum to (-255,255), allowing to add or subtract color. The formula is (x-128)*2, which means that 0 gives -256, 128 gives 0 and 255 gives 254. So, the no-effect lightmap is a fully gray image (RGB = 128,128,128) and any non-gray pixel will shift the colors of the original.&lt;br /&gt;
&lt;br /&gt;
Note that the lightmap will be scaled to the same dimensions as the original image.&lt;br /&gt;
&lt;br /&gt;
== Image-scaling function ==&lt;br /&gt;
Scales a graphic up or down.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~SCALE( ''new_width'', ''new_height'' )&lt;br /&gt;
&lt;br /&gt;
The ''new_width'' and ''new_height'' parameters are taken as the image's original width or height, respectively, if one of them happens to be zero. Negative values are treated in the same way, but an error is printed in stderr.&lt;br /&gt;
&lt;br /&gt;
== Opacity modifying function ==&lt;br /&gt;
Changes an image's opacity at render time.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~O( ''factor or percentage%'' )'''&lt;br /&gt;
&lt;br /&gt;
If the argument includes the percentage symbol (''%''), it will be treated as a percentage of full (real) opacity; an image will be displayed at its native opacity with ~O(100%).&lt;br /&gt;
&lt;br /&gt;
Without the percentage symbol, the argument is assumed to be a factor by which the image's native opacity should be multiplied. Thus, ~O(0.5) and ~O(50%) are equivalent forms of specifying to reduce an image's opacity by half.&lt;br /&gt;
&lt;br /&gt;
== Blurring function ==&lt;br /&gt;
Blurs a graphic at render time using the same algorithm used for in-game dialogs.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BL( ''radius'' )'''&lt;br /&gt;
&lt;br /&gt;
== Overlay function ==&lt;br /&gt;
Puts a time-of-day overlay on the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~LIGHTEN()'''&lt;br /&gt;
&lt;br /&gt;
'''~DARKEN()'''&lt;br /&gt;
&lt;br /&gt;
== Background coloring function ==&lt;br /&gt;
Sets the color of all the (semi-)transparent pixels of the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BG(r,g,b)'''&lt;br /&gt;
&lt;br /&gt;
== Null function ==&lt;br /&gt;
Does nothing.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~NOP()'''&lt;br /&gt;
&lt;br /&gt;
== XBRZ function ==&lt;br /&gt;
Scales functions using the XBRZ algorithm. You may scale things up either 2x, 3x, 4x, or 5x. The scaling tries to preserve the pixel art nature.&lt;br /&gt;
&lt;br /&gt;
'''~XBRZ(n)'''&lt;br /&gt;
&lt;br /&gt;
== SCALE_SHARP function ==&lt;br /&gt;
Scales functions using a nearest neighbor algorithm. Specify width and height. (It has the same syntax as ~SCALE.)&lt;br /&gt;
&lt;br /&gt;
'''~SCALE_SHARP(200,300)'''&lt;br /&gt;
&lt;br /&gt;
== PLOT_ALPHA ==&lt;br /&gt;
At each pixel, the color is replaced with a grey-tone reflecting the alpha value at that pixel, and the new image is fully opaque. Useful for plotting the alpha to help debug an IPF or inspect a sprite.&lt;br /&gt;
&lt;br /&gt;
'''~PLOT_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== WIPE_ALPHA ==&lt;br /&gt;
At each pixel, the alpha value is discarded and the pixel is made fully opaque. Useful again for diagnostics.&lt;br /&gt;
&lt;br /&gt;
'''~WIPE_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== ADJUST_ALPHA ==&lt;br /&gt;
&lt;br /&gt;
Scales the alpha value at each pixel down by a fixed factor. The argument is either a %, or an integer from 0 to 255, in which case it is divided by 255 and reinterpretted as a %.&lt;br /&gt;
&lt;br /&gt;
'''~ADJUST_ALPHA(n)'''.&lt;br /&gt;
&lt;br /&gt;
== Precedence of Functions  ==&lt;br /&gt;
&lt;br /&gt;
All functions are applied in left-to-right order, with the exception of RC(), TC() and PAL() which are applied always before any other functions. Standard team coloring for a unit is applied after all custom RC(), TC() and PAL() functions but before any other functions.&lt;br /&gt;
That is, stuff like &amp;quot;units/elves-wood/fighter.png~CROP(20,20,40,40)~CROP(10,10,10,10)&amp;quot; would result in taking a crop to a 40x40 rectangle whose top-left corner is x=20, y=20; and then taking a crop from ''that'' rectangle with x=10, y=10, w=10, h=10. The result is the area x=30, y=30, w=10, h=10 from the original graphic.&lt;br /&gt;
&lt;br /&gt;
[[Category:WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Sides&amp;diff=56416</id>
		<title>LuaWML/Sides</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Sides&amp;diff=56416"/>
		<updated>2015-05-28T12:35:25Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* wesnoth.sides */ side.recruit is a read/write table&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions and helpers for handling sides and villages.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.sides ====&lt;br /&gt;
&lt;br /&gt;
This is not a function but a table indexed by side numbers. Its elements are proxy tables with these fields:&lt;br /&gt;
* '''side''': the side number&lt;br /&gt;
* '''gold''', '''village_gold''', '''base_income''': integers (read/write)&lt;br /&gt;
* '''total_income''': integer (read only)&lt;br /&gt;
* '''objectives''', '''user_team_name''': translatable strings (read/write)&lt;br /&gt;
* '''objectives_changed''': boolean (read/write)&lt;br /&gt;
* '''team_name''': string (read/write)&lt;br /&gt;
* '''controller''': string (read/write) :&lt;br /&gt;
:''note: In networked multiplayer, the controller attribute is ambiguous. Be very careful or you have OOS errors.''&lt;br /&gt;
: The controller attribute has 6 possible values: human, network, ai, network_ai, null, idle. &lt;br /&gt;
&lt;br /&gt;
: A local human should always be &amp;quot;human&amp;quot;, a local ai should always be &amp;quot;ai&amp;quot;, a remote human should always be &amp;quot;network&amp;quot;. and a remote ai should always be &amp;quot;network_ai&amp;quot;. An empty side should be null on all clients. &lt;br /&gt;
&lt;br /&gt;
: An idle side should appear similarly as a &amp;quot;human&amp;quot; side for all sides that don't own the idle side, i.e. as &amp;quot;network&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
: These values may be checked using lua, or the :controller command in game.&lt;br /&gt;
&lt;br /&gt;
* '''fog''': boolean (read)&lt;br /&gt;
* '''shroud''': boolean (read)&lt;br /&gt;
* '''hidden''': boolean (read/write)&lt;br /&gt;
* '''name''': string (read)&lt;br /&gt;
* '''color''': string (read/write)&lt;br /&gt;
* '''recruit''': table of strings (read/write)&lt;br /&gt;
* '''scroll_to_leader''': boolean (read/write)&lt;br /&gt;
* '''village_support''': string (read/write)&lt;br /&gt;
* '''flag''': string (read)&lt;br /&gt;
* '''flag_icon''': string (read)&lt;br /&gt;
* '''defeat_condition''': string (read/write) See description at [[SideWML]], [[ScenarioWML#Scenario_End_Conditions]]&lt;br /&gt;
* '''lost''': bool (read/write) If lost=true this side will be removed from the persitent list at the end of the scenario. This key can also be used to stop the engine from removing a side by setting it to false. Writing this key only works in a victory/defeat event.&lt;br /&gt;
* '''__cfg''': WML table (dump)&lt;br /&gt;
&lt;br /&gt;
The metatable of these proxy tables appears as '''&amp;quot;side&amp;quot;'''.&lt;br /&gt;
&lt;br /&gt;
 local team = wesnoth.sides[1]&lt;br /&gt;
 team.gold = team.gold + 50&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;%d sides&amp;quot;, #wesnoth.sides))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_sides ====&lt;br /&gt;
&lt;br /&gt;
Returns a table array containing proxy tables for these sides matching the passed [[StandardSideFilter]].&lt;br /&gt;
 --set gold to 0 for all sides with a leader&lt;br /&gt;
 local sides = wesnoth.get_sides({ {&amp;quot;has_unit&amp;quot;, { canrecruit = true }} })&lt;br /&gt;
 for i,v in ipairs(sides) do&lt;br /&gt;
     v.gold = 0&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_village_owner ====&lt;br /&gt;
&lt;br /&gt;
Returns the side that owns the village at the given location.&lt;br /&gt;
&lt;br /&gt;
 local owned_by_side_1 = wesnoth.get_village_owner(12, 15) == 1&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_village_owner ====&lt;br /&gt;
&lt;br /&gt;
Gives ownership of the village at the given location to the given side (or remove ownership if none). Ownership is also removed if nil or 0 is passed for the third parameter, but no capture events are fired in this case.&lt;br /&gt;
An optional 4th parameter (boolean true|false, default: false) can be passed determining whether to fire any capture events.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.set_village_owner(12, 15, 1)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.is_enemy ====&lt;br /&gt;
&lt;br /&gt;
Returns true if side A is enemy of side B, false otherwise.&lt;br /&gt;
&lt;br /&gt;
 local enemy_flag = wesnoth.is_enemy(1, 3)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.match_side ====&lt;br /&gt;
&lt;br /&gt;
Matches a side against a given [[StandardSideFilter]].&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message(tostring(wesnoth.match_side(1, {{&amp;quot;has_unit&amp;quot;, { type = &amp;quot;Troll&amp;quot; }}})))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_starting_location ====&lt;br /&gt;
&lt;br /&gt;
 local loc = wesnoth.get_starting_location(1)&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;side 1 starts at (%u, %u)&amp;quot;, loc[1], loc[2]))&lt;br /&gt;
&lt;br /&gt;
==== helper.all_teams ====&lt;br /&gt;
&lt;br /&gt;
Returns an iterator over teams that can be used in a for-in loop.&lt;br /&gt;
&lt;br /&gt;
 for team in helper.all_teams() do team.gold = 200 end&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56399</id>
		<title>ImagePathFunctions</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56399"/>
		<updated>2015-05-24T20:31:49Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* Syntax */ Added arguments support to ~NEG&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Image Path Functions provide a simple method for WML coders to alter the way their specified images will be displayed in the game. All of the function parameters are included at the end of an image path and should not contain any spaces or special characters (other than those specified here).&lt;br /&gt;
&lt;br /&gt;
If you need to practice it without having to reload all WML, you can use an add-on named ''Image loading tester'' from the 1.10 add-on server.&lt;br /&gt;
&lt;br /&gt;
== Team-Color Function ==&lt;br /&gt;
In Wesnoth version 1.2, the only Image Path Function was '''~TC()''', which took two comma-separated parameters: the team number and the source color palette. The valid values for both of these parameters are defined in the file ''data/team-colors.cfg''&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~TC(''' ''team number'' ''',''' ''source color palette'' ''')'''&lt;br /&gt;
*''team number'' - this is the first parameter, a number 1-9 signifying the team number of a unit. Number 1 typically means the red team, 2 typically means the blue team, and so on (unless the scenario color settings for any side have been altered).&lt;br /&gt;
*''source color palette'' - the second parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
&lt;br /&gt;
== Re-Color Function ==&lt;br /&gt;
May be used to change some colors in an image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~RC(''' ''source color palette'' '''&amp;gt;''' ''color range ID'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''color range ID'' - this is the second parameter, signifying the ID of a color range defined in the file ''data/core/team-colors.cfg'' (or it may be a custom ID for a color range defined locally).  &lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
In the following example, the magenta regions in an elvish captain's image are turned  a healthy shade of green:&lt;br /&gt;
&lt;br /&gt;
  [message]&lt;br /&gt;
      speaker=narrator&lt;br /&gt;
      image=units/elves-wood/captain.png~RC(magenta&amp;gt;green)&lt;br /&gt;
      message=_ &amp;quot;Now I am on the green team.&amp;quot;&lt;br /&gt;
  [/message]&lt;br /&gt;
&lt;br /&gt;
The IDs of the color ranges may be the lowercased English name of the palette's base color (e.g. 'red', 'brown', etc.). They may also be numeric color indices from the palette WML included with the game, but this is not recommended.&lt;br /&gt;
&lt;br /&gt;
== Palette-switch Function ==&lt;br /&gt;
May be used to change colors in an image following the specifications of a source and target (new) palette.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~PAL(''' ''source color palette'' '''&amp;gt;''' ''target color palette'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, such as magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''target color palette'' - the new palette to take the place of the source colors in the image.&lt;br /&gt;
&lt;br /&gt;
== Flip Function ==&lt;br /&gt;
May be used to flip an image horizontally and/or vertically.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~FL(''' ''optional argument list'' ''')'''&lt;br /&gt;
*''vertical'' - if the string &amp;quot;vert&amp;quot; is found anywhere in the argument list, the image will be flipped vertically.&lt;br /&gt;
*''horizontal'' - if the string &amp;quot;horiz&amp;quot; is found anywhere in the argument list, the image will be flipped horizantally.&lt;br /&gt;
*if the argument list is empty, the image will only be flipped horizontally.&lt;br /&gt;
&lt;br /&gt;
== Rotate Function ==&lt;br /&gt;
May be used to rotate an image by a multiple of 90 degrees.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~ROTATE(''' ''degrees'' ''')'''&lt;br /&gt;
* ''degrees'' - The number of degrees by which the image will be rotated. This must be a multiple of 90. Positive numbers indicate clockwise rotation, while negative numbers indicate counter-clockwise. (Zero indicates no rotation.)&lt;br /&gt;
If the number of degrees is omitted, a quarter turn (90 degrees) clockwise is assumed.&lt;br /&gt;
&lt;br /&gt;
== Greyscale Function ==&lt;br /&gt;
May be used to greyscale the image (turn to black and white)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~GS( )'''&lt;br /&gt;
&lt;br /&gt;
== Black and White Function ==&lt;br /&gt;
{{devfeature1.13|1}}&lt;br /&gt;
May be used to convert the image to pure black and white, without grey pixels. &lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BW(threshold)'''&lt;br /&gt;
* ''threshold'': a value between 0 and 255 (both limits included). All pixels are converted as greyscale first, and if their average value is greater than the threshold they become white, otherwise they become black.&lt;br /&gt;
&lt;br /&gt;
== Sepia Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
May be used to give to the image a sepia tint (like in old pictures).&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~SEPIA()'''&lt;br /&gt;
&lt;br /&gt;
== Negative Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
Also known as ''invert'', it negates all the RGB values of the image, giving it an effect similar to a photographic negative.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~NEG( )'''&lt;br /&gt;
&lt;br /&gt;
Inverts the image, giving it an effect like a photographic negative.&lt;br /&gt;
&lt;br /&gt;
'''~NEG(''' ''threshold'' ''')'''&lt;br /&gt;
&lt;br /&gt;
If a channel has a value greater than the threshold, the channel will be inverted, performing an effect known as ''solarization''.&lt;br /&gt;
Threshold must be between -1 and 255, with -1 equivalent to full inversion and 255 as no-op value.&lt;br /&gt;
&lt;br /&gt;
'''~NEG(''' ''threshold_red, threshold_green, threshold_blue'' ''')'''&lt;br /&gt;
&lt;br /&gt;
If a channel has a value greater than the corresponding threshold, the channel will be inverted.&lt;br /&gt;
Each threshold must be between -1 and 255, with -1 equivalent to full inversion and 255 as no-op value.&lt;br /&gt;
&lt;br /&gt;
== Crop Function ==&lt;br /&gt;
Extracts a rectangular section of an image file.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~CROP(x,y,width,height)'''&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates for the rectangular section extracted. Must be greater or equal than zero, and inside the image's bounds.&lt;br /&gt;
* ''width'': width of the selected region. Must be less than or equal to the original image's width, and must not be negative.&lt;br /&gt;
* ''height'': height of the selected region. Must be less than or equal to the original image's height, and must not be negative.&lt;br /&gt;
&lt;br /&gt;
== Blit Function ==&lt;br /&gt;
Blit the parameter image on the main image. Example: peasant.png~BLIT(hat.png,30,10)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLIT(src,x,y)'''&lt;br /&gt;
* ''src'': an image file used as source for the blit, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to blit. Must be greater or equal than zero. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
== Mask Function ==&lt;br /&gt;
Remove parts of the main image using the parameter image as a mask. Example: grass.png~MASK(circle.png) will give a circle of grass.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~MASK(mask,x,y)'''&lt;br /&gt;
* ''mask'': an image file used as mask, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to put the mask. Parts ouside of the mask are considered transparent. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
Only the alpha channel of the mask is used and each alpha value will be the maximum alpha of the resulting image. This means that the fully-transparent parts of the mask will erase the corresponding parts of the image, but also that a semi-transparent mask will create a semi-transparent image. &lt;br /&gt;
&lt;br /&gt;
== Color-shift function ==&lt;br /&gt;
Performs simple per-channel color shifts by adding the arguments to the respective color channels.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
''Multi-channel:'' '''~CS(r,g,b)'''&lt;br /&gt;
''Single-channel:'' '''~R(v)''', '''~G(v)''', '''~B(v)'''&lt;br /&gt;
&lt;br /&gt;
The multichannel syntax assumes all arguments are set to zero initially, so one can use, e.g. ~CS(2,4) to add +2 and +4 units to the red and green channels respectively, leaving the blue channel intact. Arguments may be negative to diminish a channel's value; this can be used to change an image's brightness. Checks for out-of-range arguments or results (less than 0 or greater than 255) are made, so the resultant values are truncated if necessary.&lt;br /&gt;
&lt;br /&gt;
The single channel syntax behaves exactly the same, except that only single-channel modifications are made per function. However, one can stack them to produce the same behavior as ~CS(), e.g. ~R(r)~G(g)~B(b), but that tends to be just a performance loss.&lt;br /&gt;
&lt;br /&gt;
== Color-blend function ==&lt;br /&gt;
Blends the image with the given color to produce a more controlled tinting effect than color-shifting, independently of the image's contents.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLEND(r,g,b,o)'''&lt;br /&gt;
&lt;br /&gt;
The color is defined by the ''r'', ''g'', and ''b'' parameters (integers ranging from 0 to 255). The ''o'' (opacity) parameter controls the amount by which the given color will be blended into the image, and may be specified either as a factor from 0.0 to 1.0, or percentage up to 100%. Thus, ~BLEND(r,g,b,0.5) and ~BLEND(r,g,b,50%) are equivalent.&lt;br /&gt;
&lt;br /&gt;
== Lightmap color-shift function ==&lt;br /&gt;
Performs per-pixel and per-channel color shifts using another image (a &amp;quot;lightmap&amp;quot;) as source, allowing to create textured light effects.&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~L(lightmap)'''&lt;br /&gt;
&lt;br /&gt;
For each pixel of the original image, it checks the RGB values from the corresponding pixel of the lightmap, slightly transform them, then add these values to the original pixel.&lt;br /&gt;
&lt;br /&gt;
The transformation involved is done to convert the (0,255) spectrum to (-255,255), allowing to add or subtract color. The formula is (x-128)*2, which means that 0 gives -256, 128 gives 0 and 255 gives 254. So, the no-effect lightmap is a fully gray image (RGB = 128,128,128) and any non-gray pixel will shift the colors of the original.&lt;br /&gt;
&lt;br /&gt;
Note that the lightmap will be scaled to the same dimensions as the original image.&lt;br /&gt;
&lt;br /&gt;
== Image-scaling function ==&lt;br /&gt;
Scales a graphic up or down.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~SCALE( ''new_width'', ''new_height'' )&lt;br /&gt;
&lt;br /&gt;
The ''new_width'' and ''new_height'' parameters are taken as the image's original width or height, respectively, if one of them happens to be zero. Negative values are treated in the same way, but an error is printed in stderr.&lt;br /&gt;
&lt;br /&gt;
== Opacity modifying function ==&lt;br /&gt;
Changes an image's opacity at render time.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~O( ''factor or percentage%'' )'''&lt;br /&gt;
&lt;br /&gt;
If the argument includes the percentage symbol (''%''), it will be treated as a percentage of full (real) opacity; an image will be displayed at its native opacity with ~O(100%).&lt;br /&gt;
&lt;br /&gt;
Without the percentage symbol, the argument is assumed to be a factor by which the image's native opacity should be multiplied. Thus, ~O(0.5) and ~O(50%) are equivalent forms of specifying to reduce an image's opacity by half.&lt;br /&gt;
&lt;br /&gt;
== Blurring function ==&lt;br /&gt;
Blurs a graphic at render time using the same algorithm used for in-game dialogs.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BL( ''radius'' )'''&lt;br /&gt;
&lt;br /&gt;
== Overlay function ==&lt;br /&gt;
Puts a time-of-day overlay on the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~LIGHTEN()'''&lt;br /&gt;
&lt;br /&gt;
'''~DARKEN()'''&lt;br /&gt;
&lt;br /&gt;
== Background coloring function ==&lt;br /&gt;
Sets the color of all the (semi-)transparent pixels of the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BG(r,g,b)'''&lt;br /&gt;
&lt;br /&gt;
== Null function ==&lt;br /&gt;
Does nothing.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~NOP()'''&lt;br /&gt;
&lt;br /&gt;
== XBRZ function ==&lt;br /&gt;
Scales functions using the XBRZ algorithm. You may scale things up either 2x, 3x, 4x, or 5x. The scaling tries to preserve the pixel art nature.&lt;br /&gt;
&lt;br /&gt;
'''~XBRZ(n)'''&lt;br /&gt;
&lt;br /&gt;
== SCALE_SHARP function ==&lt;br /&gt;
Scales functions using a nearest neighbor algorithm. Specify width and height. (It has the same syntax as ~SCALE.)&lt;br /&gt;
&lt;br /&gt;
'''~SCALE_SHARP(200,300)'''&lt;br /&gt;
&lt;br /&gt;
== PLOT_ALPHA ==&lt;br /&gt;
At each pixel, the color is replaced with a grey-tone reflecting the alpha value at that pixel, and the new image is fully opaque. Useful for plotting the alpha to help debug an IPF or inspect a sprite.&lt;br /&gt;
&lt;br /&gt;
'''~PLOT_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== WIPE_ALPHA ==&lt;br /&gt;
At each pixel, the alpha value is discarded and the pixel is made fully opaque. Useful again for diagnostics.&lt;br /&gt;
&lt;br /&gt;
'''~WIPE_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== ADJUST_ALPHA ==&lt;br /&gt;
&lt;br /&gt;
Scales the alpha value at each pixel down by a fixed factor. The argument is either a %, or an integer from 0 to 255, in which case it is divided by 255 and reinterpretted as a %.&lt;br /&gt;
&lt;br /&gt;
'''~ADJUST_ALPHA(n)'''.&lt;br /&gt;
&lt;br /&gt;
== Precedence of Functions  ==&lt;br /&gt;
&lt;br /&gt;
All functions are applied in left-to-right order, with the exception of RC(), TC() and PAL() which are applied always before any other functions. Standard team coloring for a unit is applied after all custom RC(), TC() and PAL() functions but before any other functions.&lt;br /&gt;
That is, stuff like &amp;quot;units/elves-wood/fighter.png~CROP(20,20,40,40)~CROP(10,10,10,10)&amp;quot; would result in taking a crop to a 40x40 rectangle whose top-left corner is x=20, y=20; and then taking a crop from ''that'' rectangle with x=10, y=10, w=10, h=10. The result is the area x=30, y=30, w=10, h=10 from the original graphic.&lt;br /&gt;
&lt;br /&gt;
[[Category:WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=InterfaceActionsWML&amp;diff=56398</id>
		<title>InterfaceActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=InterfaceActionsWML&amp;diff=56398"/>
		<updated>2015-05-24T20:24:19Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [label] */ Added SLF support to [event] [label]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== Interface actions ==&lt;br /&gt;
&lt;br /&gt;
Part of [[ActionWML]], interface actions are actions that do not have a direct effect on gameplay;&lt;br /&gt;
instead, they show something to the player.  The main interface tags&lt;br /&gt;
are '''[message]''' and '''[objectives]''', but several other tags affect&lt;br /&gt;
the interface also.&lt;br /&gt;
&lt;br /&gt;
== [inspect] ==&lt;br /&gt;
This user interface instantly displays the gamestate inspector dialog at the current scenario state (the same one that can be brought up with [[CommandMode|the ''':inspect''' command]]), which can be used to inspect the values of WML variables, AI configuration, recall lists, and more.&lt;br /&gt;
&lt;br /&gt;
* '''name''': optional attribute to specify the name of this gamestate inspector dialog. It is just a label to help differentiate between different invocations of gamestate inspector dialog.&lt;br /&gt;
&lt;br /&gt;
== [message] ==&lt;br /&gt;
The most commonly used interface action is [message], which displays a message to the user in a dialog box. It can also be used to take input from the user.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are accepted for [message]:&lt;br /&gt;
* [[StandardUnitFilter]]: The unit whose profile and name are displayed. Do not use a [filter] tag. If no unit matching this filter is found, the message is not displayed (The unit has probably been killed).&amp;lt;br&amp;gt;'''[message]''' elements should be constructed so that it is either guaranteed that a certain unit is alive, or so that dialog flows smoothly even if the message isn't displayed.&lt;br /&gt;
&lt;br /&gt;
* '''speaker''': an alternative to standard unit filter. You may specify as the value of the speaker attribute a unit id or any of the following special values:&lt;br /&gt;
** '''narrator''': the dialog box is displayed without a caption for the unit speaking or a unit image&lt;br /&gt;
** '''unit''': the primary unit for the event is speaking&lt;br /&gt;
** '''second_unit''': the secondary unit for the event is speaking&lt;br /&gt;
&lt;br /&gt;
* '''message''': (translatable) the text to display to the right of the image. ''message'' is sometimes multiple lines; if it is, be sure to use quotes(''' ' ''' or ''' &amp;quot; ''')&lt;br /&gt;
* '''[show_if]''': if present then this message will only be displayed if the conditional statement in this tag is passed (see [[ConditionalActionsWML#Condition_Tags|ConditionalActionsWML]])&lt;br /&gt;
* '''side_for''': (default: all sides) comma-separated list of sides for who message is shown. This will &amp;lt;b&amp;gt;not&amp;lt;/b&amp;gt; work with messages that take user input ([option]/[text_input]), which can only ever be shown to the current player. {{DevFeature1.13|0}} This limitation has been lifted in 1.13.0 and later versions.&lt;br /&gt;
* '''image''': (default: profile image of speaker) the image to display next to the message. Append ~RIGHT() if you want the image to appear on the right side. &lt;br /&gt;
** {{DevFeature1.13|0}} &amp;lt;b&amp;gt;none:&amp;lt;/b&amp;gt; display no image&lt;br /&gt;
* '''caption''': (default: name of speaker) the caption to display beside the image. Name to be displayed. Note: use a translation mark to avoid wmllint errors.&lt;br /&gt;
* '''scroll''': Boolean specifying whether the game view should scroll to the speaking unit. Defaults to ''yes''.&lt;br /&gt;
* '''duration''': (default: 10) the minimum number of frames for this message to be displayed. (A frame lasts about 30 milliseconds.) During this time any dialog decisions will be disregarded.&lt;br /&gt;
* '''sound''': a sound effect (wav file) to play as the message is displayed. This can be a comma-separated list, from which one will be randomly chosen.&lt;br /&gt;
* '''[option]''': No '''[option]''' elements have to be used. If '''[option]''' elements are present, then each option will be displayed in a menu for the user to select one option. ''Note: Messages with options will not be shown at all in prestart events''&lt;br /&gt;
** '''message''': (translatable) the text displayed for the option (see [[DescriptionWML]])&lt;br /&gt;
** '''[show_if]''': if present then this option will only be displayed if the conditional statement in this tag is passed (see [[ConditionalActionsWML#Condition_Tags|ConditionalActionsWML]])&lt;br /&gt;
** '''[command]''': an element containing actions which are executed if the option is selected.&lt;br /&gt;
* '''[text_input]''': there can be only one [text_input] tag. this adds a text input field to the message. ''Note: Messages with text_input will not be shown at all in prestart events''&lt;br /&gt;
** '''variable''': the variable that the user's input will be written to&lt;br /&gt;
** '''label''': a text label to the left of the input field&lt;br /&gt;
** '''max_length''': the maximum number of characters that may be typed into the field&lt;br /&gt;
** '''text''': text that is written into the field in the beginning&lt;br /&gt;
* Check [[EventWML#Multiplayer_safety]] to find out in which events you can safely use '''[option]''' and '''[text_input]''' without causing OOS.&lt;br /&gt;
&lt;br /&gt;
=== Formatting ===&lt;br /&gt;
'''[message]''' and other tags such as unit names (user_description), objectives, and floating text can make use of [http://developer.gnome.org/pango/unstable/PangoMarkupFormat.html Pango markup formatting codes].&lt;br /&gt;
&lt;br /&gt;
Remember to use single quotes (') instead of double quotes (&amp;quot;) within the formatting string, as double quotes cannot be escaped, and the string will appear fragmented and possibly cause errors.&lt;br /&gt;
&lt;br /&gt;
For example, if you wanted to write &amp;quot;You are victorious!&amp;quot; in large, italic, gold letters, you might write it this way:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;span color='#BCB088' size='large' font-style='italic'&amp;gt;You are victorious!&amp;lt;/span&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These are the codes taken from the Pango markup formatting guide:&lt;br /&gt;
&lt;br /&gt;
*'''font''', '''font_desc''': A font description string, such as &amp;quot;Sans Italic 12&amp;quot;.&lt;br /&gt;
*'''font_family''', '''face''': A font family name.&lt;br /&gt;
*'''font_size''', '''size''': Font size in 1024ths of a point, or one of the absolute sizes 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large', or one of the relative sizes 'smaller' or 'larger'.&lt;br /&gt;
*'''font_style''', '''style''': One of 'normal', 'oblique', 'italic'.&lt;br /&gt;
*'''font_weight''', '''weight''': One of 'ultralight', 'light', 'normal', 'bold', 'ultrabold', 'heavy', or a numeric weight.&lt;br /&gt;
*'''font_variant''', '''variant''': One of 'normal' or 'smallcaps'.&lt;br /&gt;
*'''font_stretch''', '''stretch''': One of 'ultracondensed', 'extracondensed', 'condensed', 'semicondensed', 'normal', 'semiexpanded', 'expanded', 'extraexpanded', 'ultraexpanded'.&lt;br /&gt;
*'''foreground''', '''fgcolor''', '''color''': An RGB color specification such as '#00FF00' or a color name such as 'red'.&lt;br /&gt;
*'''background, bgcolor''': An RGB color specification such as '#00FF00' or a color name such as 'red'.&lt;br /&gt;
*'''underline''': One of 'none', 'single', 'double', 'low', 'error'.&lt;br /&gt;
*'''underline_color''': The color of underlines; an RGB color specification such as '#00FF00' or a color name such as 'red'.&lt;br /&gt;
*'''rise''': Vertical displacement, in 10000ths of an em. Can be negative for subscript, positive for superscript.&lt;br /&gt;
*'''strikethrough''': 'true' or 'false' whether to strike through the text.&lt;br /&gt;
*'''strikethrough_color''': The color of strikethrough lines; an RGB color specification such as '#00FF00' or a color name such as 'red'&lt;br /&gt;
*'''fallback''': 'true' or 'false' whether to enable fallback. If disabled, then characters will only be used from the closest matching font on the system. No fallback will be done to other fonts on the system that might contain the characters in the text. Fallback is enabled by default. Most applications should not disable fallback.&lt;br /&gt;
*'''letter_spacing''': Inter-letter spacing in 1024ths of a point.&lt;br /&gt;
*'''gravity''': One of 'south', 'east', 'north', 'west', 'auto'.&lt;br /&gt;
*'''gravity_hint''': One of 'natural', 'strong', 'line'.&lt;br /&gt;
&lt;br /&gt;
== [objectives] ==&lt;br /&gt;
The other tag used for plot development is '''[objectives]'''.&lt;br /&gt;
The '''[objectives]''' tag overwrites any previously set objectives,&lt;br /&gt;
and displays text which should describe the objectives of the scenario.&lt;br /&gt;
Scenario objectives are displayed on the player's first turn after the tag is used,&lt;br /&gt;
or as part of the event if it triggers during that player's turn.&lt;br /&gt;
Objectives can also be accessed at any time in a scenario using the&lt;br /&gt;
&amp;quot;Scenario Objectives&amp;quot; game menu option, making this tag useful for&lt;br /&gt;
scenario-specific information that the player may need to refer to during play.&lt;br /&gt;
&lt;br /&gt;
Attributes of '''[objectives]''':&lt;br /&gt;
* '''side''': Default '0'. The side to set the objectives for. A value of 0 sets objectives for all sides. note: There are side-specific objectives and default objectives, which are used in case a side doesn't have specific ones. Specifying 0 sets the default ones.&lt;br /&gt;
* '''[[StandardSideFilter]]''' tags and keys: Sets the objectives of all matching sides to these passed specifications (the rest of this [objectives] tag). If no sides (such as when passing side=0) or all sides match, sets the default objectives, and the side specific ones for the matching sides otherwise.&lt;br /&gt;
* '''bullet''': Default '• '. Replaces the default bullet, with whatever is passed, for all objectives, gold carryover notes, and notes defined with [note].&lt;br /&gt;
* '''summary''': Displayed first in the objectives text, this should describe the basic objective for the overall scenario.  Can be omitted.&lt;br /&gt;
* '''note''': Displayed last in the objectives text, this is sometimes used for hints or additional information.  Can be omitted.&lt;br /&gt;
* '''victory_string''': Default ' _ &amp;quot;Victory:&amp;quot;', this text precedes the victory objectives.&lt;br /&gt;
* '''defeat_string''': Default ' _ &amp;quot;Defeat:&amp;quot;', this text precedes the defeat objectives.&lt;br /&gt;
* '''gold_carryover_string''': Default ' _ &amp;quot;Gold carryover:&amp;quot;', this text precedes the gold carryover information.&lt;br /&gt;
* '''notes_string''': Default ' _ &amp;quot;Notes:&amp;quot;', this text precedes the notes.&lt;br /&gt;
* '''silent''': Default: not present. If set to &amp;quot;yes&amp;quot;, the objectives are silently changed. Else, they will be shown to the user when appropriate.&lt;br /&gt;
&lt;br /&gt;
Tags of '''[objectives]''':&lt;br /&gt;
* '''[objective]''': describes a win or loss condition. Most scenarios have multiple win or loss conditions, so use a separate [objective] subtag for each line; this helps with translations.&lt;br /&gt;
** '''bullet''': Default '• ' or whatever is set in the parent [objectives] block. Replaces the default bullet, with whatever is provided, for the objective defined by the [objective] block.&lt;br /&gt;
** '''red''': Default '0' for winning objectives, '255' for losing objectives. Overrides the default red coloring of the entire objective, including the bullet.&lt;br /&gt;
** '''green''': Default '255' for winning objectives, '0' for losing objectives. Overrides the default green coloring of the entire objective, including the bullet.&lt;br /&gt;
** '''blue''': Default '0'. Overrides the default blue coloring of the entire objective, including the bullet.&lt;br /&gt;
** '''description''': text for the specific win or loss condition.&lt;br /&gt;
** '''condition''': The color and placement of the text. Values are 'win'(colored green, placed after ''victory_string'') and 'lose'(colored red, placed after ''defeat_string'')&lt;br /&gt;
** '''show_turn_counter''': If set to yes, displays the number of turns remaining in the scenario. Default is no.&lt;br /&gt;
** '''[show_if]''': A condition that disables the objective if it doesn't hold. Conditional objectives are refreshed at '''[show_objectives]''' time only.&lt;br /&gt;
* '''[gold_carryover]''': describes how the gold carryover works in this scenario. This is intended to be a more convenient way of displaying carryover information than using the note= key in [objectives].&lt;br /&gt;
** '''bullet''': Default '• ' or whatever is set in the parent [objectives] block. Replaces the default bullet with whatever is provided.&lt;br /&gt;
** '''red''': Default '255'. Overrides the default red coloring of the entire objective, including the bullet.&lt;br /&gt;
** '''green''': Default '255'. Overrides the default green coloring of the entire objective, including the bullet.&lt;br /&gt;
** '''blue''': Default '192'. Overrides the default blue coloring of the entire objective, including the bullet.&lt;br /&gt;
** '''bonus''' (boolean): whether an early finish bonus is granted. If omitted, early finish bonus is not mentioned.&lt;br /&gt;
** '''carryover_percentage''': the amount of carryover gold. If omitted, the amount is not mentioned.&lt;br /&gt;
* '''[note]''': describes a note, usually used for hints or additional information. This is an easier way of adding several notes than concatenating them together into a single string to use with the ''note='' key.&lt;br /&gt;
** '''bullet''': Default '• ' or whatever is set in the parent [objectives] block. Replaces the default bullet with whatever is provided for the note defined by the [note] block.&lt;br /&gt;
** '''red''': Default '255'. Overrides the default red coloring of the entire note, including the bullet.&lt;br /&gt;
** '''green''': Default '255'. Overrides the default green coloring of the entire note, including the bullet.&lt;br /&gt;
** '''blue''': Default '255'. Overrides the default blue coloring of the entire note, including the bullet.&lt;br /&gt;
** '''description''': the text of the note.&lt;br /&gt;
** '''[show_if]''': The note will not be shown if the specified condition isn't met. Conditional notes are refreshed at '''[show_objectives]''' time only.&lt;br /&gt;
&lt;br /&gt;
== [set_menu_item] ==&lt;br /&gt;
This tag is used to add a custom option in the right-click context menu which can then be used to trigger arbitrary WML commands. The menu items can be set and modified during any event, for example during &amp;quot;start&amp;quot; or &amp;quot;prestart&amp;quot; events. The user can also assign hotkeys to these WML commands unless specified otherwise. When the hotkey is pressed the event will be fired/filtered at the current mouse position.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Due to limitations in portable devices where there are no scroll bars for context menus, there is a hard-coded limit of 7 custom WML menu items. If you really need to have more than 7 menu items, try combining some of them in a submenu. {{DevFeature1.13|0}} This limitation is being removed in a [http://forums.wesnoth.org/viewtopic.php?p=572554#p572554 future version] of Wesnoth.&lt;br /&gt;
&lt;br /&gt;
* '''id''': the unique id for this menu item. If a menu item with this id already exists, it allows you to set specific changes to that item.&lt;br /&gt;
* '''description''': the in-game text that will appear for this item in the menu.&lt;br /&gt;
* '''image''': the image to display next to this item.&lt;br /&gt;
* '''needs_select''': if ''yes'' (default ''no''), then the latest select event (see [[EventWML]]) that triggered before this menu item was chosen will be transmitted over the network before this menu item action will be. This only has any effect in networked multiplayer, and is intended to allow more elaborate menu item behaviour there without causing out of sync errors. If you don't know what this means, just leave it false.&lt;br /&gt;
* '''use_hotkey''': if ''no'' (default ''yes''), then the user cannot assign hotkeys to this menu item. If ''only'', the menu item is only accessible via hotkeys, not via right-click context; you can use this in combination with [default_hotkey] if you want custom hotkeys in your campaign/mp. &lt;br /&gt;
* '''[show_if]''': If present, the menu item will only be available if the conditional statement (see [[ConditionalActionsWML#Condition_Tags|ConditionalActionsWML]]) within evaluates to true. When this is evaluated, the WML variables ''$x1'' and ''$y1'' will point to the location on which the context menu was invoked, so it's possible to for example only enable the option on empty hexes or on a particular unit.&lt;br /&gt;
* '''[filter_location]''': contains a location filter similar to the one found inside Single Unit Filters (see [[FilterWML]]). The menu item will only be available on matching locations.&lt;br /&gt;
* '''[default_hotkey]''': contains a hotkey WML to specify what hotkey to assign to this, '''if the user has no hotkey assigned to this yet'''. (Unlike the rest of a menu item definition, modifying this tag has no effect on the game; it is only effective when initially defining a menu item.) Hotkey WML matches the format in the preferences file and contains the following keys:&lt;br /&gt;
** '''key''': a string that contains the key to assign to this.&lt;br /&gt;
** '''alt''', '''shift''', '''cmd'''(apple only), '''ctrl''':  boolean values.&lt;br /&gt;
* '''[command]''': contains the WML actions to be executed when the menu item is selected. Again, the WML variables ''$x1'' and ''$y1'' will point to the location on which the context menu was invoked on.&lt;br /&gt;
** '''delayed_variable_substitution ''' (boolean yes|no, default: yes): If no, forces a variable substitution run onto the wml included in this [command] block. Use this, if you want variables which are to substitute to get the values they have at execution time of the event where this set_menu_item appears. Other than that, they get the values they have at invocation time of the menu item.&lt;br /&gt;
&lt;br /&gt;
== [clear_menu_item] ==&lt;br /&gt;
&lt;br /&gt;
Removes a menu item from the scenario.&lt;br /&gt;
Normally menu items are, including all their defining wml, automatically carried over between scenarios. This tag prevents this. (The behavior is comparable to set_variable/clear_variable).&lt;br /&gt;
* '''id''': (string): id of the menu item to clear. Can be a comma-separated list.&lt;br /&gt;
&lt;br /&gt;
== Other interface tags ==&lt;br /&gt;
&lt;br /&gt;
The following tags are also action tags:&lt;br /&gt;
&lt;br /&gt;
=== [item] ===&lt;br /&gt;
Makes a graphical item appear on a certain hex. Note this only places the graphics for an item. It does not make the item do anything. Use a moveto event to make moving onto the item do something. &amp;lt;tt&amp;gt;''('''Hint:''' There are a number of predefined items that are used in various campaigns that you can make use of. You can find [http://www.wesnoth.org/macro-reference.xhtml#file:items.cfg a list of them] if you look into the items.cfg file in the wesnoth install directory (under /data/core/macros).)''&amp;lt;/tt&amp;gt;&lt;br /&gt;
* '''x''', '''y''': the location to place the item. (only for [event][item]: full [[StandardLocationFilter|SLF]] support)&lt;br /&gt;
* '''image''': the image (in ''images/'' as .png) to place on the hex. This image is aligned with the top-left of the hex (which is 72 pixels wide and 72 pixels tall). It is drawn underneath units. ''('''Hint:''' If using an image smaller than 72x72, then it might be useful to [[ImagePathFunctionWML#Blit_Function|BLIT]] the image onto &amp;lt;tt&amp;gt;misc/blank-hex.png&amp;lt;/tt&amp;gt; (a blank 72x72 image).)''&lt;br /&gt;
* '''halo''': an image to place centered on the hex. It is drawn on top of units. Use this instead of ''image'' if the image is bigger than the hex or if you want to animate an image.&lt;br /&gt;
''Example (where the integer after the colon is the duration of each frame or square bracket expansion as per AnimationWML is used): halo=scenery/fire1.png:100,scenery/fire2.png:100,scenery/fire3.png:100,scenery/fire4.png:100,scenery/fire5.png:100,scenery/fire6.png:100,scenery/fire7.png:100,scenery/fire8.png:100''&lt;br /&gt;
or equivalently (requires Wesnoth 1.11.2+):&lt;br /&gt;
''halo=scenery/fire[1~8].png:100''&lt;br /&gt;
* '''team_name''': name of the team for which the item is to be displayed (hidden for others). For multiple teams just put all the names in one string, for example separated by commas.&lt;br /&gt;
* '''visible_in_fog''': whether the item should be visible through fog or not. Default yes.&lt;br /&gt;
* '''redraw''': (boolean yes|no, default: yes): If no, disables implicit calls to [[InterfaceActionsWML#.5Bredraw.5D|[redraw]]] when placing the items.&lt;br /&gt;
&lt;br /&gt;
=== [remove_item] ===&lt;br /&gt;
Removes any graphical items on a given hex.&lt;br /&gt;
* [[StandardLocationFilter]]: the hexes to remove items off&lt;br /&gt;
* '''image''' if specified, only removes the given image item (This image name must include any [[ImagePathFunctionWML|image path functions]] appended to the original image name.)&lt;br /&gt;
&lt;br /&gt;
=== [print] ===&lt;br /&gt;
Displays a message across the screen. The message will disappear after a certain time.&lt;br /&gt;
* '''text''': (translatable) the text to display.&lt;br /&gt;
* '''size''': (default=12) the pointsize of the font to use&lt;br /&gt;
* '''duration''': (default=50) the length of time to display the text for. This is measured in the number of 'frames'. A frame in Wesnoth is usually displayed for around 30ms.&lt;br /&gt;
* '''red''', '''green''', '''blue''': (default=0,0,0) the color to display the text in. Values vary from 0-255.&lt;br /&gt;
=== [move_unit_fake] ===&lt;br /&gt;
Moves an image of a unit along a certain path on the map. The path does not need to be a continuous list of adjacent hexes, so for example only the start and end points can be given, in which case the straightest line between those points will be calculated and used.&lt;br /&gt;
* '''type''': the type of the unit whose image to use&lt;br /&gt;
* '''x''': a comma-separated list of x locations to move along&lt;br /&gt;
* '''y''': a comma-separated list of y locations to move along (x and y values are matched pairs)&lt;br /&gt;
* '''side''': the side of the fake unit, used for team-coloring the fake unit&lt;br /&gt;
* '''gender''': the gender of the fake unit. Example: gender=female&lt;br /&gt;
* '''variation''': the variation of the fake unit. Example: variation=undead&lt;br /&gt;
* '''image_mods''': [[ImagePathFunctionWML|image path functions]] sequence to be applied on the fake unit.&lt;br /&gt;
* '''force_scroll''':  Whether to scroll the map or not even when [[#.5Block_view.5D|[lock_view]]] is in effect or ''Follow Unit Actions'' is disabled in ''Advanced Preferences''. Defaults to ''yes'' starting with version '''1.11.6'''; the attribute did not exist in previous versions and this action behaved as if ''no'' was passed instead.&lt;br /&gt;
&lt;br /&gt;
=== [move_units_fake] ===&lt;br /&gt;
moves multiple images of units along paths on the map. These units are moved in lockstep.&lt;br /&gt;
* '''[fake_unit]''': A fake unit to move&lt;br /&gt;
** '''type''': the type of unit whose image to use&lt;br /&gt;
** '''x''': a comma-separated list of x locations to move along&lt;br /&gt;
** '''y''': a comma-separated list of y locations to move along (x and y values are matched pairs)&lt;br /&gt;
** '''side''': the side of the fake unit, used for team-coloring the fake unit&lt;br /&gt;
** '''skip_steps''': the number of steps to skip before this unit starts moving&lt;br /&gt;
=== [hide_unit] ===&lt;br /&gt;
Temporarily prevents the engine from displaying the given unit. The unit does not become invisible, as it would be with the '''[hides]''' ability; it is still the same plain unit, but without an image. Useful in conjunction with '''[move_unit_fake]''': to move a leader unit into position on-screen. Until 1.8 each '''[hide_unit]''' tag only hides one unit.&lt;br /&gt;
* [[StandardUnitFilter]]: All matching units will be hidden&lt;br /&gt;
&lt;br /&gt;
=== [unhide_unit] ===&lt;br /&gt;
Stops the currently hidden units from being hidden.&lt;br /&gt;
* [[StandardUnitFilter]]: Only the matching units will be unhidden&lt;br /&gt;
&lt;br /&gt;
=== [lock_view] ===&lt;br /&gt;
Locks gamemap view scrolling for human players, so they cannot scroll the gamemap view until it is unlocked. WML or Lua actions such as '''[scroll_to]''' will continue to work normally, as they ignore this restriction; the locked/unlocked state is preserved when saving the current game.&lt;br /&gt;
&lt;br /&gt;
This feature is generally intended to be used in cutscenes to prevent the player scrolling away from scripted actions. &lt;br /&gt;
&lt;br /&gt;
=== [unlock_view] ===&lt;br /&gt;
Unlocks gamemap view scrolling for human players.&lt;br /&gt;
&lt;br /&gt;
=== [scroll] ===&lt;br /&gt;
Scroll a certain number of pixels in a given direction. Useful for earthquake/shaking effects.&lt;br /&gt;
* '''x''', '''y''': the number of pixels to scroll along the x and y axis&lt;br /&gt;
* '''side''': the side or sides for which this should happen. By default, the [scroll] happens for everyone.&lt;br /&gt;
* '''[filter_side]''': a [[StandardSideFilter]] to select the sides for which this should happen. By default, the [scroll] happens for everyone.&lt;br /&gt;
&lt;br /&gt;
=== [scroll_to] ===&lt;br /&gt;
Scroll to a given hex&lt;br /&gt;
* '''x''', '''y''': the hex to scroll to&lt;br /&gt;
* [[StandardLocationFilter]], do not use a [filter_location] sub-tag. If more than one location matches the filter, only the first matching location will be used.&lt;br /&gt;
* '''check_fogged''': whether to scroll even to locations covered in fog or shroud. Possible values ''true'' (don't scroll to fog) and ''false'' (scroll even to fog), with ''false'' as the default.&lt;br /&gt;
* '''immediate''': whether to instantly warp to the target hex regardless of the scroll speed setting in Preferences (defaults to ''false'').&lt;br /&gt;
* '''side''': the side or sides for which this should happen. By default, the [scroll_to] happens for everyone.&lt;br /&gt;
* '''[filter_side]''': a [[StandardSideFilter]] to select the sides for which this should happen. By default, the [scroll_to] happens for everyone.&lt;br /&gt;
&lt;br /&gt;
=== [scroll_to_unit] ===&lt;br /&gt;
Scroll to a given unit&lt;br /&gt;
* [[StandardUnitFilter]]&lt;br /&gt;
* '''check_fogged''': whether to scroll even to locations covered in fog or shroud. Possible values ''true'' (don't scroll to fog) and ''false'' (scroll even to fog), with ''false'' as the default.&lt;br /&gt;
* '''immediate''': whether to instantly warp to the target hex regardless of the scroll speed setting in Preferences (defaults to ''false'').&lt;br /&gt;
* '''for_side''': the side or sides for which this should happen. By default, the [scroll_to_unit] happens for everyone.&lt;br /&gt;
* '''[for_side]''': a [[StandardSideFilter]] to select the sides for which this should happen. By default, the [scroll_to_unit] happens for everyone.&lt;br /&gt;
&lt;br /&gt;
=== [select_unit] ===&lt;br /&gt;
Selects a given unit.&lt;br /&gt;
* [[StandardUnitFilter]]: The first unit found will be selected.&lt;br /&gt;
* '''fire_event''': whether a ''select'' event should be triggered or not (def. ''no''). (Note that select events aren't multiplayer save.)&lt;br /&gt;
* '''highlight''': whether the unit's current hex should be highlighted (def. ''yes'').&lt;br /&gt;
&lt;br /&gt;
=== [sound]===&lt;br /&gt;
Plays a sound&lt;br /&gt;
* '''name''': the filename of the sound to play (in ''sounds/'' as .wav or .ogg)&lt;br /&gt;
* '''repeat''': repeats the sound for a specified additional number of times (default=0)&lt;br /&gt;
=== [sound_source] ===&lt;br /&gt;
Creates a sound source. &amp;quot;Sound sources&amp;quot; is a general name for a mechanism which makes possible for map elements to emit sounds according to some rules, where &amp;quot;map elements&amp;quot; can be specific locations or terrain types. For now, only sound sources tied to locations are supported.&lt;br /&gt;
* '''id''': a unique identification key of the sound source&lt;br /&gt;
* '''sounds''': a list of comma separated, randomly played sounds associated with the sound source&lt;br /&gt;
* '''delay''': a numerical value (in milliseconds) of the minimal delay between two playbacks of the source's sound if the source remains visible on the screen; if one scrolls out and back in, the source will be considered as ready to play&lt;br /&gt;
* '''chance''': a percentage (a value from 0 to 100) describing the chance of the source being activated every second after the delay has passed or when the source's location appears on the screen (note that it cannot play more than one file at the same time)&lt;br /&gt;
* '''check_fogged''': possible values &amp;quot;true&amp;quot; and &amp;quot;false&amp;quot; - if true the source will not play if its locations are fogged&lt;br /&gt;
* '''check_shrouded''': possible values &amp;quot;true&amp;quot; and &amp;quot;false&amp;quot; - if true the source will not play if its locations are shrouded&lt;br /&gt;
* '''x,y''': similar to x,y as found in a [[StandardLocationFilter]], these are the locations associated with the sound source&lt;br /&gt;
* '''fade_range''' (default = 3): distance in hexes that determines a &amp;quot;circular&amp;quot; area around the one specified by '''full_range''' where sound volume fades out linearly&lt;br /&gt;
* '''full_range''' (default = 14): distance in hexes that determines a &amp;quot;circular&amp;quot; area where source plays with full volume, relative to screen center&lt;br /&gt;
* '''loop''': number of times a sound sample should be looped if it stays visible. -1 means infinite (~65000)&lt;br /&gt;
&lt;br /&gt;
=== [remove_sound_source] ===&lt;br /&gt;
Removes a previously defined sound source.&lt;br /&gt;
* '''id''': the identification key of the sound source to remove&lt;br /&gt;
&lt;br /&gt;
=== [music]===&lt;br /&gt;
Switches to playing different music&lt;br /&gt;
* '''name''': the filename of the music to play (in ''music/'' as .ogg)&lt;br /&gt;
* see [[MusicListWML]] for the correct syntax&lt;br /&gt;
===[volume]===&lt;br /&gt;
Changes the game volume to a percent of the preferences volume for the game being played. Values can go from 0 to 100:  &lt;br /&gt;
* '''music''':  Changes the music volume.&lt;br /&gt;
* '''sound''':  Changes the sound volume.&lt;br /&gt;
=== [color_adjust]===&lt;br /&gt;
Tints the color of the screen.&lt;br /&gt;
* '''red''', '''green''', '''blue''': values from -255 to 255, the amount to tint by for each color&lt;br /&gt;
=== [delay] ===&lt;br /&gt;
Pauses the game.&lt;br /&gt;
* '''time''': the time to pause in milliseconds&lt;br /&gt;
* '''accelerate ''' (boolean yes|no, default no): {{DevFeature1.13|0}} whether the delay is affected by acceleration.&lt;br /&gt;
&lt;br /&gt;
=== [redraw] ===&lt;br /&gt;
Redraws the screen (this normally isn't done during events, although some of the other interface actions cause the screen or parts of it to be redrawn).&lt;br /&gt;
* '''clear_shroud''' (boolean yes|no, default no): If yes, clears fog and shroud around existing units. Useful if you, for example, spawn friendly units in the middle of an event and want the shroud to update accordingly (otherwise units that spawn inside fog would remain invisible for the duration of the event, since the fog would not automatically get cleared around them).&lt;br /&gt;
* '''[[StandardSideFilter]]''': the sides for which to recalculate fog and shroud.&lt;br /&gt;
* '''side''': If used (forces clear_shroud=yes), clears fog and shroud for that side.&lt;br /&gt;
&lt;br /&gt;
=== [unit_overlay] ===&lt;br /&gt;
Sets an image that will be drawn over a particular unit, and follow it around&lt;br /&gt;
* [[StandardUnitFilter]]: All matching units will get the overlay (do not use [filter])&lt;br /&gt;
* '''image''': the image to place on the unit&lt;br /&gt;
&lt;br /&gt;
=== [remove_unit_overlay] ===&lt;br /&gt;
removes a particular overlayed image from a unit&lt;br /&gt;
* [[StandardUnitFilter]]: The overlay will get removed from all matching units (do not use [filter])&lt;br /&gt;
* '''image''': the image to remove from the unit&lt;br /&gt;
&lt;br /&gt;
=== [animate_unit] ===&lt;br /&gt;
Uses an animation of a unit to animate it on screen (if the unit has the corresponding animation).&lt;br /&gt;
* '''flag''': The key to find the custom animation in the unit description (see the '''[extra_anim]''' description in [[AnimationWML]]). Standard animations can be triggered with the following keywords: ''leading recruited standing idling levelout levelin healing healed poisoned movement defend attack death victory pre_teleport post_teleport''&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument, see [[FilterWML]]. By default, the unit at the event location will be animated. You can use this tag to choose any other unit to animate.&lt;br /&gt;
* '''[primary_attack]''': If this tag is not present, the filter for animation will be triggered with no attack. If it is here, all attacks from the unit will be filtered, and a matching one will be used to filter the animation. Takes a weapon filter as argument, see [[FilterWML]].&lt;br /&gt;
* '''[secondary_attack]''': Similar to '''[primary_attack]'''. May be needed to trigger a defense animation correctly, if there are more than one animations available for the defending unit.&lt;br /&gt;
* '''hits''': yes/no/hit/miss/kill: which according variation of a attack/defense animation shall be chosen (required)&lt;br /&gt;
* '''text''': a text to hover during the animation &lt;br /&gt;
* '''red''': red value for the text color (0-255)&lt;br /&gt;
* '''green''': green value for the text color&lt;br /&gt;
* '''blue''': blue value for the text color&lt;br /&gt;
* '''with_bars''': yes/no: whether to display the status bars during the animation (e.g. the hitpoint bar)&lt;br /&gt;
* '''[animate]''': a sub block with the same syntax as '''[animate_unit]''' except that the '''[filter]''' block is mandatory to find the unit. This block will find and animate another unit simultaneously.&lt;br /&gt;
* '''[facing]''': a [[StandardLocationFilter]] specifying what direction the unit should be facing when animated&lt;br /&gt;
&lt;br /&gt;
=== [label] ===&lt;br /&gt;
Places a label on the map.&lt;br /&gt;
* '''x''', '''y''': the location of the label. {{DevFeature1.13|1}} (only for [event][label]: full [[StandardLocationFilter|SLF]] support)&lt;br /&gt;
* '''text''': what the label should say&lt;br /&gt;
* '''team_name''': if specified, the label will only be visible to the given team.&lt;br /&gt;
* '''color''': color of the label. The format is r,g,b; r, g and b are numbers between 0 and 255.&lt;br /&gt;
* '''visible_in_fog''': whether the label should be visible through fog or not. Default yes.&lt;br /&gt;
* '''visible_in_shroud''': whether the label should be visible through shroud or not. Default no.&lt;br /&gt;
* '''immutable''': whether this label is protected from being removed or changed by players. Default yes.&lt;br /&gt;
&lt;br /&gt;
=== [floating_text]===&lt;br /&gt;
Floats text (similar to the damage and healing numbers) on the given locations.&lt;br /&gt;
* [[StandardLocationFilter]]: the text will be floated on all matching locations simultaneously.&lt;br /&gt;
* '''text''': the text to display.&lt;br /&gt;
&lt;br /&gt;
The default text color is &amp;lt;span style=&amp;quot;color: #6b8cff;&amp;quot;&amp;gt;'''#6b8cff'''&amp;lt;/span&amp;gt;. To change the color, use [[#Formatting|Pango markup]]. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Float some golden yellow text at 20,20.&lt;br /&gt;
[floating_text]&lt;br /&gt;
   x,y=20,20&lt;br /&gt;
   text=&amp;quot;&amp;lt;span color='#cccc33'&amp;gt;&amp;quot; + _ &amp;quot;Your text here&amp;quot; + &amp;quot;&amp;lt;/span&amp;gt;&amp;quot;&lt;br /&gt;
[/floating_text]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [deprecated_message] ===&lt;br /&gt;
Shows a deprecated message in the message area, this feature is only intended to be used to warn about deprecated macros in mainline. The message is not translatable.&lt;br /&gt;
* '''message''': the message to show.&lt;br /&gt;
=== [wml_message] ===&lt;br /&gt;
Outputs a message to Wesnoth's console output. Intended for campaign designers to output silent text to the console, without annoying the player; then, that text might contain information useful for later bug-reporting. The log domain for it is '''wml''', and the '''debug/dbg''' log level is available for use with the '''logger''' attribute. Depending on the current log level ('''error''' by default), which may be changed with the in-game :log command, or the --log-&amp;lt;level&amp;gt;=wml command line switch, the messages are echoed to the in-game chat.&lt;br /&gt;
* '''message''': the message to show.&lt;br /&gt;
* '''logger''': the Wesnoth engine output logger that should catch the text; this might be 'err' (the errors log level), 'warn'/'wrn' (the warnings log level) or anything else (the information log level). Not all information will be displayed depending on the log level chosen when starting Wesnoth.&lt;br /&gt;
&lt;br /&gt;
Note: As of 1.9.4/1.9.5 (r48805) the following &amp;quot;loggers&amp;quot; should work: If in [wml_message]: err/error, warn/wrn/warning, debug/dbg; using the :log command: Only the long forms error, warning, info and debug (this part gathered by trying rather than source inspecting). The long forms are most likely also the only ones working when starting wesnoth with --log-&amp;lt;level&amp;gt;=wml.&lt;br /&gt;
For log level warning or error (as during normal play), only wml_messages with logger error or warning display (for both). With logger info or debug, additionally wml_messages with logger info or debug display (for both).&lt;br /&gt;
&lt;br /&gt;
=== [open_help] ===&lt;br /&gt;
Opens the in-game help.&lt;br /&gt;
* '''topic''': the id of the topic to open&lt;br /&gt;
=== [show_objectives] ===&lt;br /&gt;
refreshes the objectives defined by [objectives] and its [show_if] tags, and displays them. (It is also called whenever the user explicitly asks for the objectives; this matters only if the tag was overridden by a [[LuaWML#register_wml_action|Lua]] script.)&lt;br /&gt;
* '''side''': the side to show the objectives. If not set, all sides are used.&lt;br /&gt;
* '''[[StandardSideFilter]]''' tags and keys: Tag affects the matching sides instead of just all or the one given by the integer value of the side= key.&lt;br /&gt;
&lt;br /&gt;
=== [chat] ===&lt;br /&gt;
Displays a message in the chat area, not visible for observers. Alternative visible for observers: [[LuaWML:Display#wesnoth.message]]&lt;br /&gt;
* '''speaker''': (default=&amp;quot;WML&amp;quot;) A string for the name of the sender of the message.&lt;br /&gt;
* '''message''': The message that should be displayed.&lt;br /&gt;
* '''[[StandardSideFilter]]''' tags and keys as argument; if the same client controls multiple sides that match, then the message will only be displayed once.&lt;br /&gt;
&lt;br /&gt;
== Useful Macros ==&lt;br /&gt;
There are some predefined macros that you find useful for interface actions. You can find a complete list along with a detailed explanation of how they work [http://www.wesnoth.org/macro-reference.xhtml here].&lt;br /&gt;
* '''{HIGHLIGHT_UNIT}''' Highlight a unit on the map. Use this to show important units&lt;br /&gt;
* '''{HIGHLIGHT_IMAGE}''' Places and highlights an image on the map. Use this to show important items or locations&lt;br /&gt;
* '''{SET_IMAGE}''' Places an image on the map which has no other function.&lt;br /&gt;
* '''{QUAKE &amp;lt;soundfile&amp;gt;}''' Creates a tremor-like screenshake and plays &amp;lt;soundfile&amp;gt;. For example, '''{QUAKE (rumble.ogg)}'''.&lt;br /&gt;
* '''{FLASH_WHITE}''' Flash the screen white momentarily. You can also replace WHITE with RED, BLUE or GREEN for a different colour.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[DirectActionsWML]]&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56363</id>
		<title>ImagePathFunctions</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56363"/>
		<updated>2015-05-03T10:46:36Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* Black and White Function */ Fix version number&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Image Path Functions provide a simple method for WML coders to alter the way their specified images will be displayed in the game. All of the function parameters are included at the end of an image path and should not contain any spaces or special characters (other than those specified here).&lt;br /&gt;
&lt;br /&gt;
If you need to practice it without having to reload all WML, you can use an add-on named ''Image loading tester'' from the 1.10 add-on server.&lt;br /&gt;
&lt;br /&gt;
== Team-Color Function ==&lt;br /&gt;
In Wesnoth version 1.2, the only Image Path Function was '''~TC()''', which took two comma-separated parameters: the team number and the source color palette. The valid values for both of these parameters are defined in the file ''data/team-colors.cfg''&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~TC(''' ''team number'' ''',''' ''source color palette'' ''')'''&lt;br /&gt;
*''team number'' - this is the first parameter, a number 1-9 signifying the team number of a unit. Number 1 typically means the red team, 2 typically means the blue team, and so on (unless the scenario color settings for any side have been altered).&lt;br /&gt;
*''source color palette'' - the second parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
&lt;br /&gt;
== Re-Color Function ==&lt;br /&gt;
May be used to change some colors in an image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~RC(''' ''source color palette'' '''&amp;gt;''' ''color range ID'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''color range ID'' - this is the second parameter, signifying the ID of a color range defined in the file ''data/core/team-colors.cfg'' (or it may be a custom ID for a color range defined locally).  &lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
In the following example, the magenta regions in an elvish captain's image are turned  a healthy shade of green:&lt;br /&gt;
&lt;br /&gt;
  [message]&lt;br /&gt;
      speaker=narrator&lt;br /&gt;
      image=units/elves-wood/captain.png~RC(magenta&amp;gt;green)&lt;br /&gt;
      message=_ &amp;quot;Now I am on the green team.&amp;quot;&lt;br /&gt;
  [/message]&lt;br /&gt;
&lt;br /&gt;
The IDs of the color ranges may be the lowercased English name of the palette's base color (e.g. 'red', 'brown', etc.). They may also be numeric color indices from the palette WML included with the game, but this is not recommended.&lt;br /&gt;
&lt;br /&gt;
== Palette-switch Function ==&lt;br /&gt;
May be used to change colors in an image following the specifications of a source and target (new) palette.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~PAL(''' ''source color palette'' '''&amp;gt;''' ''target color palette'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, such as magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''target color palette'' - the new palette to take the place of the source colors in the image.&lt;br /&gt;
&lt;br /&gt;
== Flip Function ==&lt;br /&gt;
May be used to flip an image horizontally and/or vertically.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~FL(''' ''optional argument list'' ''')'''&lt;br /&gt;
*''vertical'' - if the string &amp;quot;vert&amp;quot; is found anywhere in the argument list, the image will be flipped vertically.&lt;br /&gt;
*''horizontal'' - if the string &amp;quot;horiz&amp;quot; is found anywhere in the argument list, the image will be flipped horizantally.&lt;br /&gt;
*if the argument list is empty, the image will only be flipped horizontally.&lt;br /&gt;
&lt;br /&gt;
== Rotate Function ==&lt;br /&gt;
May be used to rotate an image by a multiple of 90 degrees.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~ROTATE(''' ''degrees'' ''')'''&lt;br /&gt;
* ''degrees'' - The number of degrees by which the image will be rotated. This must be a multiple of 90. Positive numbers indicate clockwise rotation, while negative numbers indicate counter-clockwise. (Zero indicates no rotation.)&lt;br /&gt;
If the number of degrees is omitted, a quarter turn (90 degrees) clockwise is assumed.&lt;br /&gt;
&lt;br /&gt;
== Greyscale Function ==&lt;br /&gt;
May be used to greyscale the image (turn to black and white)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~GS( )'''&lt;br /&gt;
&lt;br /&gt;
== Black and White Function ==&lt;br /&gt;
{{devfeature1.13|1}}&lt;br /&gt;
May be used to convert the image to pure black and white, without grey pixels. &lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BW(threshold)'''&lt;br /&gt;
* ''threshold'': a value between 0 and 255 (both limits included). All pixels are converted as greyscale first, and if their average value is greater than the threshold they become white, otherwise they become black.&lt;br /&gt;
&lt;br /&gt;
== Sepia Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
May be used to give to the image a sepia tint (like in old pictures).&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~SEPIA()'''&lt;br /&gt;
&lt;br /&gt;
== Negative Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
Also known as ''invert'', it negates all the RGB values of the image, giving it an effect similar to a photographic negative.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~NEG( )'''&lt;br /&gt;
&lt;br /&gt;
== Crop Function ==&lt;br /&gt;
Extracts a rectangular section of an image file.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~CROP(x,y,width,height)'''&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates for the rectangular section extracted. Must be greater or equal than zero, and inside the image's bounds.&lt;br /&gt;
* ''width'': width of the selected region. Must be less than or equal to the original image's width, and must not be negative.&lt;br /&gt;
* ''height'': height of the selected region. Must be less than or equal to the original image's height, and must not be negative.&lt;br /&gt;
&lt;br /&gt;
== Blit Function ==&lt;br /&gt;
Blit the parameter image on the main image. Example: peasant.png~BLIT(hat.png,30,10)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLIT(src,x,y)'''&lt;br /&gt;
* ''src'': an image file used as source for the blit, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to blit. Must be greater or equal than zero. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
== Mask Function ==&lt;br /&gt;
Remove parts of the main image using the parameter image as a mask. Example: grass.png~MASK(circle.png) will give a circle of grass.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~MASK(mask,x,y)'''&lt;br /&gt;
* ''mask'': an image file used as mask, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to put the mask. Parts ouside of the mask are considered transparent. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
Only the alpha channel of the mask is used and each alpha value will be the maximum alpha of the resulting image. This means that the fully-transparent parts of the mask will erase the corresponding parts of the image, but also that a semi-transparent mask will create a semi-transparent image. &lt;br /&gt;
&lt;br /&gt;
== Color-shift function ==&lt;br /&gt;
Performs simple per-channel color shifts by adding the arguments to the respective color channels.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
''Multi-channel:'' '''~CS(r,g,b)'''&lt;br /&gt;
''Single-channel:'' '''~R(v)''', '''~G(v)''', '''~B(v)'''&lt;br /&gt;
&lt;br /&gt;
The multichannel syntax assumes all arguments are set to zero initially, so one can use, e.g. ~CS(2,4) to add +2 and +4 units to the red and green channels respectively, leaving the blue channel intact. Arguments may be negative to diminish a channel's value; this can be used to change an image's brightness. Checks for out-of-range arguments or results (less than 0 or greater than 255) are made, so the resultant values are truncated if necessary.&lt;br /&gt;
&lt;br /&gt;
The single channel syntax behaves exactly the same, except that only single-channel modifications are made per function. However, one can stack them to produce the same behavior as ~CS(), e.g. ~R(r)~G(g)~B(b), but that tends to be just a performance loss.&lt;br /&gt;
&lt;br /&gt;
== Color-blend function ==&lt;br /&gt;
Blends the image with the given color to produce a more controlled tinting effect than color-shifting, independently of the image's contents.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLEND(r,g,b,o)'''&lt;br /&gt;
&lt;br /&gt;
The color is defined by the ''r'', ''g'', and ''b'' parameters (integers ranging from 0 to 255). The ''o'' (opacity) parameter controls the amount by which the given color will be blended into the image, and may be specified either as a factor from 0.0 to 1.0, or percentage up to 100%. Thus, ~BLEND(r,g,b,0.5) and ~BLEND(r,g,b,50%) are equivalent.&lt;br /&gt;
&lt;br /&gt;
== Lightmap color-shift function ==&lt;br /&gt;
Performs per-pixel and per-channel color shifts using another image (a &amp;quot;lightmap&amp;quot;) as source, allowing to create textured light effects.&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~L(lightmap)'''&lt;br /&gt;
&lt;br /&gt;
For each pixel of the original image, it checks the RGB values from the corresponding pixel of the lightmap, slightly transform them, then add these values to the original pixel.&lt;br /&gt;
&lt;br /&gt;
The transformation involved is done to convert the (0,255) spectrum to (-255,255), allowing to add or subtract color. The formula is (x-128)*2, which means that 0 gives -256, 128 gives 0 and 255 gives 254. So, the no-effect lightmap is a fully gray image (RGB = 128,128,128) and any non-gray pixel will shift the colors of the original.&lt;br /&gt;
&lt;br /&gt;
Note that the lightmap will be scaled to the same dimensions as the original image.&lt;br /&gt;
&lt;br /&gt;
== Image-scaling function ==&lt;br /&gt;
Scales a graphic up or down.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~SCALE( ''new_width'', ''new_height'' )&lt;br /&gt;
&lt;br /&gt;
The ''new_width'' and ''new_height'' parameters are taken as the image's original width or height, respectively, if one of them happens to be zero. Negative values are treated in the same way, but an error is printed in stderr.&lt;br /&gt;
&lt;br /&gt;
== Opacity modifying function ==&lt;br /&gt;
Changes an image's opacity at render time.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~O( ''factor or percentage%'' )'''&lt;br /&gt;
&lt;br /&gt;
If the argument includes the percentage symbol (''%''), it will be treated as a percentage of full (real) opacity; an image will be displayed at its native opacity with ~O(100%).&lt;br /&gt;
&lt;br /&gt;
Without the percentage symbol, the argument is assumed to be a factor by which the image's native opacity should be multiplied. Thus, ~O(0.5) and ~O(50%) are equivalent forms of specifying to reduce an image's opacity by half.&lt;br /&gt;
&lt;br /&gt;
== Blurring function ==&lt;br /&gt;
Blurs a graphic at render time using the same algorithm used for in-game dialogs.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BL( ''radius'' )'''&lt;br /&gt;
&lt;br /&gt;
== Overlay function ==&lt;br /&gt;
Puts a time-of-day overlay on the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~LIGHTEN()'''&lt;br /&gt;
&lt;br /&gt;
'''~DARKEN()'''&lt;br /&gt;
&lt;br /&gt;
== Background coloring function ==&lt;br /&gt;
Sets the color of all the (semi-)transparent pixels of the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BG(r,g,b)'''&lt;br /&gt;
&lt;br /&gt;
== Null function ==&lt;br /&gt;
Does nothing.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~NOP()'''&lt;br /&gt;
&lt;br /&gt;
== XBRZ function ==&lt;br /&gt;
Scales functions using the XBRZ algorithm. You may scale things up either 2x, 3x, 4x, or 5x. The scaling tries to preserve the pixel art nature.&lt;br /&gt;
&lt;br /&gt;
'''~XBRZ(n)'''&lt;br /&gt;
&lt;br /&gt;
== SCALE_SHARP function ==&lt;br /&gt;
Scales functions using a nearest neighbor algorithm. Specify width and height. (It has the same syntax as ~SCALE.)&lt;br /&gt;
&lt;br /&gt;
'''~SCALE_SHARP(200,300)'''&lt;br /&gt;
&lt;br /&gt;
== PLOT_ALPHA ==&lt;br /&gt;
At each pixel, the color is replaced with a grey-tone reflecting the alpha value at that pixel, and the new image is fully opaque. Useful for plotting the alpha to help debug an IPF or inspect a sprite.&lt;br /&gt;
&lt;br /&gt;
'''~PLOT_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== WIPE_ALPHA ==&lt;br /&gt;
At each pixel, the alpha value is discarded and the pixel is made fully opaque. Useful again for diagnostics.&lt;br /&gt;
&lt;br /&gt;
'''~WIPE_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== ADJUST_ALPHA ==&lt;br /&gt;
&lt;br /&gt;
Scales the alpha value at each pixel down by a fixed factor. The argument is either a %, or an integer from 0 to 255, in which case it is divided by 255 and reinterpretted as a %.&lt;br /&gt;
&lt;br /&gt;
'''~ADJUST_ALPHA(n)'''.&lt;br /&gt;
&lt;br /&gt;
== Precedence of Functions  ==&lt;br /&gt;
&lt;br /&gt;
All functions are applied in left-to-right order, with the exception of RC(), TC() and PAL() which are applied always before any other functions. Standard team coloring for a unit is applied after all custom RC(), TC() and PAL() functions but before any other functions.&lt;br /&gt;
That is, stuff like &amp;quot;units/elves-wood/fighter.png~CROP(20,20,40,40)~CROP(10,10,10,10)&amp;quot; would result in taking a crop to a 40x40 rectangle whose top-left corner is x=20, y=20; and then taking a crop from ''that'' rectangle with x=10, y=10, w=10, h=10. The result is the area x=30, y=30, w=10, h=10 from the original graphic.&lt;br /&gt;
&lt;br /&gt;
[[Category:WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56362</id>
		<title>ImagePathFunctions</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56362"/>
		<updated>2015-05-03T10:46:07Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: ImagePathFunctionWML: added ~BW() function&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Image Path Functions provide a simple method for WML coders to alter the way their specified images will be displayed in the game. All of the function parameters are included at the end of an image path and should not contain any spaces or special characters (other than those specified here).&lt;br /&gt;
&lt;br /&gt;
If you need to practice it without having to reload all WML, you can use an add-on named ''Image loading tester'' from the 1.10 add-on server.&lt;br /&gt;
&lt;br /&gt;
== Team-Color Function ==&lt;br /&gt;
In Wesnoth version 1.2, the only Image Path Function was '''~TC()''', which took two comma-separated parameters: the team number and the source color palette. The valid values for both of these parameters are defined in the file ''data/team-colors.cfg''&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~TC(''' ''team number'' ''',''' ''source color palette'' ''')'''&lt;br /&gt;
*''team number'' - this is the first parameter, a number 1-9 signifying the team number of a unit. Number 1 typically means the red team, 2 typically means the blue team, and so on (unless the scenario color settings for any side have been altered).&lt;br /&gt;
*''source color palette'' - the second parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
&lt;br /&gt;
== Re-Color Function ==&lt;br /&gt;
May be used to change some colors in an image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~RC(''' ''source color palette'' '''&amp;gt;''' ''color range ID'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''color range ID'' - this is the second parameter, signifying the ID of a color range defined in the file ''data/core/team-colors.cfg'' (or it may be a custom ID for a color range defined locally).  &lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
In the following example, the magenta regions in an elvish captain's image are turned  a healthy shade of green:&lt;br /&gt;
&lt;br /&gt;
  [message]&lt;br /&gt;
      speaker=narrator&lt;br /&gt;
      image=units/elves-wood/captain.png~RC(magenta&amp;gt;green)&lt;br /&gt;
      message=_ &amp;quot;Now I am on the green team.&amp;quot;&lt;br /&gt;
  [/message]&lt;br /&gt;
&lt;br /&gt;
The IDs of the color ranges may be the lowercased English name of the palette's base color (e.g. 'red', 'brown', etc.). They may also be numeric color indices from the palette WML included with the game, but this is not recommended.&lt;br /&gt;
&lt;br /&gt;
== Palette-switch Function ==&lt;br /&gt;
May be used to change colors in an image following the specifications of a source and target (new) palette.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~PAL(''' ''source color palette'' '''&amp;gt;''' ''target color palette'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, such as magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''target color palette'' - the new palette to take the place of the source colors in the image.&lt;br /&gt;
&lt;br /&gt;
== Flip Function ==&lt;br /&gt;
May be used to flip an image horizontally and/or vertically.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~FL(''' ''optional argument list'' ''')'''&lt;br /&gt;
*''vertical'' - if the string &amp;quot;vert&amp;quot; is found anywhere in the argument list, the image will be flipped vertically.&lt;br /&gt;
*''horizontal'' - if the string &amp;quot;horiz&amp;quot; is found anywhere in the argument list, the image will be flipped horizantally.&lt;br /&gt;
*if the argument list is empty, the image will only be flipped horizontally.&lt;br /&gt;
&lt;br /&gt;
== Rotate Function ==&lt;br /&gt;
May be used to rotate an image by a multiple of 90 degrees.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~ROTATE(''' ''degrees'' ''')'''&lt;br /&gt;
* ''degrees'' - The number of degrees by which the image will be rotated. This must be a multiple of 90. Positive numbers indicate clockwise rotation, while negative numbers indicate counter-clockwise. (Zero indicates no rotation.)&lt;br /&gt;
If the number of degrees is omitted, a quarter turn (90 degrees) clockwise is assumed.&lt;br /&gt;
&lt;br /&gt;
== Greyscale Function ==&lt;br /&gt;
May be used to greyscale the image (turn to black and white)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~GS( )'''&lt;br /&gt;
&lt;br /&gt;
== Black and White Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
May be used to convert the image to pure black and white, without grey pixels. &lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BW(threshold)'''&lt;br /&gt;
* ''threshold'': a value between 0 and 255 (both limits included). All pixels are converted as greyscale first, and if their average value is greater than the threshold they become white, otherwise they become black.&lt;br /&gt;
&lt;br /&gt;
== Sepia Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
May be used to give to the image a sepia tint (like in old pictures).&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~SEPIA()'''&lt;br /&gt;
&lt;br /&gt;
== Negative Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
Also known as ''invert'', it negates all the RGB values of the image, giving it an effect similar to a photographic negative.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~NEG( )'''&lt;br /&gt;
&lt;br /&gt;
== Crop Function ==&lt;br /&gt;
Extracts a rectangular section of an image file.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~CROP(x,y,width,height)'''&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates for the rectangular section extracted. Must be greater or equal than zero, and inside the image's bounds.&lt;br /&gt;
* ''width'': width of the selected region. Must be less than or equal to the original image's width, and must not be negative.&lt;br /&gt;
* ''height'': height of the selected region. Must be less than or equal to the original image's height, and must not be negative.&lt;br /&gt;
&lt;br /&gt;
== Blit Function ==&lt;br /&gt;
Blit the parameter image on the main image. Example: peasant.png~BLIT(hat.png,30,10)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLIT(src,x,y)'''&lt;br /&gt;
* ''src'': an image file used as source for the blit, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to blit. Must be greater or equal than zero. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
== Mask Function ==&lt;br /&gt;
Remove parts of the main image using the parameter image as a mask. Example: grass.png~MASK(circle.png) will give a circle of grass.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~MASK(mask,x,y)'''&lt;br /&gt;
* ''mask'': an image file used as mask, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to put the mask. Parts ouside of the mask are considered transparent. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
Only the alpha channel of the mask is used and each alpha value will be the maximum alpha of the resulting image. This means that the fully-transparent parts of the mask will erase the corresponding parts of the image, but also that a semi-transparent mask will create a semi-transparent image. &lt;br /&gt;
&lt;br /&gt;
== Color-shift function ==&lt;br /&gt;
Performs simple per-channel color shifts by adding the arguments to the respective color channels.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
''Multi-channel:'' '''~CS(r,g,b)'''&lt;br /&gt;
''Single-channel:'' '''~R(v)''', '''~G(v)''', '''~B(v)'''&lt;br /&gt;
&lt;br /&gt;
The multichannel syntax assumes all arguments are set to zero initially, so one can use, e.g. ~CS(2,4) to add +2 and +4 units to the red and green channels respectively, leaving the blue channel intact. Arguments may be negative to diminish a channel's value; this can be used to change an image's brightness. Checks for out-of-range arguments or results (less than 0 or greater than 255) are made, so the resultant values are truncated if necessary.&lt;br /&gt;
&lt;br /&gt;
The single channel syntax behaves exactly the same, except that only single-channel modifications are made per function. However, one can stack them to produce the same behavior as ~CS(), e.g. ~R(r)~G(g)~B(b), but that tends to be just a performance loss.&lt;br /&gt;
&lt;br /&gt;
== Color-blend function ==&lt;br /&gt;
Blends the image with the given color to produce a more controlled tinting effect than color-shifting, independently of the image's contents.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLEND(r,g,b,o)'''&lt;br /&gt;
&lt;br /&gt;
The color is defined by the ''r'', ''g'', and ''b'' parameters (integers ranging from 0 to 255). The ''o'' (opacity) parameter controls the amount by which the given color will be blended into the image, and may be specified either as a factor from 0.0 to 1.0, or percentage up to 100%. Thus, ~BLEND(r,g,b,0.5) and ~BLEND(r,g,b,50%) are equivalent.&lt;br /&gt;
&lt;br /&gt;
== Lightmap color-shift function ==&lt;br /&gt;
Performs per-pixel and per-channel color shifts using another image (a &amp;quot;lightmap&amp;quot;) as source, allowing to create textured light effects.&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~L(lightmap)'''&lt;br /&gt;
&lt;br /&gt;
For each pixel of the original image, it checks the RGB values from the corresponding pixel of the lightmap, slightly transform them, then add these values to the original pixel.&lt;br /&gt;
&lt;br /&gt;
The transformation involved is done to convert the (0,255) spectrum to (-255,255), allowing to add or subtract color. The formula is (x-128)*2, which means that 0 gives -256, 128 gives 0 and 255 gives 254. So, the no-effect lightmap is a fully gray image (RGB = 128,128,128) and any non-gray pixel will shift the colors of the original.&lt;br /&gt;
&lt;br /&gt;
Note that the lightmap will be scaled to the same dimensions as the original image.&lt;br /&gt;
&lt;br /&gt;
== Image-scaling function ==&lt;br /&gt;
Scales a graphic up or down.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~SCALE( ''new_width'', ''new_height'' )&lt;br /&gt;
&lt;br /&gt;
The ''new_width'' and ''new_height'' parameters are taken as the image's original width or height, respectively, if one of them happens to be zero. Negative values are treated in the same way, but an error is printed in stderr.&lt;br /&gt;
&lt;br /&gt;
== Opacity modifying function ==&lt;br /&gt;
Changes an image's opacity at render time.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~O( ''factor or percentage%'' )'''&lt;br /&gt;
&lt;br /&gt;
If the argument includes the percentage symbol (''%''), it will be treated as a percentage of full (real) opacity; an image will be displayed at its native opacity with ~O(100%).&lt;br /&gt;
&lt;br /&gt;
Without the percentage symbol, the argument is assumed to be a factor by which the image's native opacity should be multiplied. Thus, ~O(0.5) and ~O(50%) are equivalent forms of specifying to reduce an image's opacity by half.&lt;br /&gt;
&lt;br /&gt;
== Blurring function ==&lt;br /&gt;
Blurs a graphic at render time using the same algorithm used for in-game dialogs.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BL( ''radius'' )'''&lt;br /&gt;
&lt;br /&gt;
== Overlay function ==&lt;br /&gt;
Puts a time-of-day overlay on the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~LIGHTEN()'''&lt;br /&gt;
&lt;br /&gt;
'''~DARKEN()'''&lt;br /&gt;
&lt;br /&gt;
== Background coloring function ==&lt;br /&gt;
Sets the color of all the (semi-)transparent pixels of the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BG(r,g,b)'''&lt;br /&gt;
&lt;br /&gt;
== Null function ==&lt;br /&gt;
Does nothing.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~NOP()'''&lt;br /&gt;
&lt;br /&gt;
== XBRZ function ==&lt;br /&gt;
Scales functions using the XBRZ algorithm. You may scale things up either 2x, 3x, 4x, or 5x. The scaling tries to preserve the pixel art nature.&lt;br /&gt;
&lt;br /&gt;
'''~XBRZ(n)'''&lt;br /&gt;
&lt;br /&gt;
== SCALE_SHARP function ==&lt;br /&gt;
Scales functions using a nearest neighbor algorithm. Specify width and height. (It has the same syntax as ~SCALE.)&lt;br /&gt;
&lt;br /&gt;
'''~SCALE_SHARP(200,300)'''&lt;br /&gt;
&lt;br /&gt;
== PLOT_ALPHA ==&lt;br /&gt;
At each pixel, the color is replaced with a grey-tone reflecting the alpha value at that pixel, and the new image is fully opaque. Useful for plotting the alpha to help debug an IPF or inspect a sprite.&lt;br /&gt;
&lt;br /&gt;
'''~PLOT_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== WIPE_ALPHA ==&lt;br /&gt;
At each pixel, the alpha value is discarded and the pixel is made fully opaque. Useful again for diagnostics.&lt;br /&gt;
&lt;br /&gt;
'''~WIPE_ALPHA()'''&lt;br /&gt;
&lt;br /&gt;
== ADJUST_ALPHA ==&lt;br /&gt;
&lt;br /&gt;
Scales the alpha value at each pixel down by a fixed factor. The argument is either a %, or an integer from 0 to 255, in which case it is divided by 255 and reinterpretted as a %.&lt;br /&gt;
&lt;br /&gt;
'''~ADJUST_ALPHA(n)'''.&lt;br /&gt;
&lt;br /&gt;
== Precedence of Functions  ==&lt;br /&gt;
&lt;br /&gt;
All functions are applied in left-to-right order, with the exception of RC(), TC() and PAL() which are applied always before any other functions. Standard team coloring for a unit is applied after all custom RC(), TC() and PAL() functions but before any other functions.&lt;br /&gt;
That is, stuff like &amp;quot;units/elves-wood/fighter.png~CROP(20,20,40,40)~CROP(10,10,10,10)&amp;quot; would result in taking a crop to a 40x40 rectangle whose top-left corner is x=20, y=20; and then taking a crop from ''that'' rectangle with x=10, y=10, w=10, h=10. The result is the area x=30, y=30, w=10, h=10 from the original graphic.&lt;br /&gt;
&lt;br /&gt;
[[Category:WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=56356</id>
		<title>DirectActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=56356"/>
		<updated>2015-05-01T09:53:04Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [object] */ added duration = turn end&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== Direct actions ==&lt;br /&gt;
&lt;br /&gt;
Direct actions are actions that have a direct effect on gameplay. They can be used inside of [[EventWML|events]].&lt;br /&gt;
&lt;br /&gt;
The following tags are actions:&lt;br /&gt;
&lt;br /&gt;
=== [endlevel] ===&lt;br /&gt;
Ends the scenario.&lt;br /&gt;
* '''result''': before the scenario is over, all events with ''name=result'' are triggered. If ''result=victory'', the player progresses to the next level (i.e., the next scenario in single player); if ''result=defeat'', the game returns to the main menu. &lt;br /&gt;
&lt;br /&gt;
When the result is &amp;quot;victory&amp;quot; the following keys can be used:&lt;br /&gt;
* '''bonus''': whether the player should get bonus gold (maximum possible gold that could have been earned by waiting the level out). The default is bonus=yes.&lt;br /&gt;
* '''carryover_report''': whether the player should receive a summary of the scenario outcome, the default is carryover_report=yes.&lt;br /&gt;
* '''save''': whether a start-of-scenario save should be created for the next scenario, the default is save=yes. Do not confuse this with saving of replays for the current scenario.&lt;br /&gt;
* '''replay_save''': whether a replay save for the current scenario is allowed, the default is replay_save=yes. If yes, the player's settings in preferences will be used to determine if a replay is saved. If no, will override and not save a replay.&lt;br /&gt;
* '''linger_mode''': If ...=yes, the screen is greyed out and there's the possibility to save before advancing to the next scenario, the default is linger_mode=yes.&lt;br /&gt;
* '''reveal_map''': (Multiplayer only) (Default is 'yes') If 'no', shroud doesn't disappear when game ended.&lt;br /&gt;
* '''next_scenario''': (default specified in '''[scenario]''' tag) the ID of the next scenario that should be played.  All units that side 1 controls at this point become available for recall in ''next_scenario''.&lt;br /&gt;
* '''carryover_percentage''': by default 80% of the gold is carried over to the next scenario, with this key the amount can be changed.&lt;br /&gt;
* '''carryover_add''': if true the gold will be added to the starting gold the next scenario, if false the next scenario will start with the amount of the current scenario (after taxes) or the minimum in the next scenario. Default is false.&lt;br /&gt;
* '''music''': (default specified in '''[scenario]''' or '''[game_config]''' tags) a comma-separated list of music tracks from which one will be chosen and played once after any events related to the end of level result are executed; by default, victory_music is used on victory, and defeat_music on defeat.&lt;br /&gt;
* '''end_credits''': Whether to display the credits screen at the end of a single-player campaign. Defaults to ''yes''. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text''': (translatable) Text that is shown centered in a black screen at the end of a campaign. Defaults to &amp;quot;The End&amp;quot;. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text_duration''': Delay, in milliseconds, before displaying the game credits at the end of a campaign. In other words, for how much time '''end_text''' is displayed on screen. Defaults to 3500. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* &amp;lt;strike&amp;gt;'''[next_scenario_settings]''': Any tags or attribute children of this optional argument to [endlevel] are merged into the scenario/multiplayer tag of the *next* scenario. This allows you to e.g. reconfigure the [side] tags or settings, just before load. &amp;lt;/strike&amp;gt; This feature was removed in 1.11.17, it might be redesigned and reintroduced.&lt;br /&gt;
* &amp;lt;strike&amp;gt;'''[next_scenario_append]''': Any tags of this optional argument are appended at high level to the next scenario. This is most appropriate for [event] tags, although you may find other uses. Example test scenario for these features: https://gna.org/support/download.php?file_id=20119 &amp;lt;/strike&amp;gt; This feature was removed in 1.11.17, it might be redesigned and reintroduced.&lt;br /&gt;
* '''[result]''' {{DevFeature1.13|0}} Allows to make add a side specific result, this is for competitive multiplayer scenarios/campaigns where it might happen that one player wins but another player looses, the following attributes are accepted and have the same effect as in '''[endlevel]''':&lt;br /&gt;
** '''result'''&lt;br /&gt;
** '''bonus'''&lt;br /&gt;
** '''carryover_percentage'''&lt;br /&gt;
** '''carryover_add'''&lt;br /&gt;
&lt;br /&gt;
And there is also&lt;br /&gt;
** '''side''' The number of the side for which these results should apply.&lt;br /&gt;
&lt;br /&gt;
=== [unit] ===&lt;br /&gt;
Places a unit on the map.  For syntax see [[SingleUnitWML]].&lt;br /&gt;
* {{Short Note:Predefined Macro|GENERIC_UNIT}}&lt;br /&gt;
* '''to_variable''':  spawn directly into a variable instead of on the map.&lt;br /&gt;
&lt;br /&gt;
=== [recall] ===&lt;br /&gt;
Recalls a unit taking into account any [http://wiki.wesnoth.org/SingleUnitWML filter_recall] of the leader.   The unit is recalled free of charge, and is placed near its leader, e.g., if multiple leaders are present, near the first found which would be able to normally recall it.&lt;br /&gt;
&lt;br /&gt;
If neither a valid map location is provided nor a leader on the map would be able to recall it, the tag is ignored.&lt;br /&gt;
 &lt;br /&gt;
* [[StandardUnitFilter]]: the first matching unit will be recalled.  If no units match this tag is ignored. Do not use a [filter] tag. If a comma separated list is given, every unit currently considered for recall is checked against all the types (not each single one of the types against all units).&lt;br /&gt;
* '''x,y''': the unit is placed here instead of next to the leader.&lt;br /&gt;
* '''show''': yes/no, default yes: whether the unit is animated (faded in) or instantly displayed&lt;br /&gt;
* '''fire_event''': boolean yes|no (default no); whether any according prerecall or recall events shall be fired.&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit (a nearby passable hex is chosen).&lt;br /&gt;
&lt;br /&gt;
=== [teleport] ===&lt;br /&gt;
Teleports a unit on map. {{Short Note:Predefined Macro|TELEPORT_UNIT}}&lt;br /&gt;
* '''[filter]''': [[StandardUnitFilter]] the first unit matching this filter will be teleported.&lt;br /&gt;
* '''x,y''': the position to teleport to.&lt;br /&gt;
* '''clear_shroud''': should shroud be cleared on arrival&lt;br /&gt;
* '''animate''': should a teleport animation be played (if the unit doesn't have a teleport animation, it will fade out/fade in)&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): normally, units will not be teleported into terrain that is impassable for them. Setting this attribute to &amp;quot;no&amp;quot; permits it.&lt;br /&gt;
&lt;br /&gt;
(Note: There is also a ability named teleport, see [[AbilitiesWML]].)&lt;br /&gt;
&lt;br /&gt;
=== [terrain_mask] ===&lt;br /&gt;
Changes the terrain on the map.  See [[TerrainMaskWML]].&lt;br /&gt;
&lt;br /&gt;
=== [terrain] ===&lt;br /&gt;
Changes the terrain on the map.&lt;br /&gt;
* '''terrain''': the character of the terrain to use.  See [[TerrainCodesWML]] to see what letter a type of terrain uses.&lt;br /&gt;
* [[StandardLocationFilter]]. This [[StandardLocationFilter]]'s terrain= key is used for the new terrain, filtering by terrain can be done with a nested [[StandardLocationFilter]]: [and]terrain=terrain_string_to_be_filtered_for.&lt;br /&gt;
* '''layer''': (overlay|base|both, default=both) only change the specified layer.&lt;br /&gt;
* '''replace_if_failed''': (default=no) When replacing just one layer failed, try to replace the whole terrain. If '''terrain''' is an overlay only terrain, use the default_base as base layer. If the terrain has no default base, do nothing.&lt;br /&gt;
&lt;br /&gt;
If you want to remove the overlays from a terrain and leave only the base, use:&lt;br /&gt;
 layer=overlay&lt;br /&gt;
 terrain=&amp;quot;^&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages it that there are too many choices to make; should a unit loose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [gold] ===&lt;br /&gt;
Gives sides gold.&lt;br /&gt;
* '''amount''': the amount of gold to give.&lt;br /&gt;
* '''side''': (default=1) the number of the side to give the gold to. Can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [unstore_unit] ===&lt;br /&gt;
Creates a unit from a game variable, and activates it on the playing field.  This must be a specific variable describing a unit, and may not be an array -- to unstore an entire array, iterate over it.  The variable is not cleared.  See also [[InternalActionsWML#.5Bstore_unit.5D|[store_unit]]], [[ConditionalActionsWML#.5Bwhile.5D|[while]]] and [[InternalActionsWML#.5Bclear_variable.5D|[clear_variable]]].&lt;br /&gt;
* '''variable''': the name of the variable.&lt;br /&gt;
* '''find_vacant''': whether the unit should be placed on the nearest vacant tile to its specified location.  If this is set to 'no'(default), then any unit on the same tile as the unit being unstored will be destroyed. &lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit. This key has no effect if find_vacant=no (no check performed then). Before 1.9 this key is always &amp;quot;no&amp;quot;.&lt;br /&gt;
* '''text''': (translatable) floating text to display above the unit, such as a damage amount&lt;br /&gt;
* '''red''', '''green''', '''blue''': (default=0,0,0) the color to display the text in. Values vary from 0-255. You may find it convenient to use the {COLOR_HARM} or {COLOR_HEAL} macro instead. (Use {COLOR_HARM} or {COLOR_HEAL} instead of the whole red,green,blue= line.)&lt;br /&gt;
* '''advance''': (default=true) if true the unit is advanced if it has enough XP. When modifying XP make sure to do it from inside a [[EventWML#Multiplayer_safety|synchronized event]] or it may lead to OOS errors especially when several advancement paths exist. Note that advance and post advance events are called, so infinite loops can happen.&lt;br /&gt;
* '''fire_event''': (boolean yes|no, default no) Whether any advance/post advance events shall be fired if an advancement takes place, no effect otherwise.&lt;br /&gt;
* '''animate''': (boolean yes|no, default yes) Whether &amp;quot;levelout&amp;quot; and &amp;quot;levelin&amp;quot; (or fade to white and back) animations shall be played if an advancement takes place, no effect otherwise.&lt;br /&gt;
* '''x''' ,'''y''': override unit location, &amp;quot;x,y=recall,recall&amp;quot; will put the unit on the unit's side's recall list.&lt;br /&gt;
Units can be unstored with negative (or zero) hit points. This can be useful if modifying a unit in its last_breath event (as the unit's death is already the next step), but tends to look wrong in other cases. In particular, it is possible to have units with negative hit points in play. Such units are aberrations, subject to unusual behavior as the game compensates for them. (For example, such units are currently automatically hit&amp;amp;ndash;and killed&amp;amp;ndash;in combat.) The details of the unusual behavior are subject to change between stable releases without warning.&lt;br /&gt;
&lt;br /&gt;
=== [allow_recruit] ===&lt;br /&gt;
Allows a side to recruit units it couldn't previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that is being allowed to recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [allow_extra_recruit] ===&lt;br /&gt;
Allows a leader to recruit units it couldn't previously recruit.&lt;br /&gt;
These types add to the types the leader can recruit because of [side]recruit=.&lt;br /&gt;
* '''extra_recruit''': the types of units that the unit can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_recruit] ===&lt;br /&gt;
Prevents a side from recruiting units it could previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can no longer recruit. {{DevFeature1.13|0}} If omitted, all recruits for matching sides will be disallowed.&lt;br /&gt;
* '''side''': (default=1) the number of the side that may no longer recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_extra_recruit] ===&lt;br /&gt;
Prevents a leader from recruiting units it could previously recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the side can no longer recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [set_recruit] ===&lt;br /&gt;
Sets the units a side can recruit.&lt;br /&gt;
* '''recruit''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that is having its recruitment set. This can be a comma-separated list. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [set_extra_recruit] === &lt;br /&gt;
Sets the units a leader can recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the leader can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [modify_side] ===&lt;br /&gt;
Modifies some details of a given side in the middle of a scenario.  '''The following listed properties are the only properties that [modify_side] can affect!'''&lt;br /&gt;
* '''side''': (default=1) the number of the side that is to be changed. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* '''income''': the income given at the begining of each turn.&lt;br /&gt;
* '''recruit''': a list of unit types, replacing the side's current recruitment list.&lt;br /&gt;
* '''team_name''': the team in which the side plays the scenario.&lt;br /&gt;
* '''user_team_name''': a translatable string representing the team's description. This has no effect on alliances. Defaults to ''team_name''.&lt;br /&gt;
* '''gold''': the amount of gold the side owns.&lt;br /&gt;
* '''village_gold''': the income setting per village for the side.&lt;br /&gt;
* '''controller''': the identifier string of the side's controller. Uses the same syntax of the ''controller'' key in the [[SideWML|[side]]] tag.&lt;br /&gt;
* '''fog''': a boolean string (yes/no) describing the status of Fog for the side.&lt;br /&gt;
* '''shroud''': a boolean string describing the status of Shroud for the side.&lt;br /&gt;
* '''hidden''': a boolean string specifying whether side is shown in status table.&lt;br /&gt;
* '''color''': a team color range specification, name (e.g. &amp;quot;red&amp;quot;, &amp;quot;blue&amp;quot;), or number (e.g. &amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;) for this side. The default color range names, numbers, and definitions can be found in data/core/team_colors.cfg.&lt;br /&gt;
* '''[ai]''': sets/changes AI parameters for the side. Only parameters that are specified in the tag are changed, this does not reset others to their default values. Uses the same syntax as described in [[AiWML]].  Note that [modify_side][ai] works for all simple AI parameters and some, but not all, of the composite ones. If in doubt, use [http://wiki.wesnoth.org/AiWML#Adding_and_Deleting_Aspects_with_the_.5Bmodify_ai.5D_Tag [modify_ai]] instead, which always works.&lt;br /&gt;
* '''switch_ai''': replaces a side ai with a new AI from specified file(ignoring those AI parameters above). Path to file follows the usual WML convention.&lt;br /&gt;
* '''reset_maps''': If set to &amp;quot;yes&amp;quot;, then the shroud is spread to all hexes, covering the parts of the map that had already been explored by the side, including hexes currently seen. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if shroud is on, but this is evaluated after shroud= (and before shroud_data=).&lt;br /&gt;
* '''reset_view''': If set to &amp;quot;yes&amp;quot;, then the fog of war is spread to all hexes, covering the parts of the map that had already been seen this turn by the side, including hexes currently seen, excluding hexes affected by multi-turn {{tag|DirectActionsWML|lift_fog}}. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if fog is on, but this is evaluated after fog=.&lt;br /&gt;
* '''share_maps''': change the share_maps side attribute. Be sure to use shroud=yes for that side and have it as an ally&lt;br /&gt;
* '''share_view''': change the share_view side attribute. Be sure to use fog=yes for that side and have it as an ally&lt;br /&gt;
* '''shroud_data''': changes to the side's shroud, using the same format as when defining the [side].&lt;br /&gt;
* '''suppress_end_turn_confirmation''': Boolean value controlling whether or not a player is asked for confirmation when skipping a turn.&lt;br /&gt;
* '''scroll_to_leader''': Boolean value controlling whether or not the game view scrolls to the side leader at the start of their turn when present.&lt;br /&gt;
* '''flag''': Flag animation for villages owned by this side (see [[SideWML|[side]]]).&lt;br /&gt;
* '''flag_icon''': Flag icon used for this side in the status bar (see [[SideWML|[side]]]).&lt;br /&gt;
* '''village_support''': The number of unit levels this side is able to support (does not pay upkeep on) per village it controls.&lt;br /&gt;
&lt;br /&gt;
=== [modify_turns] ===&lt;br /&gt;
Modifies the turn limit in the middle of a scenario.&lt;br /&gt;
* '''value''': the new turn limit.&lt;br /&gt;
* '''add''': if used instead of ''value'', specifies the number of turns to add to the current limit (can be negative).&lt;br /&gt;
* '''current''': changes the current turn number after applying turn limit modifications, if any. It is not possible to change the turn number to exceed the turn limit (1 &amp;lt;= current turns &amp;lt;= max turns).&lt;br /&gt;
&lt;br /&gt;
=== [allow_end_turn] ===&lt;br /&gt;
Allows human players to end their turn through the user interface if they were previously affected by the '''[disallow_end_turn]''' action. This action doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_end_turn] ===&lt;br /&gt;
Disallows human players to end their turn through the user interface. This action doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
=== [capture_village] ===&lt;br /&gt;
Changes the ownership of a village.&lt;br /&gt;
* [[StandardLocationFilter]]: all village locations matching the filter are affected.&lt;br /&gt;
* '''side''': the side that takes control of the village. This side needs to have a leader (canrecruit=yes). If the side key is not given, the village will become neutral (unless [filter_side] is present, in which case that side fiter decides, see below).&lt;br /&gt;
* '''[filter_side]''' with [[StandardSideFilter]] tags and keys as arguments; if both this tag and inline side= are present it's an error. Otherwise, the first matching side gets ownership (or the village becomes neutral if none match).&lt;br /&gt;
* '''fire_event''' (boolean yes|no, default: no): Whether any capture events shall be fired.&lt;br /&gt;
&lt;br /&gt;
=== [kill] ===&lt;br /&gt;
Removes all units (including units in a recall list) that match the filter from the game.&lt;br /&gt;
* [[StandardUnitFilter]]: Selection criterion; do not use a [filter] tag.&lt;br /&gt;
* '''animate''': if 'yes', displays the unit dying (fading away).&lt;br /&gt;
* '''fire_event''': if 'yes', triggers any appropriate 'die' events (See [[EventWML]]). Note that events are only fired for killed units that have been on the map (as opposed to recall list).&lt;br /&gt;
* '''[secondary_unit]''' with a [[StandardUnitFilter]] as argument. Do not use a [filter] tag. Has an effect only if fire_event=yes. The first on-map unit matching the filter becomes second_unit in any fired die and last breath events. If an on-map unit matches and if there are several units killed with a single [kill] tag, second_unit is this same unit for all of them. If no on-map unit matches or [secondary_unit] isn't present, the variable second_unit in each of the die and last breath events is always the same as the variable unit (the dying unit).&lt;br /&gt;
&lt;br /&gt;
=== [move_unit] ===&lt;br /&gt;
works like the MOVE_UNIT macro.&lt;br /&gt;
* [[StandardUnitFilter]] as argument; do not use a [filter] tag. All units matching the filter are moved. If the target location is occupied, the nearest free location is chosen.&lt;br /&gt;
* '''to_x''' (unsigned integer): The units are moved to this x coordinate. Can be a comma-separated list, in which case the unit follows this given path during the move.&lt;br /&gt;
* '''to_y''' (unsigned integer): The units are moved to this y coordinate. Can be a comma-separated list.&lt;br /&gt;
* '''fire_event''' (optional, boolean yes|no, default no): Whether any according moveto events shall be fired. The target location ($x1, $y1 in the event) may not be the same location that the unit was tried to be moved to, if the original target location is occupied or impassable.&lt;br /&gt;
* '''check_passability''' (boolean yes|no, default yes): Whether the terrain the unit is moved to should be checked for suiting the unit. (If it does not, a nearby suitable hex is chosen.)&lt;br /&gt;
* '''force_scroll''': Whether to scroll the map or not even when [[InterfaceActionsWML#.5Block_view.5D|[lock_view]]] is in effect or ''Follow Unit Actions'' is disabled in ''Advanced Preferences''. Defaults to using [[InterfaceActionsWML#.5Bmove_unit_fake.5D|[move_unit_fake]]]'s default value.&lt;br /&gt;
&lt;br /&gt;
=== [modify_ai] ===&lt;br /&gt;
Changes AI objects (aspects, goals, candidate actions or stages) for a specified side. See [[AiWML#Adding_and_Deleting_Aspects_with_the_.5Bmodify_ai.5D_Tag|AiWML]] for full description.&lt;br /&gt;
&lt;br /&gt;
* '''action''' (string): Takes values 'add', 'change', 'delete' or 'try_delete' to do just that for the AI object.&lt;br /&gt;
* '''path''' (string): Describes which AI object is to be modified.  &lt;br /&gt;
* '''[facet]''', '''[goal]''', '''[candidate_action]''' or '''[stage]''': Details about the AI object to be modified.&lt;br /&gt;
* [[StandardSideFilter]] tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [modify_unit] ===&lt;br /&gt;
works similar to the MODIFY_UNIT macro.&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. All units matching this filter are modified. Matches on recall list units too.&lt;br /&gt;
* Accepts generally the syntax inside of wml unit variables created by [store_unit] which can be viewed in a savefile or by using the :inspect command. It can add [trait]s and [object]s without needing to wrap them inside a [modifications] tag, and their effects are applied immediately. Cannot remove things. Subtags with the same name must be written in the correct order to match them with the tag they are supposed to modify.&lt;br /&gt;
example usage (see also the test scenario):&lt;br /&gt;
 [modify_unit]&lt;br /&gt;
   [filter]&lt;br /&gt;
     x,y=38,6&lt;br /&gt;
   [/filter]&lt;br /&gt;
   hitpoints=10&lt;br /&gt;
   {TRAIT_HEALTHY}&lt;br /&gt;
 [/modify_unit]&lt;br /&gt;
&lt;br /&gt;
The unit which is currently modified is accessible via $this_unit, e.g. hitpoints = &amp;quot;$($this_unit.hitpoints / 2)&amp;quot; to set the hitpoints of all units to half of their particular maxima. This this_unit variable is independent from the this_unit variable available in the SUF used to determine which units to modify (first all matching units are gathered, and then all those are modified).&lt;br /&gt;
&lt;br /&gt;
note: The syntax allowed is somehow vague. Just try things and possibly correct/add/modify this documentation. (a [http://forums.wesnoth.org/viewtopic.php?f=21&amp;amp;t=31676&amp;amp; forum thread] discusses some related issues).&lt;br /&gt;
&lt;br /&gt;
=== [transform_unit] ===&lt;br /&gt;
Transforms every unit matching the filter to the given unit type. Keeps intact hit points, experience and status. If the unit is transformed to a non-living type (undead or mechanical), it will be also unpoisoned. Hit points will be changed if necessary to respect the transformed unit's maximum hit points.&lt;br /&gt;
* [[StandardUnitFilter]]: do not use a [filter] tag.&lt;br /&gt;
* '''transform_to''': the unit type in which all the units matching the filter will be transformed. If missing, the units will follow their normal advancement.&lt;br /&gt;
&lt;br /&gt;
=== [petrify] ===&lt;br /&gt;
&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are petrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [unpetrify] ===&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are unpetrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [object] ===&lt;br /&gt;
Gives some unit an object which modifies their stats in some way.&lt;br /&gt;
* '''id''': (Optional) when the object is picked up, a flag is set for ''id''.  The object cannot be picked up if a flag for ''id'' has been set.  This means that any object with an id can only be used once, even if first_time_only=no is set for the event. This restriction is per level. In a campaign objects with the same id can be assigned once per level.&lt;br /&gt;
* '''delayed_variable_substitution''' (boolean yes|no, default no): If set to &amp;quot;yes&amp;quot;, the wml block contained in this [object] is not variable-substituted at execution time of the event where this [object] is within. You need this to work around a bug when adding ABILITY_TELEPORT via an [object] or when using [object][effect][filter]with a $this_unit (see http://gna.org/bugs/index.php?18893).&lt;br /&gt;
* '''[effect]''': one or more effect elements may be listed.  See [[EffectWML]] for a description of [effect].&lt;br /&gt;
* '''duration''':&lt;br /&gt;
**if 'scenario', effects only last until the end of the level (note : 'level' is the scenario, so this doesn't mean it last until the unit levels-up).&lt;br /&gt;
**if 'forever' or not set, effects never wear off.&lt;br /&gt;
** if 'turn', effects only last until the start of the unit's next turn (when the unit refreshes movement and attacks). (Like other start-of-turn behavior, objects with a duration of &amp;quot;turn&amp;quot; won't expire before turn 2.)&lt;br /&gt;
** {{DevFeature1.13|1}} if 'turn end' or 'turn_end', effects only last until the end of the unit's next turn (exactly like the slowed status).&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. The first unit found that matches the filter will be given the object. Only on-map units are considered. If no unit matches or no [filter] is supplied, it is tried to apply the object to the unit at the $x1,$y1 location of the event where this [object] is in. The case of no unit being at that spot is handled in the same way as no unit matching a given filter ([else] commands executed, cannot_use_message displayed)&lt;br /&gt;
* '''[then]''': a subtag that lets you execute actions if the filter conditions are met.  The most common action that should be inside here is a '''[remove_item]''' tag, but you could probably put any tags that otherwise work in a [then] tag.&lt;br /&gt;
* '''[else]''': a subtag that lets you execute actions if the filter conditions are *not* met.&lt;br /&gt;
* '''silent''': whether or not messages should be suppressed. Default is &amp;quot;no&amp;quot;.&lt;br /&gt;
* '''image''': the displayed image of the object.&lt;br /&gt;
* '''name''': (translatable) displayed as a caption of the image.&lt;br /&gt;
&lt;br /&gt;
* '''description''': (translatable) displayed as a message of the image.&lt;br /&gt;
* '''cannot_use_message''': (translatable) displayed instead of '''description''' if no unit passes the filter test.&lt;br /&gt;
&lt;br /&gt;
=== [remove_shroud] ===&lt;br /&gt;
Removes some shroud from the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to remove shroud. This can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles for which shroud should be removed&lt;br /&gt;
&lt;br /&gt;
=== [place_shroud] ===&lt;br /&gt;
Places some shroud on the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to place shroud. This can be a comma-separated list. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles on which shroud should be placed&lt;br /&gt;
&lt;br /&gt;
=== [lift_fog] ===&lt;br /&gt;
Lifts the fog of war from parts of the map for a certain side (only relevant for sides that have fog=yes), allowing a player to witness what occurs there even if that player has no units within vision range.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the tiles from which fog should be lifted.&lt;br /&gt;
* '''multiturn''': ''yes/no, default:no''. The default (not multiturn) causes fog to be removed in the same way that normal vision works; the cleared tiles will remain cleared until fog is recalculated (which normally happens when a side ends its turn). When multiturn is set to &amp;quot;yes&amp;quot;, the cleared tiles remain clear until {{tag||reset_fog}} cancels the clearing. This allows tiles to remain clear for multiple turns, or to be refogged before the end of the current turn (without also refogging all tiles). Multiturn lifted fog is not shared with allies (even when share_view=yes).&lt;br /&gt;
&lt;br /&gt;
=== [reset_fog] ===&lt;br /&gt;
The primary use of this tag is to remove multiturn lifted fog (created by {{tag||lift_fog}}), which causes the fog to reset to what it would have been had WML not interfered. (That is, hexes that a side's units could not see at any point this turn will be re-fogged, while seen hexes remain defogged.)&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the fog reset will be restricted to these tiles.&lt;br /&gt;
* '''reset_view''': ''yes/no, default: no'' If set to &amp;quot;yes&amp;quot;, then in addition to removing multiturn fog, the side's current view is canceled (independent of the SLF). This means that all hexes will become fogged for the side unless multiturn fog exists outside the tiles selected by the SLF. Normally, one would want the currently seen hexes to become clear of fog; this is done automatically at the end of many events, and it can be done manually with {{tag|InterfaceActionsWML|redraw}}.&lt;br /&gt;
Omitting both the SSF and the SLF would cancel all earlier uses of [lift_fog].&lt;br /&gt;
Additionally setting reset_view=&amp;quot;yes&amp;quot; would cause the side's entire map to be fogged (unless an ally keeps hexes clear by sharing its view).&lt;br /&gt;
&lt;br /&gt;
=== [allow_undo] ===&lt;br /&gt;
&lt;br /&gt;
Normally when an event with a handler fires, the player's undo stack is cleared, preventing all actions performed so far from being undone. Including this tag in the event handler prevents the stack from being cleared for this reason, allowing the player to undo actions. (However, the stack might still be cleared for other reasons, such as fog being cleared or combat occurring.) In the common cases, this means '''[allow_undo]''' allows the current action to be undone even though an event was handled. There is a less common case, though &amp;amp;mdash; specifically when handling a menu item, where there is no current action &amp;amp;mdash; and in this case, '''[allow_undo]''' means merely that earlier actions can still be undone.&lt;br /&gt;
* Using this tag in a menu item has an additional side effect in 1.11. Starting with version 1.11.1, executing a WML menu item normally counts as doing something as far as the &amp;quot;you have not started your turn yet&amp;quot; dialog is concerned. However, a menu item whose handler includes '''[allow_undo]''' will not count.&lt;br /&gt;
&lt;br /&gt;
The types of actions that can be undone are movement, recruitment, recalling, and dismissing a unit from the recall list. If an action is undone, only the position (or existence) of the involved unit will be restored; any altered variables or changes to the game will remain changed after the action is undone.  It is up to the scenario designer to avoid abusing this command.&lt;br /&gt;
* Technically, if '''[allow_undo]''' is inside an '''[event]''' with ''first_time_only=yes'' (the default setting), and the user undoes the event, then the state of the game has changed in this way: the event will not fire a second time, even though the user undid the action the first time.&lt;br /&gt;
&lt;br /&gt;
Due to a bug in 1.12 (https://gna.org/bugs/?23323) '''[allow_undo]''' should not be used in events that use one of the following things brcause it might cause OOS: &lt;br /&gt;
* [message] with [option]s&lt;br /&gt;
* [get_global_variable]&lt;br /&gt;
* wesnoth.syncronize_choice&lt;br /&gt;
&lt;br /&gt;
=== [heal_unit] ===&lt;br /&gt;
Heal a unit. The variable '''$heal_amount''' will be set to the exact number of points healed (i.e can be lesser than the parameter '''amount''' if the unit is fully healed). $heal_amount contains only the number of hitpoints the first unit that was found got healed.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] All matching on-map units are healed. If no filter is supplied, it is tried to take the unit at $x1, $y1.&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] all the units matching the filter ''and'' having the ''heals'' ability will have their animation played (if ''animate'' is set to true) for each of the units healed.&lt;br /&gt;
*  '''amount''': (integer, default full) the maximum points the unit(s) will be healed. Can't set below 1 or above max_hitpoints. If &amp;quot;full&amp;quot;, sets hitpoints to max_hitpoints. Before 1.9 the default is 0.&lt;br /&gt;
*  '''animate''': a boolean which indicate if the healing animations must be played. (default no)&lt;br /&gt;
*  '''moves''': (integer, default 0) The maximum current movement points the units will be &amp;quot;healed&amp;quot;. Can't set below 0 or above max_moves. If &amp;quot;full&amp;quot;, sets moves to max_moves.&lt;br /&gt;
* '''restore_attacks''': (boolean, default no) Whether the units' attacks_left should be reset to their max_attacks (usually 1).&lt;br /&gt;
* '''restore_statuses''': (boolean, default yes) Whether standard statuses should be reset to &amp;quot;no&amp;quot;. This affects poisoned, slowed, petrified and unhealable. Before 1.9 this is always &amp;quot;no&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== [harm_unit] ===&lt;br /&gt;
Harms every unit matching the filter, for the specific damage amount.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] all matching units will be harmed (required).&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] if present, the first matching unit will attack all the units matching the filter above.&lt;br /&gt;
*  '''amount''': the amount of damage that will be done (required).&lt;br /&gt;
*  '''alignment''': (default neutral) applies an alignment to the damage, this means that if alignment=chaotic, the damage will be increased at night and reduced at day.&lt;br /&gt;
*  '''damage_type''': if present, amount will be altered by unit resistance to the damage type specified.&lt;br /&gt;
*  '''kill''': (default yes) if yes, when a harmed unit goes to or below 0 HP, it is killed; if no its HP are set to 1.&lt;br /&gt;
*  '''fire_event''': (default no) if yes, when a unit is killed by harming, the corresponding events are fired.  If yes, also the corresponding advance and post advance events are fired.&lt;br /&gt;
*  '''animate''': (default no) if yes, scrolls to each unit before harming it and plays its defense (or attack, if it's the harmer) and death animations. Special values supported, other than the usual yes and no, are &amp;quot;attacker&amp;quot;, that means only the harmer will be animated, and &amp;quot;defender&amp;quot;, that means only the harmed units will be animated. If the supplied value is yes, attacker or defender also advancement animations are played.&lt;br /&gt;
*  '''[primary_attack], [secondary_attack]''': these set the weapon against which the harmed units will defend, and that the harming unit will use to attack, respectively (notice this is the opposite of '''[filter]''' and '''[filter_second]''' above). This allows for playing specific defense and attack animations. Both tags are expected to contain a [[FilterWML#Filtering_Weapons|Standard Weapon Filter]].&lt;br /&gt;
*  '''delay''': if animate=yes, sets the delay (in milliseconds, default 500) between each unit harming.&lt;br /&gt;
*  '''variable''': if present, the damage caused to the unit, altered by resistances, will be stored in a WML array with the given name, under the &amp;quot;harm_amount&amp;quot; key.&lt;br /&gt;
*  '''poisoned, slowed, petrified, unhealable''': (default no) if yes, every harmed unit that doesn't already have such status will have it set.&lt;br /&gt;
*  '''experience''': if yes, and there is a harmer, experience will be attributed like in regular combat.&lt;br /&gt;
*  '''resistance_multiplier''': the harmed unit's resistance is multiplied by the supplied value; this means that a value lower than 1 increases it, and a value greater than 1 decreases it. Default value is 1, that means no modification.&lt;br /&gt;
&lt;br /&gt;
=== [time_area] ===&lt;br /&gt;
How a day should progress in a given area. Everywhere not specified in a [time_area] tag is affected by the [time] tags in the [scenario] tag.&lt;br /&gt;
* [[StandardLocationFilter]]: the locations to affect. ''note: only for [event][time_area]s - at scenario toplevel [time_area] does not support [[StandardLocationFilter]], only location ranges''&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
* '''id''': an unique identifier assigned to a time_area. Optional, unless you want to remove the time_area later. Can be a comma-separated list when removing time_areas, see below.&lt;br /&gt;
* '''remove''': (boolean) yes/no value. Indicates whether the specified time_area should be removed. Requires an identifier. If no identifier is used, however, all time_areas are removed.&lt;br /&gt;
* '''current_time''': The time slot number (starting with zero) active at the creation of the area.&lt;br /&gt;
&lt;br /&gt;
''Example:'' (caves in parts of a map)&lt;br /&gt;
 [time_area]&lt;br /&gt;
     x=1-2,4-5&lt;br /&gt;
     y=1-2,1-2&lt;br /&gt;
     {UNDERGROUND}&lt;br /&gt;
 [/time_area]&lt;br /&gt;
&lt;br /&gt;
=== [end_turn] ===&lt;br /&gt;
End the current side's turn. The current event is finished before the turn is ended. Also, if the current event (where the tag appears) has been fired by another event, that event (and the complete stack of other possible parent events) is ended before [end_turn] comes into affect. Also, events following the event stack that fired [end_turn] are not omitted (e.g. [end_turn] is used by a side turn event and a turn refresh event does something afterwards).&lt;br /&gt;
&lt;br /&gt;
=== [replace_map] ===&lt;br /&gt;
&lt;br /&gt;
Replaces the entire map.&lt;br /&gt;
* '''map''': Content of a wesnoth map file. example:&lt;br /&gt;
 map=&amp;quot;{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}&amp;quot;&lt;br /&gt;
* '''expand''': if 'yes', allows the map size to increase. The expansion direction is currently always bottom-right.&lt;br /&gt;
* '''shrink''': if 'yes', allows the map size to decrease. If the map size is reduced, any units that would no longer be on the map due to its coordinates no longer existing will be put into the recall list.&lt;br /&gt;
Note: When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages it that there are too many choices to make; should a unit lose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [replace_schedule] ===&lt;br /&gt;
Replace the time of day schedule of the entire scenario.&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
* '''current_time''': The time slot number (starting with zero) active at schedule replacement.&lt;br /&gt;
&lt;br /&gt;
=== [tunnel] ===&lt;br /&gt;
&lt;br /&gt;
Create a tunnel between some locations, later usable by units to move from source hex to target hex (using the movement cost of unit on the target terrain). ([http://forums.wesnoth.org/viewtopic.php?f=21&amp;amp;t=14749&amp;amp;p=405667&amp;amp;hilit=tunnel#p405667 source])&lt;br /&gt;
&lt;br /&gt;
* '''id''' identifier for the tunnel, to allow removing (optional).&lt;br /&gt;
* '''remove''': (boolean) yes/no value. If yes, removes all defined tunnels with the same ID (then only id= is necessary). (default: no)&lt;br /&gt;
* '''bidirectional''': (boolean) if yes, creates also a tunnel in the other direction. (default: yes)&lt;br /&gt;
* '''always_visible''': (boolean) if yes, the possible movement of enemies under fog can be seen. (default: no)&lt;br /&gt;
* '''[source]''': [[StandardLocationFilter]] the source hex(es) (required).&lt;br /&gt;
* '''[target]''': [[StandardLocationFilter]] the target hex(es) (required).&lt;br /&gt;
* '''[filter]''': [[StandardUnitFilter]] the units which can use the tunnel (required). Leave empty for &amp;quot;all units&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
(Note: The tunnel tag can also be used inside the [[AbilitiesWML|[teleport]]] ability, without remove= and id=).&lt;br /&gt;
&lt;br /&gt;
=== [do_command] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Executes a command, specified using the same syntax as a [command] tag in [[ReplayWML]]. Not all [command]'s are valid: only these are accepted&lt;br /&gt;
&lt;br /&gt;
* [attack]&lt;br /&gt;
* [move]&lt;br /&gt;
* [recruit]&lt;br /&gt;
* [recall]&lt;br /&gt;
* [disband]&lt;br /&gt;
* [fire_event]&lt;br /&gt;
* [lua_ai]&lt;br /&gt;
&lt;br /&gt;
The tags corresponding to player actions generally use the same codepath as if a player had ordered it.&lt;br /&gt;
&lt;br /&gt;
One purpose of this tag is to allow scripting of noninteractive scenarios -- without a tag like this, this might require elaborate mechanisms to coerce ais in order to test these code paths.&lt;br /&gt;
&lt;br /&gt;
This command should always be replay safe.&lt;br /&gt;
&lt;br /&gt;
=== [full_heal] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Fully heals a unit matching the filter.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': the unit(s) to get healed.&lt;br /&gt;
* '''cures''': Whether the heal should remove poison and slow.&lt;br /&gt;
* '''animate''': Whether the heal should play the healed animation for each unit.&lt;br /&gt;
* '''ignore_status''': Whether the heal should affect units with unhealable=yes.&lt;br /&gt;
&lt;br /&gt;
=== [put_to_recall_list] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Puts a unit to the recall list of its side.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': the unit(s) to get put to the recall list.&lt;br /&gt;
* '''heal''': (default=no) Whether the unit should be refreshed, similar to the unit moving to the recall list at the end of a scenario.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Useful Macros ==&lt;br /&gt;
There are some predefined macros that you find useful for direct actions. You can find a complete list along with a detailed explanation of how they work [http://www.wesnoth.org/macro-reference.xhtml here].&lt;br /&gt;
* '''{MOVE_UNIT}''': Moves a unit to another location in the map and the player sees the movement (unlike [teleport])&lt;br /&gt;
* '''{FULL_HEAL}''': Brings a unit to full HP&lt;br /&gt;
* '''{LOYAL_UNIT}''': Create a loyal unit&lt;br /&gt;
* '''{MODIFY_TERRAIN_MASK}''': Modify an area of terrain&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=StandardUnitFilter&amp;diff=56210</id>
		<title>StandardUnitFilter</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=StandardUnitFilter&amp;diff=56210"/>
		<updated>2015-04-08T21:20:56Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added [filter] status=&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;From [[FilterWML]], this is the standard way of filtering units.&lt;br /&gt;
&lt;br /&gt;
When a unit filter is applied to a map, first it applies to all units on the field,&lt;br /&gt;
based on their coordinates.&lt;br /&gt;
Next it applies to units in the recall list.&lt;br /&gt;
This is important to remember as it means, for example,&lt;br /&gt;
that the tag '''[kill]''' can be used to kill units in the recall list.&lt;br /&gt;
&lt;br /&gt;
You can access the filtered unit within the filter as the ''$this_unit'' variable, see [[SingleUnitWML]] for the possible content of these variables&lt;br /&gt;
&lt;br /&gt;
The term [[StandardUnitFilter]] means that the set of such keys and tags (see below) can appear at that point. Often a [[StandardUnitFilter]] needs to be included in a [filter] tag. But many tags take the [[StandardUnitFilter]] directly as an argument, like [kill] and [have_unit]. See [[Special:WhatLinksHere/StandardUnitFilter]] for tags which can contain a StandardUnitFilter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following attributes and sub-tags are allowed:&lt;br /&gt;
&lt;br /&gt;
* '''id''': unit matches the given id. This is the same as ''id'' in the [unit] tag. Note that it is independent of a unit's user-visible name, which can be internationalized independent of this (see [[SingleUnitWML]]). id= can be a comma-separated list, every unit with one of these ids matches.&lt;br /&gt;
* '''speaker''': alias for id (no comma-separated list supported)&lt;br /&gt;
* '''type''': matches the unit's type name (can be a list of types)&lt;br /&gt;
* '''race''': the race of the unit type. This can be a comma-separated list; the unit's race must match one of the given races. &amp;lt;br&amp;gt;Mainline races are listed in data/core/units.cfg&amp;lt;br&amp;gt; &lt;br /&gt;
* '''ability''': unit has an ability with the given id; see [[AbilitiesWML]]&lt;br /&gt;
* {{DevFeature1.13|0}} '''status''': matches if the unit has the specified status active. This can be a comma-separated list, in which case the unit will match as long as it has one of the listed statuses active&lt;br /&gt;
* '''side''': the unit is on the given side (can be a list)&lt;br /&gt;
* '''has_weapon''': the unit has a weapon with the given name&lt;br /&gt;
* '''canrecruit''': yes if the unit can recruit (i.e. is a leader)&lt;br /&gt;
* '''gender''': female if the unit is female rather than the default of male&lt;br /&gt;
* '''role''': the unit has been assigned the given role; see '''[role]''', [[InternalActionsWML]]&lt;br /&gt;
* '''level''': the level of the unit&lt;br /&gt;
* '''defense''': current defense of the unit on current tile (chance to hit %, like in movement type definitions)&lt;br /&gt;
* '''movement_cost''': current movement cost of the unit on current tile&lt;br /&gt;
* '''x,y''': the position of the unit. Note: there is a special case for units on the recall list such that x,y=&amp;quot;recall,recall&amp;quot;&lt;br /&gt;
* '''find_in''': name of an array or container variable; if present, the unit will not match unless it is also found stored in the variable&lt;br /&gt;
* '''[filter_vision]''': this tests whether or not the unit is currently visible&lt;br /&gt;
** '''visible''': yes or no, default yes. When &amp;quot;yes&amp;quot;, this matches units that are not obscured by fog or shroud, and that are not hiding (via the {{tag|AbilitiesWML|hides}} ability). When &amp;quot;no&amp;quot;, this matches units that are obscured by fog or shroud, or that are hiding.&lt;br /&gt;
** [[StandardSideFilter]] tags and keys. Filter for who may be able to see (or not see) the unit. If there is *at least one* matching side which can see the unit then the filter matches, and otherwise it fails to match.&lt;br /&gt;
* '''[filter_wml]''': this is WML level filter for the unit. In it, you can filter on anything that is in the WML description of a unit. This description can be found in any savegame also in [[SingleUnitWML]]. If the filter encounters a nested '''[not]''' tag, the attributes and containers inside the tag should not match for the upper filter to match. Note: [filter_wml] is especially slow, unless it contains only a child [variables], which is used for matching variables stored inside the unit.&lt;br /&gt;
* '''[and]''': an extra unit filter. Unless the unit also matches the [and] filter, then it will not count as a match. ''Note: [and],[or], and [not] filters are considered after the containing filter; they are then processed in the order encountered.''&lt;br /&gt;
* '''[or]''': an extra unit filter. If a unit matches the [or] filter, then it will count as a match regardless of conditions in previous filters or the containing filter.&lt;br /&gt;
* '''[not]''': an extra unit filter. If a unit matches the [not] filter, then that unit will not be considered a match by the containing filter.&lt;br /&gt;
* '''[filter_adjacent]''' with a StandardUnitFilter as argument; do not use a [filter] tag. If present the correct number of adjacent units must match this filter.&lt;br /&gt;
**'''StandardUnitFilter''' tags and keys&lt;br /&gt;
** '''count''': a number, range, or comma separated range; default &amp;quot;1-6&amp;quot;&lt;br /&gt;
** '''adjacent''': a comma separated list of directions; default &amp;quot;n,ne,se,s,sw,nw&amp;quot;&lt;br /&gt;
** '''is_enemy''': a boolean specifying whether the adjacent unit must be an enemy or an ally (optional)&lt;br /&gt;
* '''[filter_location]''': [[StandardLocationFilter]] - the tile that the unit is standing on matches the location filter.&lt;br /&gt;
*'''[filter_side]''': The currently filtered unit's side must match this [[StandardSideFilter]] for the unit to match.&lt;br /&gt;
**[[StandardSideFilter]] tags and keys&lt;br /&gt;
* '''formula''': [[FormulaAI]] like formula returning a boolean (here that is 1 or 0). The unit filtered is an implicit variable in the call.&lt;br /&gt;
* '''lua_function''': the name of a [[LuaWML|Lua]] function in the global environment that takes a unit as an argument and returns true if the given unit matches the filter.&lt;br /&gt;
&lt;br /&gt;
== A Note about Re-Using the Same Attribute ==&lt;br /&gt;
You are limited to having each attribute, such as '''id''', appear once or less in a [[StandardUnitFilter]]. However, this can be worked around. If you have several specific units you want excepted from matching, use a separate [or] subfilters for each one. Also you can use [not] subfilters. For example to kill ([kill] uses the standard unit filter) all units except Gwiti Ha'atel and Tanar you can do the following:&lt;br /&gt;
  [kill]&lt;br /&gt;
    [not]&lt;br /&gt;
      id=Gwiti Ha'atel&lt;br /&gt;
    [/not]&lt;br /&gt;
    [not]&lt;br /&gt;
      id=Tanar&lt;br /&gt;
    [/not]&lt;br /&gt;
  [/kill]&lt;br /&gt;
:And similarly if you wanted to kill both Gwiti Ha'atel and Tanar, but no one else you could do the following:&lt;br /&gt;
  [kill]&lt;br /&gt;
    id=Gwiti Ha'atel&lt;br /&gt;
    [or]&lt;br /&gt;
      id=Tanar&lt;br /&gt;
    [/or]&lt;br /&gt;
  [/kill]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [http://wiki.wesnoth.org/FilterWML/Examples_-_How_to_use_Filter Examples - How to use filters]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56151</id>
		<title>ImagePathFunctions</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ImagePathFunctions&amp;diff=56151"/>
		<updated>2015-03-12T10:42:51Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added ~SEPIA() and ~NEG() functions&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Image Path Functions provide a simple method for WML coders to alter the way their specified images will be displayed in the game. All of the function parameters are included at the end of an image path and should not contain any spaces or special characters (other than those specified here).&lt;br /&gt;
&lt;br /&gt;
If you need to practice it without having to reload all WML, you can use an add-on named ''Image loading tester'' from the 1.10 add-on server.&lt;br /&gt;
&lt;br /&gt;
== Team-Color Function ==&lt;br /&gt;
In Wesnoth version 1.2, the only Image Path Function was '''~TC()''', which took two comma-separated parameters: the team number and the source color palette. The valid values for both of these parameters are defined in the file ''data/team-colors.cfg''&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~TC(''' ''team number'' ''',''' ''source color palette'' ''')'''&lt;br /&gt;
*''team number'' - this is the first parameter, a number 1-9 signifying the team number of a unit. Number 1 typically means the red team, 2 typically means the blue team, and so on (unless the scenario color settings for any side have been altered).&lt;br /&gt;
*''source color palette'' - the second parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
&lt;br /&gt;
== Re-Color Function ==&lt;br /&gt;
May be used to change some colors in an image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~RC(''' ''source color palette'' '''&amp;gt;''' ''color range ID'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, usually magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''color range ID'' - this is the second parameter, signifying the ID of a color range defined in the file ''data/core/team-colors.cfg'' (or it may be a custom ID for a color range defined locally).  &lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
In the following example, the magenta regions in an elvish captain's image are turned  a healthy shade of green:&lt;br /&gt;
&lt;br /&gt;
  [message]&lt;br /&gt;
      speaker=narrator&lt;br /&gt;
      image=units/elves-wood/captain.png~RC(magenta&amp;gt;green)&lt;br /&gt;
      message=_ &amp;quot;Now I am on the green team.&amp;quot;&lt;br /&gt;
  [/message]&lt;br /&gt;
&lt;br /&gt;
The IDs of the color ranges may be the lowercased English name of the palette's base color (e.g. 'red', 'brown', etc.). They may also be numeric color indices from the palette WML included with the game, but this is not recommended.&lt;br /&gt;
&lt;br /&gt;
== Palette-switch Function ==&lt;br /&gt;
May be used to change colors in an image following the specifications of a source and target (new) palette.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~PAL(''' ''source color palette'' '''&amp;gt;''' ''target color palette'' ''')'''&lt;br /&gt;
*''source color palette'' - the first parameter is a source color palette, such as magenta. Do not surround this parameter with quotes.&lt;br /&gt;
*''target color palette'' - the new palette to take the place of the source colors in the image.&lt;br /&gt;
&lt;br /&gt;
== Flip Function ==&lt;br /&gt;
May be used to flip an image horizontally and/or vertically.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~FL(''' ''optional argument list'' ''')'''&lt;br /&gt;
*''vertical'' - if the string &amp;quot;vert&amp;quot; is found anywhere in the argument list, the image will be flipped vertically.&lt;br /&gt;
*''horizontal'' - if the string &amp;quot;horiz&amp;quot; is found anywhere in the argument list, the image will be flipped horizantally.&lt;br /&gt;
*if the argument list is empty, the image will only be flipped horizontally.&lt;br /&gt;
&lt;br /&gt;
== Rotate Function ==&lt;br /&gt;
{{devfeature1.11}}&lt;br /&gt;
May be used to rotate an image by a multiple of 90 degrees.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~ROTATE(''' ''degrees'' ''')'''&lt;br /&gt;
* ''degrees'' - The number of degrees by which the image will be rotated. This must be a multiple of 90. Positive numbers indicate clockwise rotation, while negative numbers indicate counter-clockwise. (Zero indicates no rotation.)&lt;br /&gt;
If the number of degrees is omitted, a quarter turn (90 degrees) clockwise is assumed.&lt;br /&gt;
&lt;br /&gt;
== Greyscale Function ==&lt;br /&gt;
May be used to greyscale the image (turn to black and white)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~GS( )'''&lt;br /&gt;
&lt;br /&gt;
== Sepia Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
May be used to give to the image a sepia tint (like in old pictures).&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~SEPIA()'''&lt;br /&gt;
&lt;br /&gt;
== Negative Function ==&lt;br /&gt;
{{devfeature1.13|0}}&lt;br /&gt;
Also known as ''invert'', it negates all the RGB values of the image, giving it an effect similar to a photographic negative.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~NEG( )'''&lt;br /&gt;
&lt;br /&gt;
== Crop Function ==&lt;br /&gt;
Extracts a rectangular section of an image file.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~CROP(x,y,width,height)'''&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates for the rectangular section extracted. Must be greater or equal than zero, and inside the image's bounds.&lt;br /&gt;
* ''width'': width of the selected region. Must be less than or equal to the original image's width, and must not be negative.&lt;br /&gt;
* ''height'': height of the selected region. Must be less than or equal to the original image's height, and must not be negative.&lt;br /&gt;
&lt;br /&gt;
== Blit Function ==&lt;br /&gt;
Blit the parameter image on the main image. Example: peasant.png~BLIT(hat.png,30,10)&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLIT(src,x,y)'''&lt;br /&gt;
* ''src'': an image file used as source for the blit, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to blit. Must be greater or equal than zero. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
== Mask Function ==&lt;br /&gt;
Remove parts of the main image using the parameter image as a mask. Example: grass.png~MASK(circle.png) will give a circle of grass.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~MASK(mask,x,y)'''&lt;br /&gt;
* ''mask'': an image file used as mask, other image path functions can be used there.&lt;br /&gt;
* ''x'',''y'': top-left corner coordinates where to put the mask. Parts ouside of the mask are considered transparent. If missing assume (0,0).&lt;br /&gt;
&lt;br /&gt;
Only the alpha channel of the mask is used and each alpha value will be the maximum alpha of the resulting image. This means that the fully-transparent parts of the mask will erase the corresponding parts of the image, but also that a semi-transparent mask will create a semi-transparent image. &lt;br /&gt;
&lt;br /&gt;
== Color-shift function ==&lt;br /&gt;
Performs simple per-channel color shifts by adding the arguments to the respective color channels.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
''Multi-channel:'' '''~CS(r,g,b)'''&lt;br /&gt;
''Single-channel:'' '''~R(v)''', '''~G(v)''', '''~B(v)'''&lt;br /&gt;
&lt;br /&gt;
The multichannel syntax assumes all arguments are set to zero initially, so one can use, e.g. ~CS(2,4) to add +2 and +4 units to the red and green channels respectively, leaving the blue channel intact. Arguments may be negative to diminish a channel's value; this can be used to change an image's brightness. Checks for out-of-range arguments or results (less than 0 or greater than 255) are made, so the resultant values are truncated if necessary.&lt;br /&gt;
&lt;br /&gt;
The single channel syntax behaves exactly the same, except that only single-channel modifications are made per function. However, one can stack them to produce the same behavior as ~CS(), e.g. ~R(r)~G(g)~B(b), but that tends to be just a performance loss.&lt;br /&gt;
&lt;br /&gt;
== Color-blend function ==&lt;br /&gt;
{{DevFeature1.11}}&lt;br /&gt;
Blends the image with the given color to produce a more controlled tinting effect than color-shifting, independently of the image's contents.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~BLEND(r,g,b,o)'''&lt;br /&gt;
&lt;br /&gt;
The color is defined by the ''r'', ''g'', and ''b'' parameters (integers ranging from 0 to 255). The ''o'' (opacity) parameter controls the amount by which the given color will be blended into the image, and may be specified either as a factor from 0.0 to 1.0, or percentage up to 100%. Thus, ~BLEND(r,g,b,0.5) and ~BLEND(r,g,b,50%) are equivalent.&lt;br /&gt;
&lt;br /&gt;
== Lightmap color-shift function ==&lt;br /&gt;
Performs per-pixel and per-channel color shifts using another image (a &amp;quot;lightmap&amp;quot;) as source, allowing to create textured light effects.&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
'''~L(lightmap)'''&lt;br /&gt;
&lt;br /&gt;
For each pixel of the original image, it checks the RGB values from the corresponding pixel of the lightmap, slightly transform them, then add these values to the original pixel.&lt;br /&gt;
&lt;br /&gt;
The transformation involved is done to convert the (0,255) spectrum to (-255,255), allowing to add or subtract color. The formula is (x-128)*2, which means that 0 gives -256, 128 gives 0 and 255 gives 254. So, the no-effect lightmap is a fully gray image (RGB = 128,128,128) and any non-gray pixel will shift the colors of the original.&lt;br /&gt;
&lt;br /&gt;
Note that the lightmap will be scaled to the same dimensions as the original image.&lt;br /&gt;
&lt;br /&gt;
== Image-scaling function ==&lt;br /&gt;
Scales a graphic up or down.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~SCALE( ''new_width'', ''new_height'' )&lt;br /&gt;
&lt;br /&gt;
The ''new_width'' and ''new_height'' parameters are taken as the image's original width or height, respectively, if one of them happens to be zero. Negative values are treated in the same way, but an error is printed in stderr.&lt;br /&gt;
&lt;br /&gt;
== Opacity modifying function ==&lt;br /&gt;
Changes an image's opacity at render time.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~O( ''factor or percentage%'' )'''&lt;br /&gt;
&lt;br /&gt;
If the argument includes the percentage symbol (''%''), it will be treated as a percentage of full (real) opacity; an image will be displayed at its native opacity with ~O(100%).&lt;br /&gt;
&lt;br /&gt;
Without the percentage symbol, the argument is assumed to be a factor by which the image's native opacity should be multiplied. Thus, ~O(0.5) and ~O(50%) are equivalent forms of specifying to reduce an image's opacity by half.&lt;br /&gt;
&lt;br /&gt;
== Blurring function ==&lt;br /&gt;
Blurs a graphic at render time using the same algorithm used for in-game dialogs.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BL( ''radius'' )'''&lt;br /&gt;
&lt;br /&gt;
== Overlay function ==&lt;br /&gt;
Puts a time-of-day overlay on the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~LIGHTEN()'''&lt;br /&gt;
&lt;br /&gt;
'''~DARKEN()'''&lt;br /&gt;
&lt;br /&gt;
== Background coloring function ==&lt;br /&gt;
Sets the color of all the (semi-)transparent pixels of the image.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~BG(r,g,b)'''&lt;br /&gt;
&lt;br /&gt;
== Null function ==&lt;br /&gt;
Does nothing.&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
'''~NOP()'''&lt;br /&gt;
&lt;br /&gt;
== Precedence of Functions  ==&lt;br /&gt;
&lt;br /&gt;
All functions are applied in left-to-right order, with the exception of RC(), TC() and PAL() which are applied always before any other functions. Standard team coloring for a unit is applied after all custom RC(), TC() and PAL() functions but before any other functions.&lt;br /&gt;
That is, stuff like &amp;quot;units/elves-wood/fighter.png~CROP(20,20,40,40)~CROP(10,10,10,10)&amp;quot; would result in taking a crop to a 40x40 rectangle whose top-left corner is x=20, y=20; and then taking a crop from ''that'' rectangle with x=10, y=10, w=10, h=10. The result is the area x=30, y=30, w=10, h=10 from the original graphic.&lt;br /&gt;
&lt;br /&gt;
[[Category:WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=56046</id>
		<title>LuaWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=56046"/>
		<updated>2015-01-14T11:31:31Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* Global environment */ Support for bit32 (bitwise) library&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
== The '''[lua]''' tag ==&lt;br /&gt;
&lt;br /&gt;
This tag is a part of [[ActionWML]], thus can be used inside [event] and at other places where [[ActionWML]] can be used. It makes it possible to write actions with the [http://www.lua.org Lua 5.2] language.&lt;br /&gt;
&lt;br /&gt;
It is also possible to put this tag inside a [scenario] [[ScenarioWML]], those tags will be executed immideately when the lua engine loads which is even before the scenario preload event is fired.&lt;br /&gt;
&lt;br /&gt;
The tag supports only the '''code''' key, which is a string containing the Lua scripts. Since Lua makes usage of the quotes and the { and } symbols, it is certainly wise to enclose the script between stronger quotes, as they prevent the preprocessor from performing macro expansion and tokenization.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; wesnoth.message &amp;quot;Hello World!&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
The Lua kernel can also be accessed from the [[CommandMode|command mode]]:&lt;br /&gt;
&lt;br /&gt;
 :lua local u = wesnoth.get_units({ id = &amp;quot;Konrad&amp;quot; })[1]; u.moves = 5&lt;br /&gt;
&lt;br /&gt;
The '''[args]''' sub-tag can be used to pass a WML object to the script via its variadic local variable &amp;quot;'''...'''&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; local t = ...; wesnoth.message(tostring(t.text)) &amp;gt;&amp;gt;&lt;br /&gt;
     [args]&lt;br /&gt;
         text = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/args]&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
== Global environment ==&lt;br /&gt;
&lt;br /&gt;
All the Lua scripts of a scenario share the same global environment (aka Lua state). For instance, a function defined in an event can be used in all the events that happen after it.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             function narrator(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
In the example above, the redundant structure could be hidden behind macros. But it may be better to simply define a new WML tag.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             -- The function is now local, since its name does not have to be&lt;br /&gt;
             -- visible outside this Lua scripts.&lt;br /&gt;
             local function handler(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
             -- Create a new tag named [narrator].&lt;br /&gt;
             wesnoth.register_wml_action(&amp;quot;narrator&amp;quot;, handler)&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
The global environment is not preserved over save/load cycles. Therefore, storing values in the global environment is generally a bad idea (unless it has been redirected to WML variables, see [[LuaWML:Variables#set_wml_var_metatable|helper.set_wml_var_metatable]]). The only time assigning global variables (including function definitions) makes sense is during a [[EventWML#Predefined 'name' Key Values|preload]] event, as this event is always run. Therefore, helper functions defined at that time will be available to all the later scripts.&lt;br /&gt;
&lt;br /&gt;
The global environment initially contains the following modules: [http://www.lua.org/manual/5.1/manual.html#5.1 basic] (no name), [http://www.lua.org/manual/5.1/manual.html#5.4 string], [http://www.lua.org/manual/5.1/manual.html#5.5 table], and [http://www.lua.org/manual/5.1/manual.html#5.6 math]. {{DevFeature1.13|0}} The [http://www.lua.org/manual/5.2/manual.html#6.7 bit32] library is supported as well. A '''wesnoth''' module is also available, it provides access to the [[#Interface to the C++ engine|C++ engine]]. Additionally, the functions clock, date, time and difftime from the [http://www.lua.org/manual/5.1/manual.html#5.8 os] library (keep in mind that they aren't multiplayer- and replay-safe), as well as traceback from the [http://www.lua.org/manual/5.1/manual.html#5.9 debug] library are also available.&lt;br /&gt;
&lt;br /&gt;
At the start of a script, the variadic local variable '''...''' (three dots) is a proxy table representing [[#Encoding WML objects into Lua tables|WML data]]. This table is the content of the '''[args]''' sub-tag of the '''[lua]''' tag, if any.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following WML event is taken from Wesnoth' tutorial. It will serve as an example to present how Lua scripts are embedded into Wesnoth. The event is fired whenever a unit from side 1 (that is, the hero controlled by the user) moves to a tile that is not the one set in the WML variable ''target_hex''.&lt;br /&gt;
&lt;br /&gt;
 # General catch for them moving to the wrong place.&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [if]&lt;br /&gt;
         [variable]&lt;br /&gt;
             name=target_hex.is_set&lt;br /&gt;
             equals=yes&lt;br /&gt;
         [/variable]&lt;br /&gt;
         [then]&lt;br /&gt;
             [if]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=x1&lt;br /&gt;
                     equals=$target_hex.x&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=y1&lt;br /&gt;
                     equals=$target_hex.y&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [then]&lt;br /&gt;
                 [/then]&lt;br /&gt;
                 [else]&lt;br /&gt;
                     [redraw][/redraw]&lt;br /&gt;
                     [message]&lt;br /&gt;
                         speaker=narrator&lt;br /&gt;
                         message=_ &amp;quot;*Oops!&lt;br /&gt;
 You moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot; +&lt;br /&gt;
                         _ &amp;quot;&lt;br /&gt;
 *Left click or press spacebar to continue...&amp;quot;&lt;br /&gt;
                     [/message]&lt;br /&gt;
                 [/else]&lt;br /&gt;
             [/if]&lt;br /&gt;
         [/then]&lt;br /&gt;
     [/if]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
A Lua script that performs the same action is presented below.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             local event_data = wesnoth.current.event_context&lt;br /&gt;
             if V.target_hex.is_set and&lt;br /&gt;
                (event_data.x1 ~= V.target_hex.x or event_data.y1 ~= V.target_hex.y)&lt;br /&gt;
             then&lt;br /&gt;
                 W.redraw()&lt;br /&gt;
                 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Here is a more detailed explanation of the Lua code. Its first line&lt;br /&gt;
&lt;br /&gt;
 local event_data = wesnoth.current.event_context&lt;br /&gt;
&lt;br /&gt;
puts the event data into the ''event_data'' local variable. Since it is a ''moveto'' event, the ''event_data'' table contains the destination of the unit in the ''x1'' and ''y1'' fields.&lt;br /&gt;
&lt;br /&gt;
The next two lines then test&lt;br /&gt;
&lt;br /&gt;
 if V.target_hex.is_set and&lt;br /&gt;
    (event_data.x1 ~= V.target_hex.x or event_data.y1 ~= V.target_hex.y)&lt;br /&gt;
&lt;br /&gt;
whether the variable ''V.target_hex'' matches the event parameters. Since ''V'' is not a local variable, it is taken from the global environment. Usually, variables from the global environment are not persistent (they get lost on reloading), so it shouldn't be used to store data. In order to have an easy way to access the usual persistent Wml variables, the global variable ''V''  was mapped to the storage of WML variables by the following ''preload'' event.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             -- skipping some other initializations&lt;br /&gt;
             -- ...&lt;br /&gt;
             V = H.set_wml_var_metatable {}&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Without a prelude redirecting ''V'', the conditional would have been written&lt;br /&gt;
&lt;br /&gt;
 if wesnoth.get_variable(&amp;quot;target_hex.is_set&amp;quot;) and&lt;br /&gt;
    (event_data.x1 ~= wesnoth.get_variable(&amp;quot;target_hex.x&amp;quot;) or event_data.y1 ~= wesnoth.get_variable(&amp;quot;target_hex.y&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The body of the conditional then performs the [[InterfaceActionsWML#Other interface tags|[redraw]]] action.&lt;br /&gt;
&lt;br /&gt;
 W.redraw()&lt;br /&gt;
&lt;br /&gt;
Again, this short syntax is made possible by a line of the prelude that makes ''W'' a proxy for performing WML actions.&lt;br /&gt;
&lt;br /&gt;
 W = H.set_wml_action_metatable {}&lt;br /&gt;
&lt;br /&gt;
Without this shortcut, the first statement would have been written&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;redraw&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Finally the script displays a message by&lt;br /&gt;
&lt;br /&gt;
 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The ''narrator_says'' function is defined in the prelude too, since the construct behind it occurs several times in the tutorial. In plain WML, macros would have been used instead. The definition of the function is&lt;br /&gt;
&lt;br /&gt;
 function narrator_says(m)&lt;br /&gt;
     W.message { speaker=&amp;quot;narrator&amp;quot;,&lt;br /&gt;
                 message = m .. _ &amp;quot;\n*Left click or press spacebar to continue...&amp;quot; }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The function fires a [[InterfaceActionsWML#.5Bmessage.5D|[message]]] action and passes a WML object containing the usual two fields to it. The second field is initialized by concatenating the function argument with another string. Both strings are prefixed by the ''_'' symbol to mark them as translatable. (Note that ''_'' is just a unary function, not a keyword.) Again, this is made possible by a specific line of the prelude:&lt;br /&gt;
&lt;br /&gt;
 _ = wesnoth.textdomain &amp;quot;wesnoth-tutorial&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A longer translation of the tutorial is available at [https://gna.org/patch/download.php?file_id=5483].&lt;br /&gt;
&lt;br /&gt;
== Interface to the engine and helper functions ==&lt;br /&gt;
&lt;br /&gt;
Functionalities of the game engine are available through the functions contained in the '''wesnoth''' global table. Some of these functions return proxy tables. Writes to fields marked &amp;quot;read-only&amp;quot; are ignored. The '''__cfg''' fields return plain tables; in particular, writes do not modify the original object, and reads return the values from the time the dump was performed.&lt;br /&gt;
&lt;br /&gt;
Some helper functions are provided by the '''lua/helper.lua''' library. They are stored inside a table that is returned when loading the library with [[LuaWML:Files#wesnoth.require|wesnoth.require]].&lt;br /&gt;
&lt;br /&gt;
 helper = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== WML variables ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_all_vars|wesnoth.get_all_vars]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Variables#helper.set_wml_var_metatable|helper.set_wml_var_metatable]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_child|helper.get_child]]&lt;br /&gt;
* [[LuaWML:Variables#helper.child_range|helper.child_range]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_array|helper.get_variable_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_proxy_array|helper.get_variable_proxy_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.set_variable_array|helper.set_variable_array]]&lt;br /&gt;
&lt;br /&gt;
=== Events and WML actions ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire|wesnoth.fire]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.wml_actions|wesnoth.wml_actions]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.game_events|wesnoth.game_events]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire_event|wesnoth.fire_event]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.eval_conditional|wesnoth.eval_conditional]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.tovconfig|wesnoth.tovconfig]]&lt;br /&gt;
* [[LuaWML:Events#helper.set_wml_action_metatable|helper.set_wml_action_metatable]]&lt;br /&gt;
* [[LuaWML:Events#helper.wml_error|helper.wml_error]]&lt;br /&gt;
* [[LuaWML:Events#helper.literal|helper.literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.parsed|helper.parsed]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_literal|helper.shallow_literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_parsed|helper.shallow_parsed]]&lt;br /&gt;
&lt;br /&gt;
=== User interface ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Display#wesnoth.message|wesnoth.message]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.clear_messages|wesnoth.clear_messages]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.textdomain|wesnoth.textdomain]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.delay|wesnoth.delay]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.float_label|wesnoth.float_label]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_hex|wesnoth.select_hex]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.scroll_to_tile|wesnoth.scroll_to_tile]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.lock_view|wesnoth.lock_view]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.view_locked|wesnoth.view_locked]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.play_sound|wesnoth.play_sound]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_music|wesnoth.set_music]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_dialog|wesnoth.show_dialog]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_value|wesnoth.set_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_dialog_value|wesnoth.get_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_active|wesnoth.set_dialog_active]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_callback|wesnoth.set_dialog_callback]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_markup|wesnoth.set_dialog_markup]] {{DevFeature1.11|9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_canvas|wesnoth.set_dialog_canvas]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_displayed_unit|wesnoth.get_displayed_unit]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.theme_items|wesnoth.theme_items]]&lt;br /&gt;
* [[LuaWML:Display#helper.get_user_choice|helper.get_user_choice]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_time_of_day|wesnoth.get_time_of_day]]&lt;br /&gt;
&lt;br /&gt;
=== Map and terrains ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_map_size|wesnoth.get_map_size]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain|wesnoth.get_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.set_terrain|wesnoth.set_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain_info|wesnoth.get_terrain_info]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_selected_tile|wesnoth.get_selected_tile]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_locations|wesnoth.get_locations]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_villages|wesnoth.get_villages]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.match_location|wesnoth.match_location]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_tile_overlay|wesnoth.add_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_tile_overlay|wesnoth.remove_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_image|items.place_image]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_halo|items.place_halo]]&lt;br /&gt;
* [[LuaWML:Tiles#items.remove|items.remove]]&lt;br /&gt;
&lt;br /&gt;
=== Units ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_units|wesnoth.get_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit|wesnoth.get_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.match_unit|wesnoth.match_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_unit|wesnoth.put_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_recall_units|wesnoth.get_recall_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_recall_unit|wesnoth.put_recall_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.create_unit|wesnoth.create_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.copy_unit|wesnoth.copy_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.extract_unit|wesnoth.extract_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_modification|wesnoth.add_modification]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_resistance|wesnoth.unit_resistance]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_defense|wesnoth.unit_defense]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_movement_cost|wesnoth.unit_movement_cost]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_ability|wesnoth.unit_ability]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type_ids|wesnoth.get_unit_type_ids]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type|wesnoth.get_unit_type]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_types|wesnoth.unit_types]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.races|wesnoth.races]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_traits|wesnoth.get_traits]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.simulate_combat|wesnoth.simulate_combat]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.transform_unit|wesnoth.transform_unit]]&lt;br /&gt;
&lt;br /&gt;
=== Sides ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_side|wesnoth.get_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.sides|wesnoth.sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_sides|wesnoth.get_sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_village_owner|wesnoth.get_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.set_village_owner|wesnoth.set_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.is_enemy|wesnoth.is_enemy]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.match_side|wesnoth.match_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_starting_location|wesnoth.get_starting_location]]&lt;br /&gt;
* [[LuaWML:Sides#helper.all_teams|helper.all_teams]]&lt;br /&gt;
&lt;br /&gt;
=== Pathfinder ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_path|wesnoth.find_path]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_vacant_tile|wesnoth.find_vacant_tile]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_reach|wesnoth.find_reach]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_cost_map|wesnoth.find_cost_map]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.distance_between|helper.distance_between]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.adjacent_tiles|helper.adjacent_tiles]]&lt;br /&gt;
&lt;br /&gt;
=== Lua files ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Files#wesnoth.dofile|wesnoth.dofile]]&lt;br /&gt;
* [[LuaWML:Files#wesnoth.require|wesnoth.require]]&lt;br /&gt;
&lt;br /&gt;
=== Location sets ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Location_set#location_set.create|location_set.create]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_pairs|location_set.of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_wml_var|location_set.of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:empty|location_set:empty]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:size|location_set:size]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:clear|location_set:clear]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:get|location_set:get]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:insert|location_set:insert]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:remove|location_set:remove]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_pairs|location_set:of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_wml_var|location_set:of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_pairs|location_set:to_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_stable_pairs|location_set:to_stable_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_wml_var|location_set:to_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union|location_set:union]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter|location_set:inter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:iter|location_set:iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:stable_iter|location_set:stable_iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:filter|location_set:filter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union_merge|location_set:union_merge]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter_merge|location_set:inter_merge]]&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.game_config|wesnoth.game_config]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_era|wesnoth.get_era]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.current|wesnoth.current]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.synchronize_choice|wesnoth.synchronize_choice]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_image_size|wesnoth.get_image_size]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compare_versions|wesnoth.compare_versions]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.have_file|wesnoth.have_file]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.debug|wesnoth.debug]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_time_stamp|wesnoth.get_time_stamp]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#helper.set_wml_tag_metatable|helper.set_wml_tag_metatable]]&lt;br /&gt;
* [[LuaWML:Misc#helper.modify_unit|helper.modify_unit]]&lt;br /&gt;
* [[LuaWML:Misc#helper.move_unit_fake|helper.move_unit_fake]]&lt;br /&gt;
* [[LuaWML:Misc#helper.rand|helper.rand]]&lt;br /&gt;
* [[LuaWML:Misc#helper.round|helper.round]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#helper.shuffle|helper.shuffle]] {{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
== Encoding WML objects into Lua tables ==&lt;br /&gt;
&lt;br /&gt;
Function [[LuaWML:Events#wesnoth.fire|wesnoth.fire]] expects a table representing a WML object as its second argument (if needed). Function [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]] allows to modify whole WML objects, again by passing it a table. Function [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]] transforms a WML object into a table, if its second argument is not set to ''true''. All these tables have the same format.&lt;br /&gt;
&lt;br /&gt;
Scalar fields are transformed into WML attributes. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     a_bool = true,&lt;br /&gt;
     an_int = 42,&lt;br /&gt;
     a_float = 1.25,&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;,&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     a_bool = &amp;quot;yes&amp;quot;&lt;br /&gt;
     an_int = &amp;quot;42&amp;quot;&lt;br /&gt;
     a_float = &amp;quot;1.25&amp;quot;&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
WML child objects are not stored as Lua named fields, since several of them can have the same tag. Moreover, their tags can conflict with the attribute keys. So child objects are stored as pairs string + table in the unnamed fields in definition order. This means that for every subtag appearing in the wml code there is an additional table &amp;quot;layer&amp;quot; in the corresponding WML table of the form {[1] = &amp;quot;tag_name&amp;quot;, [2] = {}} which is equivalent to {&amp;quot;tag_name&amp;quot;, {}}. [1] etc are the unnamed fields (as opposed to wml attributes). The table under [2] in this subtable then holds the wml attributes from inside the wml subtag. So every subtag other than the toplevel tag corresponds to two nested tables each. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { v = 1, w = 2 } },&lt;br /&gt;
     { &amp;quot;foo&amp;quot;, { x = false } },&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     { &amp;quot;foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     foo = 42&lt;br /&gt;
     [bar]&lt;br /&gt;
         v = 1&lt;br /&gt;
         w = 2&lt;br /&gt;
     [/bar]&lt;br /&gt;
     [foo]&lt;br /&gt;
         x = no&lt;br /&gt;
     [/foo]&lt;br /&gt;
     [bar]&lt;br /&gt;
         y = foo&lt;br /&gt;
     [bar]&lt;br /&gt;
     [foobar]&lt;br /&gt;
         z = 5&lt;br /&gt;
         [barfoo]&lt;br /&gt;
         [/barfoo]&lt;br /&gt;
     [/foobar]&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
Both tables above are also equivalent to this WML table, where all unnamed fields are displayed:&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     [1] = { [1] = &amp;quot;bar&amp;quot;, [2] = { v = 1, w = 2 } },&lt;br /&gt;
     [2] = { [1] = &amp;quot;foo&amp;quot;, [2] = { x = false } },&lt;br /&gt;
     [3] = { [1] = &amp;quot;bar&amp;quot;, [2] = { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     [4] = { [1] = &amp;quot;foobar&amp;quot;, [2] = { z = 5, [1] = { [1] = &amp;quot;barfoo&amp;quot;, [2] = {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
So assuming ''cfg'' contains the above WML object, the following accesses are possible:&lt;br /&gt;
&lt;br /&gt;
 a_int = cfg.foo        -- &amp;quot;dummy.foo&amp;quot;, 42&lt;br /&gt;
 a_string = cfg[3][2].y -- &amp;quot;dummy.bar[1].y&amp;quot;, &amp;quot;foo&amp;quot;&lt;br /&gt;
 a_table = cfg[4][2]    -- &amp;quot;dummy.foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } }&lt;br /&gt;
&lt;br /&gt;
Consider using the [[LuaWML:Variables#helper.get_child|helper.get_child]] and [[LuaWML:Variables#helper.child_range|helper.child_range]] to ease the access to subtags.&lt;br /&gt;
&lt;br /&gt;
Functions registered by [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]] receive their data in a userdata object which has the exact same structure as above. It is read-only however. Accessing fields or children performs variable substitution on the fly. Its '''__parsed''' and '''__literal''' fields provide translations to plain tables (therefore writable). '''__literal''' returns the original text of the data (including dollar symbols in attributes and [insert_tag] children), while '''__parsed''' performs a variable substitution.&lt;br /&gt;
&lt;br /&gt;
For instance, if you cannot stand any longer the fact that '''first_time_only''' is set to yes by default for the '''[event]''' tag, you can redefine it. But we have to be careful not to cause variable substitution, since the engine would perform a second variable substitution afterwards.&lt;br /&gt;
&lt;br /&gt;
 local old_event_handler&lt;br /&gt;
 old_event_handler = register_wml_action(&amp;quot;event&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         -- Get the plain text from the user.&lt;br /&gt;
         local new_cfg = cfg.__literal&lt;br /&gt;
         -- The expression below is equivalent to cfg.__parsed.first_time_only,&lt;br /&gt;
         -- only faster. It is needed, since the first_time_only attribute may&lt;br /&gt;
         -- reference variables.&lt;br /&gt;
         local first = cfg.first_time_only&lt;br /&gt;
         -- Modify the default behavior of first_time_only.&lt;br /&gt;
         if first == nil then first = false end&lt;br /&gt;
         new_cfg.first_time_only = first&lt;br /&gt;
         -- Call the engine handler.&lt;br /&gt;
         old_event_handler(new_cfg)&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Note that, since the object is a userdata and not a table, '''pairs''' and '''ipairs''' are unfortunately not usable on it. So scripts have to work at a lower level. For instance, the following function returns the first sub-tag with a given name and it works both on WML tables and WML userdata:&lt;br /&gt;
&lt;br /&gt;
 function get_child(cfg, name)&lt;br /&gt;
     for i = 1, #cfg do&lt;br /&gt;
         local v = cfg[i]&lt;br /&gt;
         if v[1] == name then return v[2] end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Another approach for handling userdata and tables in the same way, would be to convert the former into the latter beforehand:&lt;br /&gt;
&lt;br /&gt;
 if getmetatable(cfg) == &amp;quot;wml object&amp;quot; then cfg = cfg.__parsed end&lt;br /&gt;
&lt;br /&gt;
The WML userdata provides two other special fields: '''__shallow_parsed''' and '''__shallow_literal'''. They return a table corresponding to the WML userdata with variable substitution performed on the attributes (or not). [insert_tag] tags have also been parsed, so the number of children is faithful. But contrarily to '''__parsed''' and '''__literal''', the process is not recursive: all the children are still WML userdata and variable substitution can still happen for them. These shallow translators are meant as optimized versions of the deep ones, when only the toplevel attributes need to be writable.&lt;br /&gt;
&lt;br /&gt;
== Skeleton of a preload event ==&lt;br /&gt;
&lt;br /&gt;
The following event is a skeleton for a prelude enabling Lua in your WML events. It creates a table ''H'' containing the functions from helper.lua and a table ''W'' that serves as a proxy for firing WML actions. It sets up a table ''T'' so be used for easier creation of valid WML tables. It also sets up a table ''V'' so that any access to it is redirected to the persistent WML storage.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             T = H.set_wml_tag_metatable {}&lt;br /&gt;
             V = H.set_wml_var_metatable {}&lt;br /&gt;
             _ = wesnoth.textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
             -- Define your global constants here.&lt;br /&gt;
             -- ...&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
             -- Define your global functions here.&lt;br /&gt;
             -- ...&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
It may be worth putting the whole Lua script above inside a separate file and having the ''preload'' event load it:&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; wesnoth.dofile &amp;quot;~add-ons/Whatever/file.lua&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
== Remarks ==&lt;br /&gt;
&lt;br /&gt;
The math.random function is not safe for replays and multiplayer games, since the random values will be different each time and on all the clients. Instead, the Lua code should rely on the [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] tag to synchronize random values.&lt;br /&gt;
&lt;br /&gt;
 function random(min, max)&lt;br /&gt;
   if not max then min, max = 1, min end&lt;br /&gt;
   wesnoth.fire(&amp;quot;set_variable&amp;quot;, { name = &amp;quot;LUA_random&amp;quot;, rand = string.format(&amp;quot;%d..%d&amp;quot;, min, max) })&lt;br /&gt;
   local res = wesnoth.get_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   wesnoth.set_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   return res&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference|*]]&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=56039</id>
		<title>DirectActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=56039"/>
		<updated>2015-01-05T10:05:09Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [modify_unit] */ Another clarification about [trait]s&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== Direct actions ==&lt;br /&gt;
&lt;br /&gt;
Direct actions are actions that have a direct effect on gameplay. They can be used inside of [[EventWML|events]].&lt;br /&gt;
&lt;br /&gt;
The following tags are actions:&lt;br /&gt;
&lt;br /&gt;
=== [endlevel] ===&lt;br /&gt;
Ends the scenario.&lt;br /&gt;
* '''result''': before the scenario is over, all events with ''name=result'' are triggered. If ''result=victory'', the player progresses to the next level (i.e., the next scenario in single player); if ''result=defeat'', the game returns to the main menu. &lt;br /&gt;
&lt;br /&gt;
When the result is &amp;quot;victory&amp;quot; the following keys can be used:&lt;br /&gt;
* '''bonus''': whether the player should get bonus gold (maximum possible gold that could have been earned by waiting the level out). The default is bonus=yes.&lt;br /&gt;
* '''carryover_report''': whether the player should receive a summary of the scenario outcome, the default is carryover_report=yes.&lt;br /&gt;
* '''save''': whether a start-of-scenario save should be created for the next scenario, the default is save=yes. Do not confuse this with saving of replays for the current scenario.&lt;br /&gt;
* '''replay_save''': whether a replay save for the current scenario is allowed, the default is replay_save=yes. If yes, the player's settings in preferences will be used to determine if a replay is saved. If no, will override and not save a replay.&lt;br /&gt;
* '''linger_mode''': If ...=yes, the screen is greyed out and there's the possibility to save before advancing to the next scenario, the default is linger_mode=yes.&lt;br /&gt;
* '''reveal_map''': (Multiplayer only) (Default is 'yes') If 'no', shroud doesn't disappear when game ended.&lt;br /&gt;
* '''next_scenario''': (default specified in '''[scenario]''' tag) the ID of the next scenario that should be played.  All units that side 1 controls at this point become available for recall in ''next_scenario''.&lt;br /&gt;
* '''carryover_percentage''': by default 80% of the gold is carried over to the next scenario, with this key the amount can be changed.&lt;br /&gt;
* '''carryover_add''': if true the gold will be added to the starting gold the next scenario, if false the next scenario will start with the amount of the current scenario (after taxes) or the minimum in the next scenario. Default is false.&lt;br /&gt;
* '''music''': (default specified in '''[scenario]''' or '''[game_config]''' tags) a comma-separated list of music tracks from which one will be chosen and played once after any events related to the end of level result are executed; by default, victory_music is used on victory, and defeat_music on defeat.&lt;br /&gt;
* '''end_credits''': {{DevFeature1.11}} Whether to display the credits screen at the end of a single-player campaign. Defaults to ''yes''. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text''': (translatable) Text that is shown centered in a black screen at the end of a campaign. Defaults to &amp;quot;The End&amp;quot;. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text_duration''': Delay, in milliseconds, before displaying the game credits at the end of a campaign. In other words, for how much time '''end_text''' is displayed on screen. Defaults to 3500. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* &amp;lt;strike&amp;gt;'''[next_scenario_settings]''': {{DevFeature1.11}} Any tags or attribute children of this optional argument to [endlevel] are merged into the scenario/multiplayer tag of the *next* scenario. This allows you to e.g. reconfigure the [side] tags or settings, just before load. &amp;lt;/strike&amp;gt; This feature was removed in 1.11.17, it might be redesigned and reintroduced.&lt;br /&gt;
* &amp;lt;strike&amp;gt;'''[next_scenario_append]''': {{DevFeature1.11}} Any tags of this optional argument are appended at high level to the next scenario. This is most appropriate for [event] tags, although you may find other uses. Example test scenario for these features: https://gna.org/support/download.php?file_id=20119 &amp;lt;/strike&amp;gt; This feature was removed in 1.11.17, it might be redesigned and reintroduced.&lt;br /&gt;
&lt;br /&gt;
=== [unit] ===&lt;br /&gt;
Places a unit on the map.  For syntax see [[SingleUnitWML]].&lt;br /&gt;
* {{Short Note:Predefined Macro|GENERIC_UNIT}}&lt;br /&gt;
* '''to_variable''':  spawn directly into a variable instead of on the map.&lt;br /&gt;
&lt;br /&gt;
=== [recall] ===&lt;br /&gt;
Recalls a unit taking into account any [http://wiki.wesnoth.org/SingleUnitWML filter_recall] of the leader.   The unit is recalled free of charge, and is placed near its leader, e.g., if multiple leaders are present, near the first found which would be able to normally recall it.&lt;br /&gt;
&lt;br /&gt;
If neither a valid map location is provided nor a leader on the map would be able to recall it, the tag is ignored.&lt;br /&gt;
 &lt;br /&gt;
* [[StandardUnitFilter]]: the first matching unit will be recalled.  If no units match this tag is ignored. Do not use a [filter] tag. If a comma separated list is given, every unit currently considered for recall is checked against all the types (not each single one of the types against all units).&lt;br /&gt;
* '''x,y''': the unit is placed here instead of next to the leader.&lt;br /&gt;
* '''show''': yes/no, default yes: whether the unit is animated (faded in) or instantly displayed&lt;br /&gt;
* '''fire_event''': boolean yes|no (default no); whether any according prerecall or recall events shall be fired.&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit (a nearby passable hex is chosen).&lt;br /&gt;
&lt;br /&gt;
=== [teleport] ===&lt;br /&gt;
Teleports a unit on map. {{Short Note:Predefined Macro|TELEPORT_UNIT}}&lt;br /&gt;
* '''[filter]''': [[StandardUnitFilter]] the first unit matching this filter will be teleported.&lt;br /&gt;
* '''x,y''': the position to teleport to.&lt;br /&gt;
* '''clear_shroud''': should shroud be cleared on arrival&lt;br /&gt;
* '''animate''': should a teleport animation be played (if the unit doesn't have a teleport animation, it will fade out/fade in)&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): normally, units will not be teleported into terrain that is impassable for them. Setting this attribute to &amp;quot;no&amp;quot; permits it.&lt;br /&gt;
&lt;br /&gt;
(Note: There is also a ability named teleport, see [[AbilitiesWML]].)&lt;br /&gt;
&lt;br /&gt;
=== [terrain_mask] ===&lt;br /&gt;
Changes the terrain on the map.  See [[TerrainMaskWML]].&lt;br /&gt;
&lt;br /&gt;
=== [terrain] ===&lt;br /&gt;
Changes the terrain on the map.&lt;br /&gt;
* '''terrain''': the character of the terrain to use.  See [[TerrainCodesWML]] to see what letter a type of terrain uses.&lt;br /&gt;
* [[StandardLocationFilter]]. This [[StandardLocationFilter]]'s terrain= key is used for the new terrain, filtering by terrain can be done with a nested [[StandardLocationFilter]]: [and]terrain=terrain_string_to_be_filtered_for.&lt;br /&gt;
* '''layer''': (overlay|base|both, default=both) only change the specified layer.&lt;br /&gt;
* '''replace_if_failed''': (default=no) When replacing just one layer failed, try to replace the whole terrain. If '''terrain''' is an overlay only terrain, use the default_base as base layer. If the terrain has no default base, do nothing.&lt;br /&gt;
Note: When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages it that there are too many choices to make; should a unit loose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [gold] ===&lt;br /&gt;
Gives sides gold.&lt;br /&gt;
* '''amount''': the amount of gold to give.&lt;br /&gt;
* '''side''': (default=1) the number of the side to give the gold to. Can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument {{DevFeature1.11}}: [gold][filter_side] is deprecated, use the new inline SSF.&lt;br /&gt;
&lt;br /&gt;
=== [unstore_unit] ===&lt;br /&gt;
Creates a unit from a game variable, and activates it on the playing field.  This must be a specific variable describing a unit, and may not be an array -- to unstore an entire array, iterate over it.  The variable is not cleared.  See also [[InternalActionsWML#.5Bstore_unit.5D|[store_unit]]], [[ConditionalActionsWML#.5Bwhile.5D|[while]]] and [[InternalActionsWML#.5Bclear_variable.5D|[clear_variable]]].&lt;br /&gt;
* '''variable''': the name of the variable.&lt;br /&gt;
* '''find_vacant''': whether the unit should be placed on the nearest vacant tile to its specified location.  If this is set to 'no'(default), then any unit on the same tile as the unit being unstored will be destroyed. &lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit. This key has no effect if find_vacant=no (no check performed then). Before 1.9 this key is always &amp;quot;no&amp;quot;.&lt;br /&gt;
* '''text''': (translatable) floating text to display above the unit, such as a damage amount&lt;br /&gt;
* '''red''', '''green''', '''blue''': (default=0,0,0) the color to display the text in. Values vary from 0-255. You may find it convenient to use the {COLOR_HARM} or {COLOR_HEAL} macro instead. (Use {COLOR_HARM} or {COLOR_HEAL} instead of the whole red,green,blue= line.)&lt;br /&gt;
* '''advance''': (default=true) if true the unit is advanced if it has enough XP. When modifying XP make sure to do it from inside a [[EventWML#Multiplayer_safety|synchronized event]] or it may lead to OOS errors especially when several advancement paths exist. Note that advance and post advance events are called, so infinite loops can happen.&lt;br /&gt;
* '''fire_event''': (boolean yes|no, default no) Whether any advance/post advance events shall be fired if an advancement takes place, no effect otherwise.&lt;br /&gt;
* '''animate''': {{DevFeature1.11}} (boolean yes|no, default yes) Whether &amp;quot;levelout&amp;quot; and &amp;quot;levelin&amp;quot; (or fade to white and back) animations shall be played if an advancement takes place, no effect otherwise.&lt;br /&gt;
* '''x''' ,'''y''': override unit location, &amp;quot;x,y=recall,recall&amp;quot; will put the unit on the unit's side's recall list.&lt;br /&gt;
Units can be unstored with negative (or zero) hit points. This can be useful if modifying a unit in its last_breath event (as the unit's death is already the next step), but tends to look wrong in other cases. In particular, it is possible to have units with negative hit points in play. Such units are aberrations, subject to unusual behavior as the game compensates for them. (For example, such units are currently automatically hit&amp;amp;ndash;and killed&amp;amp;ndash;in combat.) The details of the unusual behavior are subject to change between stable releases without warning.&lt;br /&gt;
&lt;br /&gt;
=== [allow_recruit] ===&lt;br /&gt;
Allows a side to recruit units it couldn't previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that is being allowed to recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [allow_extra_recruit] ===&lt;br /&gt;
Allows a leader to recruit units it couldn't previously recruit.&lt;br /&gt;
These types add to the types the leader can recruit because of [side]recruit=.&lt;br /&gt;
* '''extra_recruit''': the types of units that the unit can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_recruit] ===&lt;br /&gt;
Prevents a side from recruiting units it could previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can no longer recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that may no longer recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_extra_recruit] ===&lt;br /&gt;
Prevents a leader from recruiting units it could previously recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the side can no longer recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [set_recruit] ===&lt;br /&gt;
Sets the units a side can recruit.&lt;br /&gt;
* '''recruit''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that is having its recruitment set. This can be a comma-separated list. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [set_extra_recruit] === &lt;br /&gt;
Sets the units a leader can recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the leader can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [modify_side] ===&lt;br /&gt;
Modifies some details of a given side in the middle of a scenario.  '''The following listed properties are the only properties that [modify_side] can affect!'''&lt;br /&gt;
* '''side''': (default=1) the number of the side that is to be changed. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* '''income''': the income given at the begining of each turn.&lt;br /&gt;
* '''recruit''': a list of unit types, replacing the side's current recruitment list.&lt;br /&gt;
* '''team_name''': the team in which the side plays the scenario.&lt;br /&gt;
* '''user_team_name''': a translatable string representing the team's description. This has no effect on alliances. Defaults to ''team_name''.&lt;br /&gt;
* '''gold''': the amount of gold the side owns.&lt;br /&gt;
* '''village_gold''': the income setting per village for the side.&lt;br /&gt;
* '''controller''': the identifier string of the side's controller. Uses the same syntax of the ''controller'' key in the [[SideWML|[side]]] tag.&lt;br /&gt;
* '''fog''': a boolean string (yes/no) describing the status of Fog for the side.&lt;br /&gt;
* '''shroud''': a boolean string describing the status of Shroud for the side.&lt;br /&gt;
* '''hidden''': a boolean string specifying whether side is shown in status table.&lt;br /&gt;
* '''color''': {{DevFeature1.11}} a team color range specification, name (e.g. &amp;quot;red&amp;quot;, &amp;quot;blue&amp;quot;), or number (e.g. &amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;) for this side. The default color range names, numbers, and definitions can be found in data/core/team_colors.cfg.&lt;br /&gt;
* '''[ai]''': sets/changes AI parameters for the side. Only parameters that are specified in the tag are changed, this does not reset others to their default values. Uses the same syntax as described in [[AiWML]].  Note that [modify_side][ai] works for all simple AI parameters and some, but not all, of the composite ones. If in doubt, use [http://wiki.wesnoth.org/AiWML#Adding_and_Deleting_Aspects_with_the_.5Bmodify_ai.5D_Tag [modify_ai]] instead, which always works.&lt;br /&gt;
* '''switch_ai''': replaces a side ai with a new AI from specified file(ignoring those AI parameters above). Path to file follows the usual WML convention.&lt;br /&gt;
* '''reset_maps''': {{DevFeature1.11}} If set to &amp;quot;yes&amp;quot;, then the shroud is spread to all hexes, covering the parts of the map that had already been explored by the side, including hexes currently seen. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if shroud is on, but this is evaluated after shroud= (and before shroud_data=).&lt;br /&gt;
* '''reset_view''': {{DevFeature1.11}} If set to &amp;quot;yes&amp;quot;, then the fog of war is spread to all hexes, covering the parts of the map that had already been seen this turn by the side, including hexes currently seen, excluding hexes affected by multi-turn {{tag|DirectActionsWML|lift_fog}}. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if fog is on, but this is evaluated after fog=.&lt;br /&gt;
* '''share_maps''': change the share_maps side attribute. Be sure to use shroud=yes for that side and have it as an ally&lt;br /&gt;
* '''share_view''': change the share_view side attribute. Be sure to use fog=yes for that side and have it as an ally&lt;br /&gt;
* '''shroud_data''': changes to the side's shroud, using the same format as when defining the [side].&lt;br /&gt;
* '''suppress_end_turn_confirmation''': {{DevFeature1.11}} Boolean value controlling whether or not a player is asked for confirmation when skipping a turn.&lt;br /&gt;
* '''scroll_to_leader''': {{DevFeature1.11}} Boolean value controlling whether or not the game view scrolls to the side leader at the start of their turn when present.&lt;br /&gt;
* '''flag''': {{DevFeature1.11}} Flag animation for villages owned by this side (see [[SideWML|[side]]]).&lt;br /&gt;
* '''flag_icon''': {{DevFeature1.11}} Flag icon used for this side in the status bar (see [[SideWML|[side]]]).&lt;br /&gt;
* '''village_support''': {{DevFeature1.11}} The number of unit levels this side is able to support (does not pay upkeep on) per village it controls.&lt;br /&gt;
&lt;br /&gt;
=== [modify_turns] ===&lt;br /&gt;
Modifies the turn limit in the middle of a scenario.&lt;br /&gt;
* '''value''': the new turn limit.&lt;br /&gt;
* '''add''': if used instead of ''value'', specifies the number of turns to add to the current limit (can be negative).&lt;br /&gt;
* '''current''': changes the current turn number after applying turn limit modifications, if any. It is not possible to change the turn number to exceed the turn limit (1 &amp;lt;= current turns &amp;lt;= max turns).&lt;br /&gt;
&lt;br /&gt;
=== [allow_end_turn] ===&lt;br /&gt;
Allows human players to end their turn through the user interface if they were previously affected by the '''[disallow_end_turn]''' action. This action doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_end_turn] ===&lt;br /&gt;
Disallows human players to end their turn through the user interface. This action doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' on Wesnoth versions prior to 1.10.6, there are two bugs affecting this WML action. First, its effect was lost when reloading from a saved game ([https://gna.org/bugs/?20350 bug #20350]); second, its effect persisted when advancing scenarios in a campaign ([https://gna.org/bugs/?20351 bug #20351]).&lt;br /&gt;
&lt;br /&gt;
A known workaround for both issues would be to use [[PreprocessorRef#.23ifver_and_.23ifnver|#ifver]]-based preprocessor macros to include additional code for Wesnoth 1.10.5 and earlier taking advantage of unique ''preload'', ''victory'', and ''defeat'' [[EventWML|event handlers]], such as the following:&lt;br /&gt;
&lt;br /&gt;
 #ifver WESNOTH_VERSION &amp;gt; 1.10.5&lt;br /&gt;
 &lt;br /&gt;
 #define DISALLOW_END_TURN&lt;br /&gt;
     [disallow_end_turn][/disallow_end_turn]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #define ALLOW_END_TURN&lt;br /&gt;
     [allow_end_turn][/allow_end_turn]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #else&lt;br /&gt;
 &lt;br /&gt;
 #define DISALLOW_END_TURN&lt;br /&gt;
     [disallow_end_turn][/disallow_end_turn]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20350_workaround&lt;br /&gt;
         name=preload&lt;br /&gt;
 &lt;br /&gt;
         [disallow_end_turn][/disallow_end_turn]&lt;br /&gt;
     [/event]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20351_workaround&lt;br /&gt;
         name=victory,defeat&lt;br /&gt;
 &lt;br /&gt;
         [allow_end_turn][/allow_end_turn]&lt;br /&gt;
     [/event]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #define ALLOW_END_TURN&lt;br /&gt;
     [allow_end_turn][/allow_end_turn]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20350_workaround&lt;br /&gt;
         remove=yes&lt;br /&gt;
     [/event]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20351_workaround&lt;br /&gt;
         remove=yes&lt;br /&gt;
     [/event]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #endif&lt;br /&gt;
&lt;br /&gt;
=== [capture_village] ===&lt;br /&gt;
Changes the ownership of a village.&lt;br /&gt;
* [[StandardLocationFilter]]: all village locations matching the filter are affected.&lt;br /&gt;
* '''side''': the side that takes control of the village. This side needs to have a leader (canrecruit=yes). If the side key is not given, the village will become neutral (unless [filter_side] is present, in which case that side fiter decides, see below).&lt;br /&gt;
* '''[filter_side]''' with [[StandardSideFilter]] tags and keys as arguments; if both this tag and inline side= are present it's an error. Otherwise, the first matching side gets ownership (or the village becomes neutral if none match).&lt;br /&gt;
* '''fire_event''' (boolean yes|no, default: no): Whether any capture events shall be fired.&lt;br /&gt;
&lt;br /&gt;
=== [kill] ===&lt;br /&gt;
Removes all units (including units in a recall list) that match the filter from the game.&lt;br /&gt;
* [[StandardUnitFilter]]: Selection criterion; do not use a [filter] tag.&lt;br /&gt;
* '''animate''': if 'yes', displays the unit dying (fading away).&lt;br /&gt;
* '''fire_event''': if 'yes', triggers any appropriate 'die' events (See [[EventWML]]). Note that events are only fired for killed units that have been on the map (as opposed to recall list).&lt;br /&gt;
* '''[secondary_unit]''' with a [[StandardUnitFilter]] as argument. Do not use a [filter] tag. Has an effect only if fire_event=yes. The first on-map unit matching the filter becomes second_unit in any fired die and last breath events. If an on-map unit matches and if there are several units killed with a single [kill] tag, second_unit is this same unit for all of them. If no on-map unit matches or [secondary_unit] isn't present, the variable second_unit in each of the die and last breath events is always the same as the variable unit (the dying unit).&lt;br /&gt;
&lt;br /&gt;
=== [move_unit] ===&lt;br /&gt;
works like the MOVE_UNIT macro.&lt;br /&gt;
* [[StandardUnitFilter]] as argument; do not use a [filter] tag. All units matching the filter are moved. If the target location is occupied, the nearest free location is chosen.&lt;br /&gt;
* '''to_x''' (unsigned integer): The units are moved to this x coordinate. Can be a comma-separated list, in which case the unit follows this given path during the move.&lt;br /&gt;
* '''to_y''' (unsigned integer): The units are moved to this y coordinate. Can be a comma-separated list.&lt;br /&gt;
* '''fire_event''' (optional, boolean yes|no, default no): Whether any according moveto events shall be fired. The target location ($x1, $y1 in the event) may not be the same location that the unit was tried to be moved to, if the original target location is occupied or impassable.&lt;br /&gt;
* '''check_passability''' (boolean yes|no, default yes): Whether the terrain the unit is moved to should be checked for suiting the unit. (If it does not, a nearby suitable hex is chosen.)&lt;br /&gt;
* {{DevFeature1.11}} '''force_scroll''': Whether to scroll the map or not even when [[InterfaceActionsWML#.5Block_view.5D|[lock_view]]] is in effect or ''Follow Unit Actions'' is disabled in ''Advanced Preferences''. Defaults to using [[InterfaceActionsWML#.5Bmove_unit_fake.5D|[move_unit_fake]]]'s default value.&lt;br /&gt;
&lt;br /&gt;
=== [modify_ai] ===&lt;br /&gt;
Changes AI objects (aspects, goals, candidate actions or stages) for a specified side. See [[AiWML#Adding_and_Deleting_Aspects_with_the_.5Bmodify_ai.5D_Tag|AiWML]] for full description.&lt;br /&gt;
&lt;br /&gt;
* '''action''' (string): Takes values 'add', 'change', 'delete' or 'try_delete' to do just that for the AI object.&lt;br /&gt;
* '''path''' (string): Describes which AI object is to be modified.  &lt;br /&gt;
* '''[facet]''', '''[goal]''', '''[candidate_action]''' or '''[stage]''': Details about the AI object to be modified.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument {{DevFeature1.11}}: [modify_ai][filter_side] is deprecated, use the new inline SSF.&lt;br /&gt;
&lt;br /&gt;
=== [modify_unit] ===&lt;br /&gt;
works similar to the MODIFY_UNIT macro.&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. All units matching this filter are modified. Matches on recall list units too.&lt;br /&gt;
* Accepts generally the syntax inside of wml unit variables created by [store_unit] which can be viewed in a savefile or by using the :inspect command. It can add [trait]s and [object]s without needing to wrap them inside a [modifications] tag, and their effects are applied immediately. Cannot remove things. Subtags with the same name must be written in the correct order to match them with the tag they are supposed to modify.&lt;br /&gt;
example usage (see also the test scenario):&lt;br /&gt;
 [modify_unit]&lt;br /&gt;
   [filter]&lt;br /&gt;
     x,y=38,6&lt;br /&gt;
   [/filter]&lt;br /&gt;
   hitpoints=10&lt;br /&gt;
   {TRAIT_HEALTHY}&lt;br /&gt;
 [/modify_unit]&lt;br /&gt;
&lt;br /&gt;
The unit which is currently modified is accessible via $this_unit, e.g. hitpoints = &amp;quot;$($this_unit.hitpoints / 2)&amp;quot; to set the hitpoints of all units to half of their particular maxima. This this_unit variable is independent from the this_unit variable available in the SUF used to determine which units to modify (first all matching units are gathered, and then all those are modified).&lt;br /&gt;
&lt;br /&gt;
note: The syntax allowed is somehow vague. Just try things and possibly correct/add/modify this documentation. (a [http://forums.wesnoth.org/viewtopic.php?f=21&amp;amp;t=31676&amp;amp; forum thread] discusses some related issues).&lt;br /&gt;
&lt;br /&gt;
=== [transform_unit] ===&lt;br /&gt;
Transforms every unit matching the filter to the given unit type. Keeps intact hit points, experience and status. If the unit is transformed to a non-living type (undead or mechanical), it will be also unpoisoned.&lt;br /&gt;
{{DevFeature1.11}} Hit points will be changed if necessary to respect the transformed unit's maximum hit points.&lt;br /&gt;
* [[StandardUnitFilter]]: do not use a [filter] tag.&lt;br /&gt;
* '''transform_to''': the unit type in which all the units matching the filter will be transformed. If missing, the units will follow their normal advancement.&lt;br /&gt;
&lt;br /&gt;
=== [petrify] ===&lt;br /&gt;
&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are petrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [unpetrify] ===&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are unpetrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [object] ===&lt;br /&gt;
Gives some unit an object which modifies their stats in some way.&lt;br /&gt;
* '''id''': (Optional) when the object is picked up, a flag is set for ''id''.  The object cannot be picked up if a flag for ''id'' has been set.  This means that any object with an id can only be used once, even if first_time_only=no is set for the event. This restriction is per level. In a campaign objects with the same id can be assigned once per level.&lt;br /&gt;
* '''delayed_variable_substitution''' (boolean yes|no, default no): If set to &amp;quot;yes&amp;quot;, the wml block contained in this [object] is not variable-substituted at execution time of the event where this [object] is within. You need this to work around a bug when adding ABILITY_TELEPORT via an [object] or when using [object][effect][filter]with a $this_unit (see http://gna.org/bugs/index.php?18893).&lt;br /&gt;
* '''[effect]''': one or more effect elements may be listed.  See [[EffectWML]] for a description of [effect].&lt;br /&gt;
* '''duration''':&lt;br /&gt;
**if 'level', effects only last until the end of the level (note : 'level' is the scenario, so this doesn't mean it last until the unit levels-up). {{DevFeature1.11}} 'level' has been renamed to 'scenario'.&lt;br /&gt;
**if 'forever' or not set, effects never wear off.&lt;br /&gt;
** {{DevFeature1.11}} if 'turn', effects only last until the start of the unit's next turn (when the unit refreshes movement and attacks). (Like other start-of-turn behavior, objects with a duration of &amp;quot;turn&amp;quot; won't expire before turn 2.)&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. The first unit found that matches the filter will be given the object. Only on-map units are considered. If no unit matches or no [filter] is supplied, it is tried to apply the object to the unit at the $x1,$y1 location of the event where this [object] is in. The case of no unit being at that spot is handled in the same way as no unit matching a given filter ([else] commands executed, cannot_use_message displayed)&lt;br /&gt;
* '''[then]''': a subtag that lets you execute actions if the filter conditions are met.  The most common action that should be inside here is a '''[remove_item]''' tag, but you could probably put any tags that otherwise work in a [then] tag.&lt;br /&gt;
* '''[else]''': a subtag that lets you execute actions if the filter conditions are *not* met.&lt;br /&gt;
* '''silent''': whether or not messages should be suppressed. Default is &amp;quot;no&amp;quot;.&lt;br /&gt;
* '''image''': the displayed image of the object.&lt;br /&gt;
* '''name''': (translatable) displayed as a caption of the image.&lt;br /&gt;
&lt;br /&gt;
* '''description''': (translatable) displayed as a message of the image.&lt;br /&gt;
* '''cannot_use_message''': (translatable) displayed instead of '''description''' if no unit passes the filter test.&lt;br /&gt;
&lt;br /&gt;
=== [remove_shroud] ===&lt;br /&gt;
Removes some shroud from the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to remove shroud. This can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles for which shroud should be removed&lt;br /&gt;
&lt;br /&gt;
=== [place_shroud] ===&lt;br /&gt;
Places some shroud on the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to place shroud. This can be a comma-separated list. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles on which shroud should be placed&lt;br /&gt;
&lt;br /&gt;
=== [lift_fog] ===&lt;br /&gt;
{{DevFeature1.11}}Lifts the fog of war from parts of the map for a certain side (only relevant for sides that have fog=yes), allowing a player to witness what occurs there even if that player has no units within vision range.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the tiles from which fog should be lifted.&lt;br /&gt;
* '''multiturn''': ''yes/no, default:no''. The default (not multiturn) causes fog to be removed in the same way that normal vision works; the cleared tiles will remain cleared until fog is recalculated (which normally happens when a side ends its turn). When multiturn is set to &amp;quot;yes&amp;quot;, the cleared tiles remain clear until {{tag||reset_fog}} cancels the clearing. This allows tiles to remain clear for multiple turns, or to be refogged before the end of the current turn (without also refogging all tiles). Multiturn lifted fog is not shared with allies (even when share_view=yes).&lt;br /&gt;
&lt;br /&gt;
=== [reset_fog] ===&lt;br /&gt;
{{DevFeature1.11}}The primary use of this tag is to remove multiturn lifted fog (created by {{tag||lift_fog}}), which causes the fog to reset to what it would have been had WML not interfered. (That is, hexes that a side's units could not see at any point this turn will be re-fogged, while seen hexes remain defogged.)&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the fog reset will be restricted to these tiles.&lt;br /&gt;
* '''reset_view''': ''yes/no, default: no'' If set to &amp;quot;yes&amp;quot;, then in addition to removing multiturn fog, the side's current view is canceled (independent of the SLF). This means that all hexes will become fogged for the side unless multiturn fog exists outside the tiles selected by the SLF. Normally, one would want the currently seen hexes to become clear of fog; this is done automatically at the end of many events, and it can be done manually with {{tag|InterfaceActionsWML|redraw}}.&lt;br /&gt;
Omitting both the SSF and the SLF would cancel all earlier uses of [lift_fog].&lt;br /&gt;
Additionally setting reset_view=&amp;quot;yes&amp;quot; would cause the side's entire map to be fogged (unless an ally keeps hexes clear by sharing its view).&lt;br /&gt;
&lt;br /&gt;
=== [allow_undo] ===&lt;br /&gt;
&lt;br /&gt;
Normally when an event with a handler fires, the player's undo stack is cleared, preventing all actions performed so far from being undone. Including this tag in the event handler prevents the stack from being cleared for this reason, allowing the player to undo actions. (However, the stack might still be cleared for other reasons, such as fog being cleared or combat occurring.) In the common cases, this means '''[allow_undo]''' allows the current action to be undone even though an event was handled. There is a less common case, though &amp;amp;mdash; specifically when handling a menu item, where there is no current action &amp;amp;mdash; and in this case, '''[allow_undo]''' means merely that earlier actions can still be undone.&lt;br /&gt;
* {{DevFeature1.11}} Using this tag in a menu item has an additional side effect in 1.11. Starting with version 1.11.1, executing a WML menu item normally counts as doing something as far as the &amp;quot;you have not started your turn yet&amp;quot; dialog is concerned. However, a menu item whose handler includes '''[allow_undo]''' will not count.&lt;br /&gt;
&lt;br /&gt;
This tag does nothing during recruit and recall actions, as the game incorrectly ignores whether or not an event fired during those times. {{DevFeature1.11}} This has been fixed in the latest development release.&lt;br /&gt;
&lt;br /&gt;
The types of actions that can be undone are movement, recruitment, recalling, and dismissing a unit from the recall list. If an action is undone, only the position (or existence) of the involved unit will be restored; any altered variables or changes to the game will remain changed after the action is undone.  It is up to the scenario designer to avoid abusing this command.&lt;br /&gt;
* Technically, if '''[allow_undo]''' is inside an '''[event]''' with ''first_time_only=yes'' (the default setting), and the user undoes the event, then the state of the game has changed in this way: the event will not fire a second time, even though the user undid the action the first time.&lt;br /&gt;
&lt;br /&gt;
=== [heal_unit] ===&lt;br /&gt;
Heal a unit. The variable '''$heal_amount''' will be set to the exact number of points healed (i.e can be lesser than the parameter '''amount''' if the unit is fully healed). $heal_amount contains only the number of hitpoints the first unit that was found got healed.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] All matching on-map units are healed. If no filter is supplied, it is tried to take the unit at $x1, $y1.&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] all the units matching the filter ''and'' having the ''heals'' ability will have their animation played (if ''animate'' is set to true) for each of the units healed.&lt;br /&gt;
*  '''amount''': (integer, default full) the maximum points the unit(s) will be healed. Can't set below 1 or above max_hitpoints. If &amp;quot;full&amp;quot;, sets hitpoints to max_hitpoints. Before 1.9 the default is 0.&lt;br /&gt;
*  '''animate''': a boolean which indicate if the healing animations must be played. (default no)&lt;br /&gt;
*  '''moves''': (integer, default 0) The maximum current movement points the units will be &amp;quot;healed&amp;quot;. Can't set below 0 or above max_moves. If &amp;quot;full&amp;quot;, sets moves to max_moves.&lt;br /&gt;
* '''restore_attacks''': (boolean, default no) Whether the units' attacks_left should be reset to their max_attacks (usually 1).&lt;br /&gt;
* '''restore_statuses''': (boolean, default yes) Whether standard statuses should be reset to &amp;quot;no&amp;quot;. This affects poisoned, slowed, petrified and unhealable. Before 1.9 this is always &amp;quot;no&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== [harm_unit] ===&lt;br /&gt;
Harms every unit matching the filter, for the specific damage amount.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] all matching units will be harmed (required).&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] if present, the first matching unit will attack all the units matching the filter above.&lt;br /&gt;
*  '''amount''': the amount of damage that will be done (required).&lt;br /&gt;
*  '''alignment''': (default neutral) applies an alignment to the damage, this means that if alignment=chaotic, the damage will be increased at night and reduced at day.&lt;br /&gt;
*  '''damage_type''': if present, amount will be altered by unit resistance to the damage type specified.&lt;br /&gt;
*  '''kill''': (default yes) if yes, when a harmed unit goes to or below 0 HP, it is killed; if no its HP are set to 1.&lt;br /&gt;
*  '''fire_event''': (default no) if yes, when a unit is killed by harming, the corresponding events are fired. {{DevFeature1.11}} If yes, also the corresponding advance and post advance events are fired.&lt;br /&gt;
*  '''animate''': (default no) if yes, scrolls to each unit before harming it and plays its defense (or attack, if it's the harmer) and death animations. Special values supported, other than the usual yes and no, are &amp;quot;attacker&amp;quot;, that means only the harmer will be animated, and &amp;quot;defender&amp;quot;, that means only the harmed units will be animated. {{DevFeature1.11}} If the supplied value is yes, attacker or defender also advancement animations are played.&lt;br /&gt;
*  '''[primary_attack], [secondary_attack]''': these set the weapon against which the harmed units will defend, and that the harming unit will use to attack, respectively (notice this is the opposite of '''[filter]''' and '''[filter_second]''' above). This allows for playing specific defense and attack animations. Both tags are expected to contain a [[FilterWML#Filtering_Weapons|Standard Weapon Filter]].&lt;br /&gt;
*  '''delay''': if animate=yes, sets the delay (in milliseconds, default 500) between each unit harming.&lt;br /&gt;
*  '''variable''': if present, the damage caused to the unit, altered by resistances, will be stored in a WML array with the given name, under the &amp;quot;harm_amount&amp;quot; key.&lt;br /&gt;
*  '''poisoned, slowed, petrified, unhealable''': (default no) if yes, every harmed unit that doesn't already have such status will have it set.&lt;br /&gt;
*  '''experience''': if yes, and there is a harmer, experience will be attributed like in regular combat.&lt;br /&gt;
*  '''resistance_multiplier''': {{DevFeature1.11}} the harmed unit's resistance is multiplied by the supplied value; this means that a value lower than 1 increases it, and a value greater than 1 decreases it. Default value is 1, that means no modification.&lt;br /&gt;
&lt;br /&gt;
=== [time_area] ===&lt;br /&gt;
How a day should progress in a given area. Everywhere not specified in a [time_area] tag is affected by the [time] tags in the [scenario] tag.&lt;br /&gt;
* [[StandardLocationFilter]]: the locations to affect. ''note: only for [event][time_area]s - at scenario toplevel [time_area] does not support [[StandardLocationFilter]], only location ranges''&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
* '''id''': an unique identifier assigned to a time_area. Optional, unless you want to remove the time_area later. Can be a comma-separated list when removing time_areas, see below.&lt;br /&gt;
* '''remove''': (boolean) yes/no value. Indicates whether the specified time_area should be removed. Requires an identifier. If no identifier is used, however, all time_areas are removed.&lt;br /&gt;
* '''current_time''': The time slot number (starting with zero) active at the creation of the area.{{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
''Example:'' (caves in parts of a map)&lt;br /&gt;
 [time_area]&lt;br /&gt;
     x=1-2,4-5&lt;br /&gt;
     y=1-2,1-2&lt;br /&gt;
     {UNDERGROUND}&lt;br /&gt;
 [/time_area]&lt;br /&gt;
&lt;br /&gt;
=== [end_turn] ===&lt;br /&gt;
End the current side's turn. The current event is finished before the turn is ended. Also, if the current event (where the tag appears) has been fired by another event, that event (and the complete stack of other possible parent events) is ended before [end_turn] comes into affect. Also, events following the event stack that fired [end_turn] are not omitted (e.g. [end_turn] is used by a side turn event and a turn refresh event does something afterwards).&lt;br /&gt;
&lt;br /&gt;
=== [replace_map] ===&lt;br /&gt;
&lt;br /&gt;
Replaces the entire map.&lt;br /&gt;
* '''map''': Content of a wesnoth map file. example:&lt;br /&gt;
 map=&amp;quot;{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}&amp;quot;&lt;br /&gt;
* '''expand''': if 'yes', allows the map size to increase. The expansion direction is currently always bottom-right.&lt;br /&gt;
* '''shrink''': if 'yes', allows the map size to decrease. If the map size is reduced, any units that would no longer be on the map due to its coordinates no longer existing will be put into the recall list.&lt;br /&gt;
Note: When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages it that there are too many choices to make; should a unit lose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [replace_schedule] ===&lt;br /&gt;
Replace the time of day schedule of the entire scenario.&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
* '''current_time''': The time slot number (starting with zero) active at schedule replacement.{{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
=== [tunnel] ===&lt;br /&gt;
&lt;br /&gt;
Create a tunnel between some locations, later usable by units to move from source hex to target hex (using the movement cost of unit on the target terrain). ([http://forums.wesnoth.org/viewtopic.php?f=21&amp;amp;t=14749&amp;amp;p=405667&amp;amp;hilit=tunnel#p405667 source])&lt;br /&gt;
&lt;br /&gt;
* '''id''' identifier for the tunnel, to allow removing (optional).&lt;br /&gt;
* '''remove''': (boolean) yes/no value. If yes, removes all defined tunnels with the same ID (then only id= is necessary). (default: no)&lt;br /&gt;
* '''bidirectional''': (boolean) if yes, creates also a tunnel in the other direction. (default: yes)&lt;br /&gt;
* '''always_visible''': (boolean) if yes, the possible movement of enemies under fog can be seen. (default: no)&lt;br /&gt;
* '''[source]''': [[StandardLocationFilter]] the source hex(es) (required).&lt;br /&gt;
* '''[target]''': [[StandardLocationFilter]] the target hex(es) (required).&lt;br /&gt;
* '''[filter]''': [[StandardUnitFilter]] the units which can use the tunnel (required). Leave empty for &amp;quot;all units&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
(Note: The tunnel tag can also be used inside the [[AbilitiesWML|[teleport]]] ability, without remove= and id=).&lt;br /&gt;
&lt;br /&gt;
=== [do_command] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Executes a command, specified using the same syntax as a [command] tag in [[ReplayWML]]. Not all [command]'s are valid: only these are accepted&lt;br /&gt;
&lt;br /&gt;
* [attack]&lt;br /&gt;
* [move]&lt;br /&gt;
* [recruit]&lt;br /&gt;
* [recall]&lt;br /&gt;
* [disband]&lt;br /&gt;
* [fire_event]&lt;br /&gt;
* [lua_ai]&lt;br /&gt;
&lt;br /&gt;
The tags corresponding to player actions generally use the same codepath as if a player had ordered it.&lt;br /&gt;
&lt;br /&gt;
One purpose of this tag is to allow scripting of noninteractive scenarios -- without a tag like this, this might require elaborate mechanisms to coerce ais in order to test these code paths.&lt;br /&gt;
&lt;br /&gt;
This command should always be replay safe.&lt;br /&gt;
&lt;br /&gt;
=== [store_relative_dir] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Gets the relative direction from one hex to another. This is an interface to the function wesnoth uses to decide how a unit will face while it is moving / attacking / defending.&lt;br /&gt;
&lt;br /&gt;
* '''[source]''' x and y must describe a map location&lt;br /&gt;
* '''[destination]''' similar&lt;br /&gt;
* '''variable''' name of the variable to store string result in (one of 'n', 'nw', 'ne', 's', 'sw', 'se')&lt;br /&gt;
* '''mode''' optional. 0 is the default setting corresponding to default wesnoth implementation used in animations. 1 is an alternate &amp;quot;radially symmetric&amp;quot; mode. The default mode breaks ties in the direction of south, since this makes more units face the player directly on screen. The radially symmetric mode breaks ties in the direction of counter-clockwise, and might be more appropriate in some cases.&lt;br /&gt;
&lt;br /&gt;
=== [full_heal] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Fully heals a unit matching the filter.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': the unit(s) to get healed.&lt;br /&gt;
* '''cures''': Whether the heal should remove poison and slow.&lt;br /&gt;
* '''animate''': Whether the heal should play the healed animation for each unit.&lt;br /&gt;
* '''ignore_status''': Whether the heal should affect units with unhealable=yes.&lt;br /&gt;
&lt;br /&gt;
=== [put_to_recall_list] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Puts a unit to the recall list of its side.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': the unit(s) to get put to the recall list.&lt;br /&gt;
* '''heal''': (default=no) Whether the unit should be refreshed, similar to the unit moving to the recall list at the end of a scenario.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Useful Macros ==&lt;br /&gt;
There are some predefined macros that you find useful for direct actions. You can find a complete list along with a detailed explanation of how they work [http://www.wesnoth.org/macro-reference.xhtml here].&lt;br /&gt;
* '''{MOVE_UNIT}''': Moves a unit to another location in the map and the player sees the movement (unlike [teleport])&lt;br /&gt;
* '''{FULL_HEAL}''': Brings a unit to full HP&lt;br /&gt;
* '''{LOYAL_UNIT}''': Create a loyal unit&lt;br /&gt;
* '''{MODIFY_TERRAIN_MASK}''': Modify an area of terrain&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=56028</id>
		<title>DirectActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=56028"/>
		<updated>2015-01-04T15:01:47Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [modify_unit] */ Clarified an unclear point about traits&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== Direct actions ==&lt;br /&gt;
&lt;br /&gt;
Direct actions are actions that have a direct effect on gameplay. They can be used inside of [[EventWML|events]].&lt;br /&gt;
&lt;br /&gt;
The following tags are actions:&lt;br /&gt;
&lt;br /&gt;
=== [endlevel] ===&lt;br /&gt;
Ends the scenario.&lt;br /&gt;
* '''result''': before the scenario is over, all events with ''name=result'' are triggered. If ''result=victory'', the player progresses to the next level (i.e., the next scenario in single player); if ''result=defeat'', the game returns to the main menu. &lt;br /&gt;
&lt;br /&gt;
When the result is &amp;quot;victory&amp;quot; the following keys can be used:&lt;br /&gt;
* '''bonus''': whether the player should get bonus gold (maximum possible gold that could have been earned by waiting the level out). The default is bonus=yes.&lt;br /&gt;
* '''carryover_report''': whether the player should receive a summary of the scenario outcome, the default is carryover_report=yes.&lt;br /&gt;
* '''save''': whether a start-of-scenario save should be created for the next scenario, the default is save=yes. Do not confuse this with saving of replays for the current scenario.&lt;br /&gt;
* '''replay_save''': whether a replay save for the current scenario is allowed, the default is replay_save=yes. If yes, the player's settings in preferences will be used to determine if a replay is saved. If no, will override and not save a replay.&lt;br /&gt;
* '''linger_mode''': If ...=yes, the screen is greyed out and there's the possibility to save before advancing to the next scenario, the default is linger_mode=yes.&lt;br /&gt;
* '''reveal_map''': (Multiplayer only) (Default is 'yes') If 'no', shroud doesn't disappear when game ended.&lt;br /&gt;
* '''next_scenario''': (default specified in '''[scenario]''' tag) the ID of the next scenario that should be played.  All units that side 1 controls at this point become available for recall in ''next_scenario''.&lt;br /&gt;
* '''carryover_percentage''': by default 80% of the gold is carried over to the next scenario, with this key the amount can be changed.&lt;br /&gt;
* '''carryover_add''': if true the gold will be added to the starting gold the next scenario, if false the next scenario will start with the amount of the current scenario (after taxes) or the minimum in the next scenario. Default is false.&lt;br /&gt;
* '''music''': (default specified in '''[scenario]''' or '''[game_config]''' tags) a comma-separated list of music tracks from which one will be chosen and played once after any events related to the end of level result are executed; by default, victory_music is used on victory, and defeat_music on defeat.&lt;br /&gt;
* '''end_credits''': {{DevFeature1.11}} Whether to display the credits screen at the end of a single-player campaign. Defaults to ''yes''. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text''': (translatable) Text that is shown centered in a black screen at the end of a campaign. Defaults to &amp;quot;The End&amp;quot;. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text_duration''': Delay, in milliseconds, before displaying the game credits at the end of a campaign. In other words, for how much time '''end_text''' is displayed on screen. Defaults to 3500. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* &amp;lt;strike&amp;gt;'''[next_scenario_settings]''': {{DevFeature1.11}} Any tags or attribute children of this optional argument to [endlevel] are merged into the scenario/multiplayer tag of the *next* scenario. This allows you to e.g. reconfigure the [side] tags or settings, just before load. &amp;lt;/strike&amp;gt; This feature was removed in 1.11.17, it might be redesigned and reintroduced.&lt;br /&gt;
* &amp;lt;strike&amp;gt;'''[next_scenario_append]''': {{DevFeature1.11}} Any tags of this optional argument are appended at high level to the next scenario. This is most appropriate for [event] tags, although you may find other uses. Example test scenario for these features: https://gna.org/support/download.php?file_id=20119 &amp;lt;/strike&amp;gt; This feature was removed in 1.11.17, it might be redesigned and reintroduced.&lt;br /&gt;
&lt;br /&gt;
=== [unit] ===&lt;br /&gt;
Places a unit on the map.  For syntax see [[SingleUnitWML]].&lt;br /&gt;
* {{Short Note:Predefined Macro|GENERIC_UNIT}}&lt;br /&gt;
* '''to_variable''':  spawn directly into a variable instead of on the map.&lt;br /&gt;
&lt;br /&gt;
=== [recall] ===&lt;br /&gt;
Recalls a unit taking into account any [http://wiki.wesnoth.org/SingleUnitWML filter_recall] of the leader.   The unit is recalled free of charge, and is placed near its leader, e.g., if multiple leaders are present, near the first found which would be able to normally recall it.&lt;br /&gt;
&lt;br /&gt;
If neither a valid map location is provided nor a leader on the map would be able to recall it, the tag is ignored.&lt;br /&gt;
 &lt;br /&gt;
* [[StandardUnitFilter]]: the first matching unit will be recalled.  If no units match this tag is ignored. Do not use a [filter] tag. If a comma separated list is given, every unit currently considered for recall is checked against all the types (not each single one of the types against all units).&lt;br /&gt;
* '''x,y''': the unit is placed here instead of next to the leader.&lt;br /&gt;
* '''show''': yes/no, default yes: whether the unit is animated (faded in) or instantly displayed&lt;br /&gt;
* '''fire_event''': boolean yes|no (default no); whether any according prerecall or recall events shall be fired.&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit (a nearby passable hex is chosen).&lt;br /&gt;
&lt;br /&gt;
=== [teleport] ===&lt;br /&gt;
Teleports a unit on map. {{Short Note:Predefined Macro|TELEPORT_UNIT}}&lt;br /&gt;
* '''[filter]''': [[StandardUnitFilter]] the first unit matching this filter will be teleported.&lt;br /&gt;
* '''x,y''': the position to teleport to.&lt;br /&gt;
* '''clear_shroud''': should shroud be cleared on arrival&lt;br /&gt;
* '''animate''': should a teleport animation be played (if the unit doesn't have a teleport animation, it will fade out/fade in)&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): normally, units will not be teleported into terrain that is impassable for them. Setting this attribute to &amp;quot;no&amp;quot; permits it.&lt;br /&gt;
&lt;br /&gt;
(Note: There is also a ability named teleport, see [[AbilitiesWML]].)&lt;br /&gt;
&lt;br /&gt;
=== [terrain_mask] ===&lt;br /&gt;
Changes the terrain on the map.  See [[TerrainMaskWML]].&lt;br /&gt;
&lt;br /&gt;
=== [terrain] ===&lt;br /&gt;
Changes the terrain on the map.&lt;br /&gt;
* '''terrain''': the character of the terrain to use.  See [[TerrainCodesWML]] to see what letter a type of terrain uses.&lt;br /&gt;
* [[StandardLocationFilter]]. This [[StandardLocationFilter]]'s terrain= key is used for the new terrain, filtering by terrain can be done with a nested [[StandardLocationFilter]]: [and]terrain=terrain_string_to_be_filtered_for.&lt;br /&gt;
* '''layer''': (overlay|base|both, default=both) only change the specified layer.&lt;br /&gt;
* '''replace_if_failed''': (default=no) When replacing just one layer failed, try to replace the whole terrain. If '''terrain''' is an overlay only terrain, use the default_base as base layer. If the terrain has no default base, do nothing.&lt;br /&gt;
Note: When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages it that there are too many choices to make; should a unit loose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [gold] ===&lt;br /&gt;
Gives sides gold.&lt;br /&gt;
* '''amount''': the amount of gold to give.&lt;br /&gt;
* '''side''': (default=1) the number of the side to give the gold to. Can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument {{DevFeature1.11}}: [gold][filter_side] is deprecated, use the new inline SSF.&lt;br /&gt;
&lt;br /&gt;
=== [unstore_unit] ===&lt;br /&gt;
Creates a unit from a game variable, and activates it on the playing field.  This must be a specific variable describing a unit, and may not be an array -- to unstore an entire array, iterate over it.  The variable is not cleared.  See also [[InternalActionsWML#.5Bstore_unit.5D|[store_unit]]], [[ConditionalActionsWML#.5Bwhile.5D|[while]]] and [[InternalActionsWML#.5Bclear_variable.5D|[clear_variable]]].&lt;br /&gt;
* '''variable''': the name of the variable.&lt;br /&gt;
* '''find_vacant''': whether the unit should be placed on the nearest vacant tile to its specified location.  If this is set to 'no'(default), then any unit on the same tile as the unit being unstored will be destroyed. &lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit. This key has no effect if find_vacant=no (no check performed then). Before 1.9 this key is always &amp;quot;no&amp;quot;.&lt;br /&gt;
* '''text''': (translatable) floating text to display above the unit, such as a damage amount&lt;br /&gt;
* '''red''', '''green''', '''blue''': (default=0,0,0) the color to display the text in. Values vary from 0-255. You may find it convenient to use the {COLOR_HARM} or {COLOR_HEAL} macro instead. (Use {COLOR_HARM} or {COLOR_HEAL} instead of the whole red,green,blue= line.)&lt;br /&gt;
* '''advance''': (default=true) if true the unit is advanced if it has enough XP. When modifying XP make sure to do it from inside a [[EventWML#Multiplayer_safety|synchronized event]] or it may lead to OOS errors especially when several advancement paths exist. Note that advance and post advance events are called, so infinite loops can happen.&lt;br /&gt;
* '''fire_event''': (boolean yes|no, default no) Whether any advance/post advance events shall be fired if an advancement takes place, no effect otherwise.&lt;br /&gt;
* '''animate''': {{DevFeature1.11}} (boolean yes|no, default yes) Whether &amp;quot;levelout&amp;quot; and &amp;quot;levelin&amp;quot; (or fade to white and back) animations shall be played if an advancement takes place, no effect otherwise.&lt;br /&gt;
* '''x''' ,'''y''': override unit location, &amp;quot;x,y=recall,recall&amp;quot; will put the unit on the unit's side's recall list.&lt;br /&gt;
Units can be unstored with negative (or zero) hit points. This can be useful if modifying a unit in its last_breath event (as the unit's death is already the next step), but tends to look wrong in other cases. In particular, it is possible to have units with negative hit points in play. Such units are aberrations, subject to unusual behavior as the game compensates for them. (For example, such units are currently automatically hit&amp;amp;ndash;and killed&amp;amp;ndash;in combat.) The details of the unusual behavior are subject to change between stable releases without warning.&lt;br /&gt;
&lt;br /&gt;
=== [allow_recruit] ===&lt;br /&gt;
Allows a side to recruit units it couldn't previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that is being allowed to recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [allow_extra_recruit] ===&lt;br /&gt;
Allows a leader to recruit units it couldn't previously recruit.&lt;br /&gt;
These types add to the types the leader can recruit because of [side]recruit=.&lt;br /&gt;
* '''extra_recruit''': the types of units that the unit can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_recruit] ===&lt;br /&gt;
Prevents a side from recruiting units it could previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can no longer recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that may no longer recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_extra_recruit] ===&lt;br /&gt;
Prevents a leader from recruiting units it could previously recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the side can no longer recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [set_recruit] ===&lt;br /&gt;
Sets the units a side can recruit.&lt;br /&gt;
* '''recruit''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that is having its recruitment set. This can be a comma-separated list. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [set_extra_recruit] === &lt;br /&gt;
Sets the units a leader can recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the leader can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [modify_side] ===&lt;br /&gt;
Modifies some details of a given side in the middle of a scenario.  '''The following listed properties are the only properties that [modify_side] can affect!'''&lt;br /&gt;
* '''side''': (default=1) the number of the side that is to be changed. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* '''income''': the income given at the begining of each turn.&lt;br /&gt;
* '''recruit''': a list of unit types, replacing the side's current recruitment list.&lt;br /&gt;
* '''team_name''': the team in which the side plays the scenario.&lt;br /&gt;
* '''user_team_name''': a translatable string representing the team's description. This has no effect on alliances. Defaults to ''team_name''.&lt;br /&gt;
* '''gold''': the amount of gold the side owns.&lt;br /&gt;
* '''village_gold''': the income setting per village for the side.&lt;br /&gt;
* '''controller''': the identifier string of the side's controller. Uses the same syntax of the ''controller'' key in the [[SideWML|[side]]] tag.&lt;br /&gt;
* '''fog''': a boolean string (yes/no) describing the status of Fog for the side.&lt;br /&gt;
* '''shroud''': a boolean string describing the status of Shroud for the side.&lt;br /&gt;
* '''hidden''': a boolean string specifying whether side is shown in status table.&lt;br /&gt;
* '''color''': {{DevFeature1.11}} a team color range specification, name (e.g. &amp;quot;red&amp;quot;, &amp;quot;blue&amp;quot;), or number (e.g. &amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;) for this side. The default color range names, numbers, and definitions can be found in data/core/team_colors.cfg.&lt;br /&gt;
* '''[ai]''': sets/changes AI parameters for the side. Only parameters that are specified in the tag are changed, this does not reset others to their default values. Uses the same syntax as described in [[AiWML]].  Note that [modify_side][ai] works for all simple AI parameters and some, but not all, of the composite ones. If in doubt, use [http://wiki.wesnoth.org/AiWML#Adding_and_Deleting_Aspects_with_the_.5Bmodify_ai.5D_Tag [modify_ai]] instead, which always works.&lt;br /&gt;
* '''switch_ai''': replaces a side ai with a new AI from specified file(ignoring those AI parameters above). Path to file follows the usual WML convention.&lt;br /&gt;
* '''reset_maps''': {{DevFeature1.11}} If set to &amp;quot;yes&amp;quot;, then the shroud is spread to all hexes, covering the parts of the map that had already been explored by the side, including hexes currently seen. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if shroud is on, but this is evaluated after shroud= (and before shroud_data=).&lt;br /&gt;
* '''reset_view''': {{DevFeature1.11}} If set to &amp;quot;yes&amp;quot;, then the fog of war is spread to all hexes, covering the parts of the map that had already been seen this turn by the side, including hexes currently seen, excluding hexes affected by multi-turn {{tag|DirectActionsWML|lift_fog}}. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if fog is on, but this is evaluated after fog=.&lt;br /&gt;
* '''share_maps''': change the share_maps side attribute. Be sure to use shroud=yes for that side and have it as an ally&lt;br /&gt;
* '''share_view''': change the share_view side attribute. Be sure to use fog=yes for that side and have it as an ally&lt;br /&gt;
* '''shroud_data''': changes to the side's shroud, using the same format as when defining the [side].&lt;br /&gt;
* '''suppress_end_turn_confirmation''': {{DevFeature1.11}} Boolean value controlling whether or not a player is asked for confirmation when skipping a turn.&lt;br /&gt;
* '''scroll_to_leader''': {{DevFeature1.11}} Boolean value controlling whether or not the game view scrolls to the side leader at the start of their turn when present.&lt;br /&gt;
* '''flag''': {{DevFeature1.11}} Flag animation for villages owned by this side (see [[SideWML|[side]]]).&lt;br /&gt;
* '''flag_icon''': {{DevFeature1.11}} Flag icon used for this side in the status bar (see [[SideWML|[side]]]).&lt;br /&gt;
* '''village_support''': {{DevFeature1.11}} The number of unit levels this side is able to support (does not pay upkeep on) per village it controls.&lt;br /&gt;
&lt;br /&gt;
=== [modify_turns] ===&lt;br /&gt;
Modifies the turn limit in the middle of a scenario.&lt;br /&gt;
* '''value''': the new turn limit.&lt;br /&gt;
* '''add''': if used instead of ''value'', specifies the number of turns to add to the current limit (can be negative).&lt;br /&gt;
* '''current''': changes the current turn number after applying turn limit modifications, if any. It is not possible to change the turn number to exceed the turn limit (1 &amp;lt;= current turns &amp;lt;= max turns).&lt;br /&gt;
&lt;br /&gt;
=== [allow_end_turn] ===&lt;br /&gt;
Allows human players to end their turn through the user interface if they were previously affected by the '''[disallow_end_turn]''' action. This action doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_end_turn] ===&lt;br /&gt;
Disallows human players to end their turn through the user interface. This action doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' on Wesnoth versions prior to 1.10.6, there are two bugs affecting this WML action. First, its effect was lost when reloading from a saved game ([https://gna.org/bugs/?20350 bug #20350]); second, its effect persisted when advancing scenarios in a campaign ([https://gna.org/bugs/?20351 bug #20351]).&lt;br /&gt;
&lt;br /&gt;
A known workaround for both issues would be to use [[PreprocessorRef#.23ifver_and_.23ifnver|#ifver]]-based preprocessor macros to include additional code for Wesnoth 1.10.5 and earlier taking advantage of unique ''preload'', ''victory'', and ''defeat'' [[EventWML|event handlers]], such as the following:&lt;br /&gt;
&lt;br /&gt;
 #ifver WESNOTH_VERSION &amp;gt; 1.10.5&lt;br /&gt;
 &lt;br /&gt;
 #define DISALLOW_END_TURN&lt;br /&gt;
     [disallow_end_turn][/disallow_end_turn]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #define ALLOW_END_TURN&lt;br /&gt;
     [allow_end_turn][/allow_end_turn]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #else&lt;br /&gt;
 &lt;br /&gt;
 #define DISALLOW_END_TURN&lt;br /&gt;
     [disallow_end_turn][/disallow_end_turn]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20350_workaround&lt;br /&gt;
         name=preload&lt;br /&gt;
 &lt;br /&gt;
         [disallow_end_turn][/disallow_end_turn]&lt;br /&gt;
     [/event]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20351_workaround&lt;br /&gt;
         name=victory,defeat&lt;br /&gt;
 &lt;br /&gt;
         [allow_end_turn][/allow_end_turn]&lt;br /&gt;
     [/event]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #define ALLOW_END_TURN&lt;br /&gt;
     [allow_end_turn][/allow_end_turn]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20350_workaround&lt;br /&gt;
         remove=yes&lt;br /&gt;
     [/event]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20351_workaround&lt;br /&gt;
         remove=yes&lt;br /&gt;
     [/event]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #endif&lt;br /&gt;
&lt;br /&gt;
=== [capture_village] ===&lt;br /&gt;
Changes the ownership of a village.&lt;br /&gt;
* [[StandardLocationFilter]]: all village locations matching the filter are affected.&lt;br /&gt;
* '''side''': the side that takes control of the village. This side needs to have a leader (canrecruit=yes). If the side key is not given, the village will become neutral (unless [filter_side] is present, in which case that side fiter decides, see below).&lt;br /&gt;
* '''[filter_side]''' with [[StandardSideFilter]] tags and keys as arguments; if both this tag and inline side= are present it's an error. Otherwise, the first matching side gets ownership (or the village becomes neutral if none match).&lt;br /&gt;
* '''fire_event''' (boolean yes|no, default: no): Whether any capture events shall be fired.&lt;br /&gt;
&lt;br /&gt;
=== [kill] ===&lt;br /&gt;
Removes all units (including units in a recall list) that match the filter from the game.&lt;br /&gt;
* [[StandardUnitFilter]]: Selection criterion; do not use a [filter] tag.&lt;br /&gt;
* '''animate''': if 'yes', displays the unit dying (fading away).&lt;br /&gt;
* '''fire_event''': if 'yes', triggers any appropriate 'die' events (See [[EventWML]]). Note that events are only fired for killed units that have been on the map (as opposed to recall list).&lt;br /&gt;
* '''[secondary_unit]''' with a [[StandardUnitFilter]] as argument. Do not use a [filter] tag. Has an effect only if fire_event=yes. The first on-map unit matching the filter becomes second_unit in any fired die and last breath events. If an on-map unit matches and if there are several units killed with a single [kill] tag, second_unit is this same unit for all of them. If no on-map unit matches or [secondary_unit] isn't present, the variable second_unit in each of the die and last breath events is always the same as the variable unit (the dying unit).&lt;br /&gt;
&lt;br /&gt;
=== [move_unit] ===&lt;br /&gt;
works like the MOVE_UNIT macro.&lt;br /&gt;
* [[StandardUnitFilter]] as argument; do not use a [filter] tag. All units matching the filter are moved. If the target location is occupied, the nearest free location is chosen.&lt;br /&gt;
* '''to_x''' (unsigned integer): The units are moved to this x coordinate. Can be a comma-separated list, in which case the unit follows this given path during the move.&lt;br /&gt;
* '''to_y''' (unsigned integer): The units are moved to this y coordinate. Can be a comma-separated list.&lt;br /&gt;
* '''fire_event''' (optional, boolean yes|no, default no): Whether any according moveto events shall be fired. The target location ($x1, $y1 in the event) may not be the same location that the unit was tried to be moved to, if the original target location is occupied or impassable.&lt;br /&gt;
* '''check_passability''' (boolean yes|no, default yes): Whether the terrain the unit is moved to should be checked for suiting the unit. (If it does not, a nearby suitable hex is chosen.)&lt;br /&gt;
* {{DevFeature1.11}} '''force_scroll''': Whether to scroll the map or not even when [[InterfaceActionsWML#.5Block_view.5D|[lock_view]]] is in effect or ''Follow Unit Actions'' is disabled in ''Advanced Preferences''. Defaults to using [[InterfaceActionsWML#.5Bmove_unit_fake.5D|[move_unit_fake]]]'s default value.&lt;br /&gt;
&lt;br /&gt;
=== [modify_ai] ===&lt;br /&gt;
Changes AI objects (aspects, goals, candidate actions or stages) for a specified side. See [[AiWML#Adding_and_Deleting_Aspects_with_the_.5Bmodify_ai.5D_Tag|AiWML]] for full description.&lt;br /&gt;
&lt;br /&gt;
* '''action''' (string): Takes values 'add', 'change', 'delete' or 'try_delete' to do just that for the AI object.&lt;br /&gt;
* '''path''' (string): Describes which AI object is to be modified.  &lt;br /&gt;
* '''[facet]''', '''[goal]''', '''[candidate_action]''' or '''[stage]''': Details about the AI object to be modified.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument {{DevFeature1.11}}: [modify_ai][filter_side] is deprecated, use the new inline SSF.&lt;br /&gt;
&lt;br /&gt;
=== [modify_unit] ===&lt;br /&gt;
works similar to the MODIFY_UNIT macro.&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. All units matching this filter are modified. Matches on recall list units too.&lt;br /&gt;
* Accepts generally the syntax inside of wml unit variables created by [store_unit] which can be viewed in a savefile or by using the :inspect command. It can add [trait]s and [object]s without needing to wrap them inside a [modifications] tag. Cannot remove things. Subtags with the same name must be written in the correct order to match them with the tag they are supposed to modify.&lt;br /&gt;
example usage (see also the test scenario):&lt;br /&gt;
 [modify_unit]&lt;br /&gt;
   [filter]&lt;br /&gt;
     x,y=38,6&lt;br /&gt;
   [/filter]&lt;br /&gt;
   hitpoints=10&lt;br /&gt;
   {TRAIT_HEALTHY}&lt;br /&gt;
 [/modify_unit]&lt;br /&gt;
&lt;br /&gt;
The unit which is currently modified is accessible via $this_unit, e.g. hitpoints = &amp;quot;$($this_unit.hitpoints / 2)&amp;quot; to set the hitpoints of all units to half of their particular maxima. This this_unit variable is independent from the this_unit variable available in the SUF used to determine which units to modify (first all matching units are gathered, and then all those are modified).&lt;br /&gt;
&lt;br /&gt;
note: The syntax allowed is somehow vague. Just try things and possibly correct/add/modify this documentation. (a [http://forums.wesnoth.org/viewtopic.php?f=21&amp;amp;t=31676&amp;amp; forum thread] discusses some related issues).&lt;br /&gt;
&lt;br /&gt;
=== [transform_unit] ===&lt;br /&gt;
Transforms every unit matching the filter to the given unit type. Keeps intact hit points, experience and status. If the unit is transformed to a non-living type (undead or mechanical), it will be also unpoisoned.&lt;br /&gt;
{{DevFeature1.11}} Hit points will be changed if necessary to respect the transformed unit's maximum hit points.&lt;br /&gt;
* [[StandardUnitFilter]]: do not use a [filter] tag.&lt;br /&gt;
* '''transform_to''': the unit type in which all the units matching the filter will be transformed. If missing, the units will follow their normal advancement.&lt;br /&gt;
&lt;br /&gt;
=== [petrify] ===&lt;br /&gt;
&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are petrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [unpetrify] ===&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are unpetrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [object] ===&lt;br /&gt;
Gives some unit an object which modifies their stats in some way.&lt;br /&gt;
* '''id''': (Optional) when the object is picked up, a flag is set for ''id''.  The object cannot be picked up if a flag for ''id'' has been set.  This means that any object with an id can only be used once, even if first_time_only=no is set for the event. This restriction is per level. In a campaign objects with the same id can be assigned once per level.&lt;br /&gt;
* '''delayed_variable_substitution''' (boolean yes|no, default no): If set to &amp;quot;yes&amp;quot;, the wml block contained in this [object] is not variable-substituted at execution time of the event where this [object] is within. You need this to work around a bug when adding ABILITY_TELEPORT via an [object] or when using [object][effect][filter]with a $this_unit (see http://gna.org/bugs/index.php?18893).&lt;br /&gt;
* '''[effect]''': one or more effect elements may be listed.  See [[EffectWML]] for a description of [effect].&lt;br /&gt;
* '''duration''':&lt;br /&gt;
**if 'level', effects only last until the end of the level (note : 'level' is the scenario, so this doesn't mean it last until the unit levels-up). {{DevFeature1.11}} 'level' has been renamed to 'scenario'.&lt;br /&gt;
**if 'forever' or not set, effects never wear off.&lt;br /&gt;
** {{DevFeature1.11}} if 'turn', effects only last until the start of the unit's next turn (when the unit refreshes movement and attacks). (Like other start-of-turn behavior, objects with a duration of &amp;quot;turn&amp;quot; won't expire before turn 2.)&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. The first unit found that matches the filter will be given the object. Only on-map units are considered. If no unit matches or no [filter] is supplied, it is tried to apply the object to the unit at the $x1,$y1 location of the event where this [object] is in. The case of no unit being at that spot is handled in the same way as no unit matching a given filter ([else] commands executed, cannot_use_message displayed)&lt;br /&gt;
* '''[then]''': a subtag that lets you execute actions if the filter conditions are met.  The most common action that should be inside here is a '''[remove_item]''' tag, but you could probably put any tags that otherwise work in a [then] tag.&lt;br /&gt;
* '''[else]''': a subtag that lets you execute actions if the filter conditions are *not* met.&lt;br /&gt;
* '''silent''': whether or not messages should be suppressed. Default is &amp;quot;no&amp;quot;.&lt;br /&gt;
* '''image''': the displayed image of the object.&lt;br /&gt;
* '''name''': (translatable) displayed as a caption of the image.&lt;br /&gt;
&lt;br /&gt;
* '''description''': (translatable) displayed as a message of the image.&lt;br /&gt;
* '''cannot_use_message''': (translatable) displayed instead of '''description''' if no unit passes the filter test.&lt;br /&gt;
&lt;br /&gt;
=== [remove_shroud] ===&lt;br /&gt;
Removes some shroud from the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to remove shroud. This can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles for which shroud should be removed&lt;br /&gt;
&lt;br /&gt;
=== [place_shroud] ===&lt;br /&gt;
Places some shroud on the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to place shroud. This can be a comma-separated list. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles on which shroud should be placed&lt;br /&gt;
&lt;br /&gt;
=== [lift_fog] ===&lt;br /&gt;
{{DevFeature1.11}}Lifts the fog of war from parts of the map for a certain side (only relevant for sides that have fog=yes), allowing a player to witness what occurs there even if that player has no units within vision range.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the tiles from which fog should be lifted.&lt;br /&gt;
* '''multiturn''': ''yes/no, default:no''. The default (not multiturn) causes fog to be removed in the same way that normal vision works; the cleared tiles will remain cleared until fog is recalculated (which normally happens when a side ends its turn). When multiturn is set to &amp;quot;yes&amp;quot;, the cleared tiles remain clear until {{tag||reset_fog}} cancels the clearing. This allows tiles to remain clear for multiple turns, or to be refogged before the end of the current turn (without also refogging all tiles). Multiturn lifted fog is not shared with allies (even when share_view=yes).&lt;br /&gt;
&lt;br /&gt;
=== [reset_fog] ===&lt;br /&gt;
{{DevFeature1.11}}The primary use of this tag is to remove multiturn lifted fog (created by {{tag||lift_fog}}), which causes the fog to reset to what it would have been had WML not interfered. (That is, hexes that a side's units could not see at any point this turn will be re-fogged, while seen hexes remain defogged.)&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the fog reset will be restricted to these tiles.&lt;br /&gt;
* '''reset_view''': ''yes/no, default: no'' If set to &amp;quot;yes&amp;quot;, then in addition to removing multiturn fog, the side's current view is canceled (independent of the SLF). This means that all hexes will become fogged for the side unless multiturn fog exists outside the tiles selected by the SLF. Normally, one would want the currently seen hexes to become clear of fog; this is done automatically at the end of many events, and it can be done manually with {{tag|InterfaceActionsWML|redraw}}.&lt;br /&gt;
Omitting both the SSF and the SLF would cancel all earlier uses of [lift_fog].&lt;br /&gt;
Additionally setting reset_view=&amp;quot;yes&amp;quot; would cause the side's entire map to be fogged (unless an ally keeps hexes clear by sharing its view).&lt;br /&gt;
&lt;br /&gt;
=== [allow_undo] ===&lt;br /&gt;
&lt;br /&gt;
Normally when an event with a handler fires, the player's undo stack is cleared, preventing all actions performed so far from being undone. Including this tag in the event handler prevents the stack from being cleared for this reason, allowing the player to undo actions. (However, the stack might still be cleared for other reasons, such as fog being cleared or combat occurring.) In the common cases, this means '''[allow_undo]''' allows the current action to be undone even though an event was handled. There is a less common case, though &amp;amp;mdash; specifically when handling a menu item, where there is no current action &amp;amp;mdash; and in this case, '''[allow_undo]''' means merely that earlier actions can still be undone.&lt;br /&gt;
* {{DevFeature1.11}} Using this tag in a menu item has an additional side effect in 1.11. Starting with version 1.11.1, executing a WML menu item normally counts as doing something as far as the &amp;quot;you have not started your turn yet&amp;quot; dialog is concerned. However, a menu item whose handler includes '''[allow_undo]''' will not count.&lt;br /&gt;
&lt;br /&gt;
This tag does nothing during recruit and recall actions, as the game incorrectly ignores whether or not an event fired during those times. {{DevFeature1.11}} This has been fixed in the latest development release.&lt;br /&gt;
&lt;br /&gt;
The types of actions that can be undone are movement, recruitment, recalling, and dismissing a unit from the recall list. If an action is undone, only the position (or existence) of the involved unit will be restored; any altered variables or changes to the game will remain changed after the action is undone.  It is up to the scenario designer to avoid abusing this command.&lt;br /&gt;
* Technically, if '''[allow_undo]''' is inside an '''[event]''' with ''first_time_only=yes'' (the default setting), and the user undoes the event, then the state of the game has changed in this way: the event will not fire a second time, even though the user undid the action the first time.&lt;br /&gt;
&lt;br /&gt;
=== [heal_unit] ===&lt;br /&gt;
Heal a unit. The variable '''$heal_amount''' will be set to the exact number of points healed (i.e can be lesser than the parameter '''amount''' if the unit is fully healed). $heal_amount contains only the number of hitpoints the first unit that was found got healed.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] All matching on-map units are healed. If no filter is supplied, it is tried to take the unit at $x1, $y1.&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] all the units matching the filter ''and'' having the ''heals'' ability will have their animation played (if ''animate'' is set to true) for each of the units healed.&lt;br /&gt;
*  '''amount''': (integer, default full) the maximum points the unit(s) will be healed. Can't set below 1 or above max_hitpoints. If &amp;quot;full&amp;quot;, sets hitpoints to max_hitpoints. Before 1.9 the default is 0.&lt;br /&gt;
*  '''animate''': a boolean which indicate if the healing animations must be played. (default no)&lt;br /&gt;
*  '''moves''': (integer, default 0) The maximum current movement points the units will be &amp;quot;healed&amp;quot;. Can't set below 0 or above max_moves. If &amp;quot;full&amp;quot;, sets moves to max_moves.&lt;br /&gt;
* '''restore_attacks''': (boolean, default no) Whether the units' attacks_left should be reset to their max_attacks (usually 1).&lt;br /&gt;
* '''restore_statuses''': (boolean, default yes) Whether standard statuses should be reset to &amp;quot;no&amp;quot;. This affects poisoned, slowed, petrified and unhealable. Before 1.9 this is always &amp;quot;no&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== [harm_unit] ===&lt;br /&gt;
Harms every unit matching the filter, for the specific damage amount.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] all matching units will be harmed (required).&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] if present, the first matching unit will attack all the units matching the filter above.&lt;br /&gt;
*  '''amount''': the amount of damage that will be done (required).&lt;br /&gt;
*  '''alignment''': (default neutral) applies an alignment to the damage, this means that if alignment=chaotic, the damage will be increased at night and reduced at day.&lt;br /&gt;
*  '''damage_type''': if present, amount will be altered by unit resistance to the damage type specified.&lt;br /&gt;
*  '''kill''': (default yes) if yes, when a harmed unit goes to or below 0 HP, it is killed; if no its HP are set to 1.&lt;br /&gt;
*  '''fire_event''': (default no) if yes, when a unit is killed by harming, the corresponding events are fired. {{DevFeature1.11}} If yes, also the corresponding advance and post advance events are fired.&lt;br /&gt;
*  '''animate''': (default no) if yes, scrolls to each unit before harming it and plays its defense (or attack, if it's the harmer) and death animations. Special values supported, other than the usual yes and no, are &amp;quot;attacker&amp;quot;, that means only the harmer will be animated, and &amp;quot;defender&amp;quot;, that means only the harmed units will be animated. {{DevFeature1.11}} If the supplied value is yes, attacker or defender also advancement animations are played.&lt;br /&gt;
*  '''[primary_attack], [secondary_attack]''': these set the weapon against which the harmed units will defend, and that the harming unit will use to attack, respectively (notice this is the opposite of '''[filter]''' and '''[filter_second]''' above). This allows for playing specific defense and attack animations. Both tags are expected to contain a [[FilterWML#Filtering_Weapons|Standard Weapon Filter]].&lt;br /&gt;
*  '''delay''': if animate=yes, sets the delay (in milliseconds, default 500) between each unit harming.&lt;br /&gt;
*  '''variable''': if present, the damage caused to the unit, altered by resistances, will be stored in a WML array with the given name, under the &amp;quot;harm_amount&amp;quot; key.&lt;br /&gt;
*  '''poisoned, slowed, petrified, unhealable''': (default no) if yes, every harmed unit that doesn't already have such status will have it set.&lt;br /&gt;
*  '''experience''': if yes, and there is a harmer, experience will be attributed like in regular combat.&lt;br /&gt;
*  '''resistance_multiplier''': {{DevFeature1.11}} the harmed unit's resistance is multiplied by the supplied value; this means that a value lower than 1 increases it, and a value greater than 1 decreases it. Default value is 1, that means no modification.&lt;br /&gt;
&lt;br /&gt;
=== [time_area] ===&lt;br /&gt;
How a day should progress in a given area. Everywhere not specified in a [time_area] tag is affected by the [time] tags in the [scenario] tag.&lt;br /&gt;
* [[StandardLocationFilter]]: the locations to affect. ''note: only for [event][time_area]s - at scenario toplevel [time_area] does not support [[StandardLocationFilter]], only location ranges''&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
* '''id''': an unique identifier assigned to a time_area. Optional, unless you want to remove the time_area later. Can be a comma-separated list when removing time_areas, see below.&lt;br /&gt;
* '''remove''': (boolean) yes/no value. Indicates whether the specified time_area should be removed. Requires an identifier. If no identifier is used, however, all time_areas are removed.&lt;br /&gt;
* '''current_time''': The time slot number (starting with zero) active at the creation of the area.{{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
''Example:'' (caves in parts of a map)&lt;br /&gt;
 [time_area]&lt;br /&gt;
     x=1-2,4-5&lt;br /&gt;
     y=1-2,1-2&lt;br /&gt;
     {UNDERGROUND}&lt;br /&gt;
 [/time_area]&lt;br /&gt;
&lt;br /&gt;
=== [end_turn] ===&lt;br /&gt;
End the current side's turn. The current event is finished before the turn is ended. Also, if the current event (where the tag appears) has been fired by another event, that event (and the complete stack of other possible parent events) is ended before [end_turn] comes into affect. Also, events following the event stack that fired [end_turn] are not omitted (e.g. [end_turn] is used by a side turn event and a turn refresh event does something afterwards).&lt;br /&gt;
&lt;br /&gt;
=== [replace_map] ===&lt;br /&gt;
&lt;br /&gt;
Replaces the entire map.&lt;br /&gt;
* '''map''': Content of a wesnoth map file. example:&lt;br /&gt;
 map=&amp;quot;{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}&amp;quot;&lt;br /&gt;
* '''expand''': if 'yes', allows the map size to increase. The expansion direction is currently always bottom-right.&lt;br /&gt;
* '''shrink''': if 'yes', allows the map size to decrease. If the map size is reduced, any units that would no longer be on the map due to its coordinates no longer existing will be put into the recall list.&lt;br /&gt;
Note: When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages it that there are too many choices to make; should a unit lose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [replace_schedule] ===&lt;br /&gt;
Replace the time of day schedule of the entire scenario.&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
* '''current_time''': The time slot number (starting with zero) active at schedule replacement.{{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
=== [tunnel] ===&lt;br /&gt;
&lt;br /&gt;
Create a tunnel between some locations, later usable by units to move from source hex to target hex (using the movement cost of unit on the target terrain). ([http://forums.wesnoth.org/viewtopic.php?f=21&amp;amp;t=14749&amp;amp;p=405667&amp;amp;hilit=tunnel#p405667 source])&lt;br /&gt;
&lt;br /&gt;
* '''id''' identifier for the tunnel, to allow removing (optional).&lt;br /&gt;
* '''remove''': (boolean) yes/no value. If yes, removes all defined tunnels with the same ID (then only id= is necessary). (default: no)&lt;br /&gt;
* '''bidirectional''': (boolean) if yes, creates also a tunnel in the other direction. (default: yes)&lt;br /&gt;
* '''always_visible''': (boolean) if yes, the possible movement of enemies under fog can be seen. (default: no)&lt;br /&gt;
* '''[source]''': [[StandardLocationFilter]] the source hex(es) (required).&lt;br /&gt;
* '''[target]''': [[StandardLocationFilter]] the target hex(es) (required).&lt;br /&gt;
* '''[filter]''': [[StandardUnitFilter]] the units which can use the tunnel (required). Leave empty for &amp;quot;all units&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
(Note: The tunnel tag can also be used inside the [[AbilitiesWML|[teleport]]] ability, without remove= and id=).&lt;br /&gt;
&lt;br /&gt;
=== [do_command] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Executes a command, specified using the same syntax as a [command] tag in [[ReplayWML]]. Not all [command]'s are valid: only these are accepted&lt;br /&gt;
&lt;br /&gt;
* [attack]&lt;br /&gt;
* [move]&lt;br /&gt;
* [recruit]&lt;br /&gt;
* [recall]&lt;br /&gt;
* [disband]&lt;br /&gt;
* [fire_event]&lt;br /&gt;
* [lua_ai]&lt;br /&gt;
&lt;br /&gt;
The tags corresponding to player actions generally use the same codepath as if a player had ordered it.&lt;br /&gt;
&lt;br /&gt;
One purpose of this tag is to allow scripting of noninteractive scenarios -- without a tag like this, this might require elaborate mechanisms to coerce ais in order to test these code paths.&lt;br /&gt;
&lt;br /&gt;
This command should always be replay safe.&lt;br /&gt;
&lt;br /&gt;
=== [store_relative_dir] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Gets the relative direction from one hex to another. This is an interface to the function wesnoth uses to decide how a unit will face while it is moving / attacking / defending.&lt;br /&gt;
&lt;br /&gt;
* '''[source]''' x and y must describe a map location&lt;br /&gt;
* '''[destination]''' similar&lt;br /&gt;
* '''variable''' name of the variable to store string result in (one of 'n', 'nw', 'ne', 's', 'sw', 'se')&lt;br /&gt;
* '''mode''' optional. 0 is the default setting corresponding to default wesnoth implementation used in animations. 1 is an alternate &amp;quot;radially symmetric&amp;quot; mode. The default mode breaks ties in the direction of south, since this makes more units face the player directly on screen. The radially symmetric mode breaks ties in the direction of counter-clockwise, and might be more appropriate in some cases.&lt;br /&gt;
&lt;br /&gt;
=== [full_heal] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Fully heals a unit matching the filter.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': the unit(s) to get healed.&lt;br /&gt;
* '''cures''': Whether the heal should remove poison and slow.&lt;br /&gt;
* '''animate''': Whether the heal should play the healed animation for each unit.&lt;br /&gt;
* '''ignore_status''': Whether the heal should affect units with unhealable=yes.&lt;br /&gt;
&lt;br /&gt;
=== [put_to_recall_list] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}}&lt;br /&gt;
&lt;br /&gt;
Puts a unit to the recall list of its side.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': the unit(s) to get put to the recall list.&lt;br /&gt;
* '''heal''': (default=no) Whether the unit should be refreshed, similar to the unit moving to the recall list at the end of a scenario.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Useful Macros ==&lt;br /&gt;
There are some predefined macros that you find useful for direct actions. You can find a complete list along with a detailed explanation of how they work [http://www.wesnoth.org/macro-reference.xhtml here].&lt;br /&gt;
* '''{MOVE_UNIT}''': Moves a unit to another location in the map and the player sees the movement (unlike [teleport])&lt;br /&gt;
* '''{FULL_HEAL}''': Brings a unit to full HP&lt;br /&gt;
* '''{LOYAL_UNIT}''': Create a loyal unit&lt;br /&gt;
* '''{MODIFY_TERRAIN_MASK}''': Modify an area of terrain&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=Maintenance_tools&amp;diff=55374</id>
		<title>Maintenance tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=Maintenance_tools&amp;diff=55374"/>
		<updated>2014-08-18T14:49:33Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* GUI.pyw */ Improved system requirements description&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Wesnoth source code distribution includes a couple of tools intended to help authors maintain campaigns, faction &amp;amp; unit packs, and other WML resources. These&lt;br /&gt;
are:&lt;br /&gt;
 &lt;br /&gt;
; wmlscope: a cross-reference lister, useful for finding unresolved macro and resource-file references.&lt;br /&gt;
&lt;br /&gt;
; wmllint: a utility for sanity-checking WML syntax and porting your old WML to the current version of WML.  &lt;br /&gt;
&lt;br /&gt;
; wmlindent: a utility for reindenting WML to a uniform style.&lt;br /&gt;
&lt;br /&gt;
; GUI.pyw: a graphical interface&lt;br /&gt;
&lt;br /&gt;
You will need a Python 2 interpreter on your system to use these tools.  Linux, *BSD, and Mac OS/X should already have Python 2 installed; for Windows it's a free download&lt;br /&gt;
from http://www.python.org.  You will also need to know how to run command-line tools on your system.&lt;br /&gt;
&lt;br /&gt;
If you're working with ubuntu you might have to install the package wesnoth-1.10-tools (or the convenient version).&lt;br /&gt;
 sudo apt-get install wesnoth-1.10-tools&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All three tools will require you to supply a &amp;lt;i&amp;gt;directory list&amp;lt;/i&amp;gt;.  This is a set of directories containing the WML files you want to work on.&lt;br /&gt;
&lt;br /&gt;
This page is intended as ducementation for users.  A developer's-eye discussion of the design constraints on these tools, and their limitations, can be found here [https://mail.gna.org/public/wesnoth-dev/2010-02/msg00078.html].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Note to Windows Users:&amp;lt;/u&amp;gt; This means you have to run it from the '''Command Line'''. The command line may be reached by hitting Start, then Run, then &amp;quot;cmd&amp;quot; or &amp;quot;command&amp;quot; depending on your version of Windows.&lt;br /&gt;
&lt;br /&gt;
Example uses:&lt;br /&gt;
 python wmllint path\to\files&lt;br /&gt;
 python wmlindent path\to\files&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
 &amp;quot;C:\Program Files\Python2.4\python.exe&amp;quot; data\tools\wmllint --dryrun data\core data\{multiplayer,themes} data\campaigns &lt;br /&gt;
(You have to specify the full directory path to the executable if you don't have your environment variables set up correctly).&lt;br /&gt;
The first thing you type is the path to your python executable, followed by a space. The second thing you type is the path to the desired script to run, followed by a space. The third thing you type is the path to the folder (or file) to be processed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''A convenient way of running wmllint''' on Linux (Debian Lenny) and Windows (Xp) in comparison, '''Linux''':&lt;br /&gt;
&lt;br /&gt;
Assuming we're working with wesnoth 1.9 or more advanced versions (1.10 in this case).&lt;br /&gt;
 python2 /usr/share/games/wesnoth/1.10/data/tools/wmllint --dryrun /usr/share/games/wesnoth/1.10/data/core ~/.local/share/wesnoth/1.10/data/add-ons/A_Simple_Campaign 1&amp;gt;wmllint-run.log 2&amp;gt;wmllint-err.log&lt;br /&gt;
I have these commands inside of a file named&lt;br /&gt;
 wmllint_dryrun_ASC.sh&lt;br /&gt;
and execute it by opening a shell (=terminal, console, command window, bash,...), navigating into the directory with that file and typing&lt;br /&gt;
 bash wmllint_dryrun_ASC.sh&lt;br /&gt;
The python2 command should be automatically known on Debian. The path to the script tells the python interpreter what to execute. --dryrun: A wmllint option, see below. The path to the core files is needed to let wmllint know about e.g. defined core units, followed by the path to the add-on that shall be checked; the last two commands cause the result of the wmllint usage to be written into those files in the same directory as the script.&lt;br /&gt;
'''Windows''', this is logically exactly the same as the Linux shell script above, so if you are on a Mac you can probably conclude how you need to adapt the paths:&lt;br /&gt;
 E:\Python26\python.exe E:\Programme\Wesnoth_1.8_svn\data\tools\wmllint --dryrun E:\Programme\Wesnoth_1.8_svn\data\core E:\Programme\Wesnoth_1.8_svn\userdata\data\add-ons\A_Simple_Campaign 1&amp;gt;wmllint-run.log 2&amp;gt;wmllint-err.log&lt;br /&gt;
This is the content of a .txt file, whose extension I rename to .bat and double-click onto it. Opening a command window is not needed this way.&lt;br /&gt;
Since python isn't natively installed on windows and I don't have environment variables set, the full path to python.exe is given. If your directories contain spaces it may help to include the path in quotes:&lt;br /&gt;
 &amp;quot;C:\Programs\Battle for Wesnoth 1.8\data\tools\wmllint&amp;quot;&lt;br /&gt;
Remember that you do not need to enter all of the commands/paths at once. If it doesn't work, start with only &amp;quot;python&amp;quot; or &amp;quot;C:\Python26\python.exe&amp;quot; or the like and interpret the error messages that you get. If you get an &amp;quot;unknown command&amp;quot;, python isn't installed or environment variables aren't set correctly. After that, you can add the later commands one by one.&lt;br /&gt;
&lt;br /&gt;
== wmlscope ==&lt;br /&gt;
&lt;br /&gt;
The main use for &amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; is to find WML macro references without definitions and references to resource files (sounds and images) that don't exist.  These are difficult to spot from in-game because they usually result in silence or a missing image rather than actual broken game logic.  They may happen because of typos in your WML, or because the name of a macro or the location of a resource file changed between versions of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; also checks macro invocations for consistency.  It will complain&lt;br /&gt;
if a macro is called with the wrong number of arguments.  In most cases it can deduce information about the type of the literal expected to be passed to a given macro argument by looking at the name of the formal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Meanining&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Formals requiring this type&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Literals of this type&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;side&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a single side number&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;SIDE, *_SIDE, SIDE[0-9]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric or &amp;quot;global&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;numeric&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric integer literal&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;SIDE, X, Y, RED, GREEN, BLUE, TURN, PROB, LAYER, TIME, *_SIDE, *NUMBER, *AMOUNT, *COST, *RADIUS, *_X, *_Y, *_INCREMENT, *_FACTOR, *_TIME, *_SIZE, DURATION&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;\-?[0-9]+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;percentage&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a percentage&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*PERCENTAGE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric or 0\.[0-9]+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;position&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a single x,y coordinate&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;POSITION, *_POSITION, BASE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;-?[0-9]+,-?[0-9]+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;span&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of coordinates or coordinate ranges&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*_SPAN&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric, position or ([0-9]+\-[0-9]+,?|[0-9]+,?)+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;alliance&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of side numbers&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;SIDES, *_SIDES&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a span, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;range&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;an attack range&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;RANGE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;quot;melee&amp;quot; or &amp;quot;ranged&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;alignment&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;an alignment keyword&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;ALIGN&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;quot;lawful&amp;quot; or &amp;quot;neutral&amp;quot; or &amp;quot;chaotic&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;types&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of unit types&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;TYPES&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname, name, or anything that contains spaces and matches no other type&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;terrain_pattern&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of terrain codes to filter&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;ADJACENT*, TERRAINLIST*, *TERRAIN_PATTERN, RESTRICTING&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a terrain_code or name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;terrain_code&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a single terrain code, perhaps with overlay&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;TERRAIN*, *TERRAIN&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname or (\*|[A-Z][a-z]+)\^([A-Z][a-z\\|/]+\Z)?&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;shortname&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a terrain code or a short, capitalized variable name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[A-Z][a-z][a-z]?&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a name or identifier&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;NAME, VAR, IMAGESTEM, ID, FLAG, *_NAME, *_ID, NAMESPACE, BUILDER, *_VAR&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;anything without spaces that matches no other type&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;optional_string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a string value (may be empty)&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;ID_STRING, NAME_STRING, DESCRIPTION, IPF&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a string, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a nonempty string not matching any of the preceding types&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;STRING, TYPE, TEXT, *_STRING, *_TYPE, *_TEXT&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname, a name, a stringliteral, or anything that contains spaces and matches no other type&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;stringliteral&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a string in doublequotes or a translated string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;quot;.*&amp;quot; or _.* but not _[a-z].*&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;image&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;an image path, perhaps with [[ImagePathFunctionWML|image path functions]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*IMAGE, PROFILE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[A-Za-z0-9{}.][A-Za-z0-9_/+{}.-]*\.(png|jpg)(?=(~.*)?)&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;sound&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a music or sound filename&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;MUSIC, SOUND&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;string ending with &amp;quot;.wav&amp;quot; or &amp;quot;.ogg&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;filter&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[FilterWML|WML filter]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;FILTER&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;any non-quoted string containing &amp;quot;=&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;WML&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;arbitrary WML fragment&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;WML, *_WML&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;any non-quoted string containing &amp;quot;=&amp;quot;, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;affix&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a prefix, suffix, or infix for a variable name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;AFFIX, *AFFIX, POSTFIX, ROTATION&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname or name, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;any&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;anything&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*VALUE, [ARS][0-9]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;anything&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the actual argument is a macro call {.*}, then it matches any formal  Otherwise, if the formal has an identifiable type, &amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; will complain if the actual literal does not match it.&lt;br /&gt;
&lt;br /&gt;
The argument type check only works in macro calls that fit on a single line.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; has many options for changing the reports it generates; the more advanced ones are intended for Wesnoth developers.  Invocations for the most commonly useful reports it generates are included in &amp;lt;i&amp;gt;data/tools/Makefile&amp;lt;/i&amp;gt; of the source distribution. Here are some of those reports:&lt;br /&gt;
&lt;br /&gt;
; make unresolved: Report on unresolved macro calls and resource references; also report macro argument-type mismatches.  (This is what you are most likely to want to do). &lt;br /&gt;
&lt;br /&gt;
; make all: Report all macro and resource file references, not just unresolved ones.&lt;br /&gt;
&lt;br /&gt;
; make collisions: Report on duplicate resource files.&lt;br /&gt;
&lt;br /&gt;
For more advanced users, or those who want to understand what the canned Makefile invocations are doing, here is a summary of &amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt;'s options. Some of the more advanced options will require you to understand &lt;br /&gt;
[http://docs.python.org/lib/re-syntax.html Python regular expressions].&lt;br /&gt;
&lt;br /&gt;
; -h, --help:                 Emit a help message and quit&lt;br /&gt;
; -c, --crossreference:       Report resolved macro references (implies -w 1)&lt;br /&gt;
; -C, --collisions:           Report duplicate resource files   &lt;br /&gt;
; -d, --deflist:              Make definition list.  (This one is for campaign server maintainers.)&lt;br /&gt;
; -e &amp;lt;i&amp;gt;regexp&amp;lt;/i&amp;gt;, --exclude &amp;lt;i&amp;gt;regexp&amp;lt;/i&amp;gt;:   Ignore files matching the specified regular expression. &lt;br /&gt;
; -f &amp;lt;i&amp;gt;dir&amp;lt;/i&amp;gt;, --from &amp;lt;i&amp;gt;dir&amp;lt;/i&amp;gt;:         Report only on macros defined under &amp;lt;i&amp;gt;dir&amp;lt;/i&amp;gt;&lt;br /&gt;
; -l, --listfiles:            List files that will be processed&lt;br /&gt;
; -r &amp;lt;i&amp;gt;ddd&amp;lt;/i&amp;gt;, --refcount=&amp;lt;i&amp;gt;ddd&amp;lt;/i&amp;gt;:     Report only on macros with references in exactly &amp;lt;i&amp;gt;ddd&amp;lt;/i&amp;gt; files.&lt;br /&gt;
; -u, --unresolved:           Report unresolved macro references&lt;br /&gt;
; -w, --warnlevel:            Set to 1 to warn of duplicate macro definitions&lt;br /&gt;
; --force-used reg:          Ignore reference count 0 on names matching regexp&lt;br /&gt;
; --extracthelp:              Extract help from macro definition comments.&lt;br /&gt;
&lt;br /&gt;
== wmllint ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; is a tool for migrating your WML to the current version.  It handles two problems: &lt;br /&gt;
&lt;br /&gt;
* Resource files and macro names may change between versions of the game. &amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; knows about these changes and will tweak your WML to fit where it can.&lt;br /&gt;
&lt;br /&gt;
* Between 1.2.x and 1.3.1 the terrain-coding system used in map files underwent a major change. It changed again in a minor way between 1.3.1 and 1.3.2.  &amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; will translate your maps for you, unless you use custom terrains in which case you will have to do it by hand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; also performs various sanity-checking operations, reporting:&lt;br /&gt;
&lt;br /&gt;
* unbalanced tags&lt;br /&gt;
* strings that need a translation mark and do not have them&lt;br /&gt;
* strings that have a translation mark and should not&lt;br /&gt;
* translatable strings containing macro references &lt;br /&gt;
* filter references by description= (id= in 1.5) not matched by an actual unit&lt;br /&gt;
* abilities or traits without matching special notes, or vice-versa&lt;br /&gt;
* consistency between recruit= and recruitment_pattern= instances&lt;br /&gt;
* double space after punctuation in translatable strings.&lt;br /&gt;
* unknown races or movement types in units&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; takes a directory-path argument specifying the WML directories to work on.  It will modify any cfg and map files under those directories that need to be changed.  Here is a summary of its options:&lt;br /&gt;
&lt;br /&gt;
; -h, --help:                 Emit a help message and quit.&lt;br /&gt;
; -d, --dryrun:               List changes but don't perform them.&lt;br /&gt;
; -v, --verbose:              Set verbosity; more details below.&lt;br /&gt;
; -c, --clean:                Clean up -bak files.&lt;br /&gt;
; -D, --diff:                 Show diffs between unconverted and unconverted files.&lt;br /&gt;
; -r, --revert:               Revert the conversion from the -bak files.&lt;br /&gt;
; -n, --nolift:               Suppress lifting, do sanity checks only &lt;br /&gt;
&lt;br /&gt;
The verbosity option works like this:&lt;br /&gt;
&lt;br /&gt;
; -v:          lists changes.&lt;br /&gt;
; -v -v:       warns of maps already converted.&lt;br /&gt;
; -v -v -v:    names each file before it's processed.&lt;br /&gt;
; -v -v -v -v: shows verbose parse details (developers only).&lt;br /&gt;
&lt;br /&gt;
The recommended procedure is this:&lt;br /&gt;
&lt;br /&gt;
# Run it with --dryrun first to see what it will do.&lt;br /&gt;
# If the messages look good, run without --dryrun; the old content will be left in backup files with a -bak extension.&lt;br /&gt;
# Eyeball the changes with the --diff option.&lt;br /&gt;
# Use wmlscope, with a directory path including the Wesnoth mainline WML, to check that you have no unresolved references.&lt;br /&gt;
# Test the conversion.&lt;br /&gt;
# Use either --clean to remove the -bak files or --revert to undo the conversion.&lt;br /&gt;
&lt;br /&gt;
Additionally, wmllint tries to locate a spell checker on your system and spell-checks storyline and message strings.  It will work automatically with either aspell, myspell, or ispell provided you have the &amp;lt;tt&amp;gt;enchant.py&amp;lt;/tt&amp;gt; Python library installed.&lt;br /&gt;
&lt;br /&gt;
== wmlindent ==&lt;br /&gt;
&lt;br /&gt;
Call with no arguments to filter WML on standard input to reindented WML on&lt;br /&gt;
standard output.  If arguments are specified, they are taken to be files to be&lt;br /&gt;
re-indented in place; interrupting will be safe, as each reindenting&lt;br /&gt;
will be done to a copy that is atomically renamed when it's done. This&lt;br /&gt;
code never modifies anything but blank lines and leading and trailing whitespace on non-blank lines.&lt;br /&gt;
&lt;br /&gt;
The indent unit is four spaces.  Absence of an option to change this is&lt;br /&gt;
deliberate; the purpose of this tool is to prevent style wars, not encourage&lt;br /&gt;
them.&lt;br /&gt;
&lt;br /&gt;
If you don't apply this tool to your own WML, the mainline-campaign maintainers &lt;br /&gt;
will do it when and if your code is accepted into the tree.&lt;br /&gt;
&lt;br /&gt;
Note: This tool does not include a parser.  It will produce bad results on WML&lt;br /&gt;
that is syntactically unbalanced.  Unbalanced double quotes that aren't part&lt;br /&gt;
of a multiline literal will also confuse it.  You will receive warnings&lt;br /&gt;
if there's an indent open at end of file or if a closer occurs with&lt;br /&gt;
indent already zero; these two conditions strongly suggest unbalanced WML.&lt;br /&gt;
&lt;br /&gt;
== GUI.pyw ==&lt;br /&gt;
&lt;br /&gt;
Starting from version 1.11.15 and 1.13.0, a GUI (written in Tkinter, plus the themed widgets ttk) is available in the same directory as the other tools. To use it, you need to have a version of Python equal to or greater than 2.7.0 (the 2.6.x series doesn't include the ttk widgets, and as such is unsuitable for this script).&lt;br /&gt;
&lt;br /&gt;
If you're on Linux, be sure to have installed the ''python-tk'' module, '''or the application won't run at all'''. To install it in a Debian-based distro (like Ubuntu), type this line in a Terminal:&lt;br /&gt;
 sudo apt-get install python-tk&lt;br /&gt;
&lt;br /&gt;
To start it, just double click on the GUI.pyw file. The interface is pretty much self explanatory, and allows you to run wmllint, wmlscope and wmlindent, modify their options, select an add-on, and save the tools' output as a text file.&lt;br /&gt;
&lt;br /&gt;
[[Category:Create]]&lt;br /&gt;
[[Category:Tools]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=55284</id>
		<title>LuaWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=55284"/>
		<updated>2014-06-29T09:30:10Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* WML variables */ Added wesnoth.get_all_vars&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
== The '''[lua]''' tag ==&lt;br /&gt;
&lt;br /&gt;
This tag is a part of [[ActionWML]], thus can be used inside [event] and at other places where [[ActionWML]] can be used. It makes it possible to write actions with the [http://www.lua.org Lua 5.2] language.&lt;br /&gt;
&lt;br /&gt;
It is also possible to put this tag inside a [scenario] [[ScenarioWML]], those tags will be executed immideately when the lua engine loads which is even before the scenario preload event is fired.&lt;br /&gt;
&lt;br /&gt;
The tag supports only the '''code''' key, which is a string containing the Lua scripts. Since Lua makes usage of the quotes and the { and } symbols, it is certainly wise to enclose the script between stronger quotes, as they prevent the preprocessor from performing macro expansion and tokenization.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; wesnoth.message &amp;quot;Hello World!&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
The Lua kernel can also be accessed from the [[CommandMode|command mode]]:&lt;br /&gt;
&lt;br /&gt;
 :lua local u = wesnoth.get_units({ id = &amp;quot;Konrad&amp;quot; })[1]; u.moves = 5&lt;br /&gt;
&lt;br /&gt;
The '''[args]''' sub-tag can be used to pass a WML object to the script via its variadic local variable &amp;quot;'''...'''&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; local t = ...; wesnoth.message(tostring(t.text)) &amp;gt;&amp;gt;&lt;br /&gt;
     [args]&lt;br /&gt;
         text = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/args]&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
== Global environment ==&lt;br /&gt;
&lt;br /&gt;
All the Lua scripts of a scenario share the same global environment (aka Lua state). For instance, a function defined in an event can be used in all the events that happen after it.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             function narrator(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
In the example above, the redundant structure could be hidden behind macros. But it may be better to simply define a new WML tag.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             -- The function is now local, since its name does not have to be&lt;br /&gt;
             -- visible outside this Lua scripts.&lt;br /&gt;
             local function handler(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
             -- Create a new tag named [narrator].&lt;br /&gt;
             wesnoth.register_wml_action(&amp;quot;narrator&amp;quot;, handler)&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
The global environment is not preserved over save/load cycles. Therefore, storing values in the global environment is generally a bad idea (unless it has been redirected to WML variables, see [[LuaWML:Variables#set_wml_var_metatable|helper.set_wml_var_metatable]]). The only time assigning global variables (including function definitions) makes sense is during a [[EventWML#Predefined 'name' Key Values|preload]] event, as this event is always run. Therefore, helper functions defined at that time will be available to all the later scripts.&lt;br /&gt;
&lt;br /&gt;
The global environment initially contains the following modules: [http://www.lua.org/manual/5.1/manual.html#5.1 basic] (no name), [http://www.lua.org/manual/5.1/manual.html#5.4 string], [http://www.lua.org/manual/5.1/manual.html#5.5 table], and [http://www.lua.org/manual/5.1/manual.html#5.6 math]. A '''wesnoth''' module is also available, it provides access to the [[#Interface to the C++ engine|C++ engine]]. Additionally, the functions clock, date, time and difftime from the [http://www.lua.org/manual/5.1/manual.html#5.8 os] library (keep in mind that they aren't multiplayer- and replay-safe), as well as traceback from the [http://www.lua.org/manual/5.1/manual.html#5.9 debug] library are also available.&lt;br /&gt;
&lt;br /&gt;
At the start of a script, the variadic local variable '''...''' (three dots) is a proxy table representing [[#Encoding WML objects into Lua tables|WML data]]. This table is the content of the '''[args]''' sub-tag of the '''[lua]''' tag, if any.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following WML event is taken from Wesnoth' tutorial. It will serve as an example to present how Lua scripts are embedded into Wesnoth. The event is fired whenever a unit from side 1 (that is, the hero controlled by the user) moves to a tile that is not the one set in the WML variable ''target_hex''.&lt;br /&gt;
&lt;br /&gt;
 # General catch for them moving to the wrong place.&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [if]&lt;br /&gt;
         [variable]&lt;br /&gt;
             name=target_hex.is_set&lt;br /&gt;
             equals=yes&lt;br /&gt;
         [/variable]&lt;br /&gt;
         [then]&lt;br /&gt;
             [if]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=x1&lt;br /&gt;
                     equals=$target_hex.x&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=y1&lt;br /&gt;
                     equals=$target_hex.y&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [then]&lt;br /&gt;
                 [/then]&lt;br /&gt;
                 [else]&lt;br /&gt;
                     [redraw][/redraw]&lt;br /&gt;
                     [message]&lt;br /&gt;
                         speaker=narrator&lt;br /&gt;
                         message=_ &amp;quot;*Oops!&lt;br /&gt;
 You moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot; +&lt;br /&gt;
                         _ &amp;quot;&lt;br /&gt;
 *Left click or press spacebar to continue...&amp;quot;&lt;br /&gt;
                     [/message]&lt;br /&gt;
                 [/else]&lt;br /&gt;
             [/if]&lt;br /&gt;
         [/then]&lt;br /&gt;
     [/if]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
A Lua script that performs the same action is presented below.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             local event_data = wesnoth.current.event_context&lt;br /&gt;
             if V.target_hex.is_set and&lt;br /&gt;
                (event_data.x1 ~= V.target_hex.x or event_data.y1 ~= V.target_hex.y)&lt;br /&gt;
             then&lt;br /&gt;
                 W.redraw()&lt;br /&gt;
                 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Here is a more detailed explanation of the Lua code. Its first line&lt;br /&gt;
&lt;br /&gt;
 local event_data = wesnoth.current.event_context&lt;br /&gt;
&lt;br /&gt;
puts the event data into the ''event_data'' local variable. Since it is a ''moveto'' event, the ''event_data'' table contains the destination of the unit in the ''x1'' and ''y1'' fields.&lt;br /&gt;
&lt;br /&gt;
The next two lines then test&lt;br /&gt;
&lt;br /&gt;
 if V.target_hex.is_set and&lt;br /&gt;
    (event_data.x1 ~= V.target_hex.x or event_data.y1 ~= V.target_hex.y)&lt;br /&gt;
&lt;br /&gt;
whether the variable ''V.target_hex'' matches the event parameters. Since ''V'' is not a local variable, it is taken from the global environment. Usually, variables from the global environment are not persistent (they get lost on reloading), so it shouldn't be used to store data. In order to have an easy way to access the usual persistent Wml variables, the global variable ''V''  was mapped to the storage of WML variables by the following ''preload'' event.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             -- skipping some other initializations&lt;br /&gt;
             -- ...&lt;br /&gt;
             V = H.set_wml_var_metatable {}&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Without a prelude redirecting ''V'', the conditional would have been written&lt;br /&gt;
&lt;br /&gt;
 if wesnoth.get_variable(&amp;quot;target_hex.is_set&amp;quot;) and&lt;br /&gt;
    (event_data.x1 ~= wesnoth.get_variable(&amp;quot;target_hex.x&amp;quot;) or event_data.y1 ~= wesnoth.get_variable(&amp;quot;target_hex.y&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The body of the conditional then performs the [[InterfaceActionsWML#Other interface tags|[redraw]]] action.&lt;br /&gt;
&lt;br /&gt;
 W.redraw()&lt;br /&gt;
&lt;br /&gt;
Again, this short syntax is made possible by a line of the prelude that makes ''W'' a proxy for performing WML actions.&lt;br /&gt;
&lt;br /&gt;
 W = H.set_wml_action_metatable {}&lt;br /&gt;
&lt;br /&gt;
Without this shortcut, the first statement would have been written&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;redraw&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Finally the script displays a message by&lt;br /&gt;
&lt;br /&gt;
 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The ''narrator_says'' function is defined in the prelude too, since the construct behind it occurs several times in the tutorial. In plain WML, macros would have been used instead. The definition of the function is&lt;br /&gt;
&lt;br /&gt;
 function narrator_says(m)&lt;br /&gt;
     W.message { speaker=&amp;quot;narrator&amp;quot;,&lt;br /&gt;
                 message = m .. _ &amp;quot;\n*Left click or press spacebar to continue...&amp;quot; }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The function fires a [[InterfaceActionsWML#.5Bmessage.5D|[message]]] action and passes a WML object containing the usual two fields to it. The second field is initialized by concatenating the function argument with another string. Both strings are prefixed by the ''_'' symbol to mark them as translatable. (Note that ''_'' is just a unary function, not a keyword.) Again, this is made possible by a specific line of the prelude:&lt;br /&gt;
&lt;br /&gt;
 _ = wesnoth.textdomain &amp;quot;wesnoth-tutorial&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A longer translation of the tutorial is available at [https://gna.org/patch/download.php?file_id=5483].&lt;br /&gt;
&lt;br /&gt;
== Interface to the engine and helper functions ==&lt;br /&gt;
&lt;br /&gt;
Functionalities of the game engine are available through the functions contained in the '''wesnoth''' global table. Some of these functions return proxy tables. Writes to fields marked &amp;quot;read-only&amp;quot; are ignored. The '''__cfg''' fields return plain tables; in particular, writes do not modify the original object, and reads return the values from the time the dump was performed.&lt;br /&gt;
&lt;br /&gt;
Some helper functions are provided by the '''lua/helper.lua''' library. They are stored inside a table that is returned when loading the library with [[LuaWML:Files#wesnoth.require|wesnoth.require]].&lt;br /&gt;
&lt;br /&gt;
 helper = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== WML variables ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_all_vars|wesnoth.get_all_vars]] {{DevFeature1.13|0}}&lt;br /&gt;
* [[LuaWML:Variables#helper.set_wml_var_metatable|helper.set_wml_var_metatable]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_child|helper.get_child]]&lt;br /&gt;
* [[LuaWML:Variables#helper.child_range|helper.child_range]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_array|helper.get_variable_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_proxy_array|helper.get_variable_proxy_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.set_variable_array|helper.set_variable_array]]&lt;br /&gt;
&lt;br /&gt;
=== Events and WML actions ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire|wesnoth.fire]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.wml_actions|wesnoth.wml_actions]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.game_events|wesnoth.game_events]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire_event|wesnoth.fire_event]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.eval_conditional|wesnoth.eval_conditional]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.tovconfig|wesnoth.tovconfig]]&lt;br /&gt;
* [[LuaWML:Events#helper.set_wml_action_metatable|helper.set_wml_action_metatable]]&lt;br /&gt;
* [[LuaWML:Events#helper.wml_error|helper.wml_error]]&lt;br /&gt;
* [[LuaWML:Events#helper.literal|helper.literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.parsed|helper.parsed]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_literal|helper.shallow_literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_parsed|helper.shallow_parsed]]&lt;br /&gt;
&lt;br /&gt;
=== User interface ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Display#wesnoth.message|wesnoth.message]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.clear_messages|wesnoth.clear_messages]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.textdomain|wesnoth.textdomain]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.delay|wesnoth.delay]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.float_label|wesnoth.float_label]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_hex|wesnoth.select_hex]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.scroll_to_tile|wesnoth.scroll_to_tile]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.lock_view|wesnoth.lock_view]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.view_locked|wesnoth.view_locked]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.play_sound|wesnoth.play_sound]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_music|wesnoth.set_music]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_dialog|wesnoth.show_dialog]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_value|wesnoth.set_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_dialog_value|wesnoth.get_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_active|wesnoth.set_dialog_active]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_callback|wesnoth.set_dialog_callback]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_markup|wesnoth.set_dialog_markup]] {{DevFeature1.11|9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_canvas|wesnoth.set_dialog_canvas]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_displayed_unit|wesnoth.get_displayed_unit]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.theme_items|wesnoth.theme_items]]&lt;br /&gt;
* [[LuaWML:Display#helper.get_user_choice|helper.get_user_choice]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_time_of_day|wesnoth.get_time_of_day]]&lt;br /&gt;
&lt;br /&gt;
=== Map and terrains ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_map_size|wesnoth.get_map_size]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain|wesnoth.get_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.set_terrain|wesnoth.set_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain_info|wesnoth.get_terrain_info]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_selected_tile|wesnoth.get_selected_tile]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_locations|wesnoth.get_locations]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_villages|wesnoth.get_villages]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.match_location|wesnoth.match_location]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_tile_overlay|wesnoth.add_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_tile_overlay|wesnoth.remove_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_image|items.place_image]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_halo|items.place_halo]]&lt;br /&gt;
* [[LuaWML:Tiles#items.remove|items.remove]]&lt;br /&gt;
&lt;br /&gt;
=== Units ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_units|wesnoth.get_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit|wesnoth.get_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.match_unit|wesnoth.match_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_unit|wesnoth.put_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_recall_units|wesnoth.get_recall_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_recall_unit|wesnoth.put_recall_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.create_unit|wesnoth.create_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.copy_unit|wesnoth.copy_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.extract_unit|wesnoth.extract_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_modification|wesnoth.add_modification]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_resistance|wesnoth.unit_resistance]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_defense|wesnoth.unit_defense]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_movement_cost|wesnoth.unit_movement_cost]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_ability|wesnoth.unit_ability]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type_ids|wesnoth.get_unit_type_ids]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type|wesnoth.get_unit_type]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_types|wesnoth.unit_types]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.races|wesnoth.races]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_traits|wesnoth.get_traits]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.simulate_combat|wesnoth.simulate_combat]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.transform_unit|wesnoth.transform_unit]]&lt;br /&gt;
&lt;br /&gt;
=== Sides ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_side|wesnoth.get_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.sides|wesnoth.sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_sides|wesnoth.get_sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_village_owner|wesnoth.get_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.set_village_owner|wesnoth.set_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.is_enemy|wesnoth.is_enemy]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.match_side|wesnoth.match_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_starting_location|wesnoth.get_starting_location]]&lt;br /&gt;
* [[LuaWML:Sides#helper.all_teams|helper.all_teams]]&lt;br /&gt;
&lt;br /&gt;
=== Pathfinder ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_path|wesnoth.find_path]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_vacant_tile|wesnoth.find_vacant_tile]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_reach|wesnoth.find_reach]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_cost_map|wesnoth.find_cost_map]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.distance_between|helper.distance_between]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.adjacent_tiles|helper.adjacent_tiles]]&lt;br /&gt;
&lt;br /&gt;
=== Lua files ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Files#wesnoth.dofile|wesnoth.dofile]]&lt;br /&gt;
* [[LuaWML:Files#wesnoth.require|wesnoth.require]]&lt;br /&gt;
&lt;br /&gt;
=== Location sets ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Location_set#location_set.create|location_set.create]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_pairs|location_set.of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_wml_var|location_set.of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:empty|location_set:empty]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:size|location_set:size]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:clear|location_set:clear]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:get|location_set:get]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:insert|location_set:insert]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:remove|location_set:remove]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_pairs|location_set:of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_wml_var|location_set:of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_pairs|location_set:to_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_stable_pairs|location_set:to_stable_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_wml_var|location_set:to_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union|location_set:union]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter|location_set:inter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:iter|location_set:iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:stable_iter|location_set:stable_iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:filter|location_set:filter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union_merge|location_set:union_merge]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter_merge|location_set:inter_merge]]&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.game_config|wesnoth.game_config]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_era|wesnoth.get_era]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.current|wesnoth.current]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.synchronize_choice|wesnoth.synchronize_choice]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_image_size|wesnoth.get_image_size]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compare_versions|wesnoth.compare_versions]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.have_file|wesnoth.have_file]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.debug|wesnoth.debug]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_time_stamp|wesnoth.get_time_stamp]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#helper.set_wml_tag_metatable|helper.set_wml_tag_metatable]]&lt;br /&gt;
* [[LuaWML:Misc#helper.modify_unit|helper.modify_unit]]&lt;br /&gt;
* [[LuaWML:Misc#helper.move_unit_fake|helper.move_unit_fake]]&lt;br /&gt;
* [[LuaWML:Misc#helper.rand|helper.rand]]&lt;br /&gt;
* [[LuaWML:Misc#helper.round|helper.round]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#helper.shuffle|helper.shuffle]] {{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
== Encoding WML objects into Lua tables ==&lt;br /&gt;
&lt;br /&gt;
Function [[LuaWML:Events#wesnoth.fire|wesnoth.fire]] expects a table representing a WML object as its second argument (if needed). Function [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]] allows to modify whole WML objects, again by passing it a table. Function [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]] transforms a WML object into a table, if its second argument is not set to ''true''. All these tables have the same format.&lt;br /&gt;
&lt;br /&gt;
Scalar fields are transformed into WML attributes. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     a_bool = true,&lt;br /&gt;
     an_int = 42,&lt;br /&gt;
     a_float = 1.25,&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;,&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     a_bool = &amp;quot;yes&amp;quot;&lt;br /&gt;
     an_int = &amp;quot;42&amp;quot;&lt;br /&gt;
     a_float = &amp;quot;1.25&amp;quot;&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
WML child objects are not stored as Lua named fields, since several of them can have the same tag. Moreover, their tags can conflict with the attribute keys. So child objects are stored as pairs string + table in the unnamed fields in definition order. This means that for every subtag appearing in the wml code there is an additional table &amp;quot;layer&amp;quot; in the corresponding WML table of the form {[1] = &amp;quot;tag_name&amp;quot;, [2] = {}} which is equivalent to {&amp;quot;tag_name&amp;quot;, {}}. [1] etc are the unnamed fields (as opposed to wml attributes). The table under [2] in this subtable then holds the wml attributes from inside the wml subtag. So every subtag other than the toplevel tag corresponds to two nested tables each. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { v = 1, w = 2 } },&lt;br /&gt;
     { &amp;quot;foo&amp;quot;, { x = false } },&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     { &amp;quot;foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     foo = 42&lt;br /&gt;
     [bar]&lt;br /&gt;
         v = 1&lt;br /&gt;
         w = 2&lt;br /&gt;
     [/bar]&lt;br /&gt;
     [foo]&lt;br /&gt;
         x = no&lt;br /&gt;
     [/foo]&lt;br /&gt;
     [bar]&lt;br /&gt;
         y = foo&lt;br /&gt;
     [bar]&lt;br /&gt;
     [foobar]&lt;br /&gt;
         z = 5&lt;br /&gt;
         [barfoo]&lt;br /&gt;
         [/barfoo]&lt;br /&gt;
     [/foobar]&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
Both tables above are also equivalent to this WML table, where all unnamed fields are displayed:&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     [1] = { [1] = &amp;quot;bar&amp;quot;, [2] = { v = 1, w = 2 } },&lt;br /&gt;
     [2] = { [1] = &amp;quot;foo&amp;quot;, [2] = { x = false } },&lt;br /&gt;
     [3] = { [1] = &amp;quot;bar&amp;quot;, [2] = { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     [4] = { [1] = &amp;quot;foobar&amp;quot;, [2] = { z = 5, [1] = { [1] = &amp;quot;barfoo&amp;quot;, [2] = {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
So assuming ''cfg'' contains the above WML object, the following accesses are possible:&lt;br /&gt;
&lt;br /&gt;
 a_int = cfg.foo        -- &amp;quot;dummy.foo&amp;quot;, 42&lt;br /&gt;
 a_string = cfg[3][2].y -- &amp;quot;dummy.bar[1].y&amp;quot;, &amp;quot;foo&amp;quot;&lt;br /&gt;
 a_table = cfg[4][2]    -- &amp;quot;dummy.foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } }&lt;br /&gt;
&lt;br /&gt;
Consider using the [[LuaWML:Variables#helper.get_child|helper.get_child]] and [[LuaWML:Variables#helper.child_range|helper.child_range]] to ease the access to subtags.&lt;br /&gt;
&lt;br /&gt;
Functions registered by [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]] receive their data in a userdata object which has the exact same structure as above. It is read-only however. Accessing fields or children performs variable substitution on the fly. Its '''__parsed''' and '''__literal''' fields provide translations to plain tables (therefore writable). '''__literal''' returns the original text of the data (including dollar symbols in attributes and [insert_tag] children), while '''__parsed''' performs a variable substitution.&lt;br /&gt;
&lt;br /&gt;
For instance, if you cannot stand any longer the fact that '''first_time_only''' is set to yes by default for the '''[event]''' tag, you can redefine it. But we have to be careful not to cause variable substitution, since the engine would perform a second variable substitution afterwards.&lt;br /&gt;
&lt;br /&gt;
 local old_event_handler&lt;br /&gt;
 old_event_handler = register_wml_action(&amp;quot;event&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         -- Get the plain text from the user.&lt;br /&gt;
         local new_cfg = cfg.__literal&lt;br /&gt;
         -- The expression below is equivalent to cfg.__parsed.first_time_only,&lt;br /&gt;
         -- only faster. It is needed, since the first_time_only attribute may&lt;br /&gt;
         -- reference variables.&lt;br /&gt;
         local first = cfg.first_time_only&lt;br /&gt;
         -- Modify the default behavior of first_time_only.&lt;br /&gt;
         if first == nil then first = false end&lt;br /&gt;
         new_cfg.first_time_only = first&lt;br /&gt;
         -- Call the engine handler.&lt;br /&gt;
         old_event_handler(new_cfg)&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Note that, since the object is a userdata and not a table, '''pairs''' and '''ipairs''' are unfortunately not usable on it. So scripts have to work at a lower level. For instance, the following function returns the first sub-tag with a given name and it works both on WML tables and WML userdata:&lt;br /&gt;
&lt;br /&gt;
 function get_child(cfg, name)&lt;br /&gt;
     for i = 1, #cfg do&lt;br /&gt;
         local v = cfg[i]&lt;br /&gt;
         if v[1] == name then return v[2] end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Another approach for handling userdata and tables in the same way, would be to convert the former into the latter beforehand:&lt;br /&gt;
&lt;br /&gt;
 if getmetatable(cfg) == &amp;quot;wml object&amp;quot; then cfg = cfg.__parsed end&lt;br /&gt;
&lt;br /&gt;
The WML userdata provides two other special fields: '''__shallow_parsed''' and '''__shallow_literal'''. They return a table corresponding to the WML userdata with variable substitution performed on the attributes (or not). [insert_tag] tags have also been parsed, so the number of children is faithful. But contrarily to '''__parsed''' and '''__literal''', the process is not recursive: all the children are still WML userdata and variable substitution can still happen for them. These shallow translators are meant as optimized versions of the deep ones, when only the toplevel attributes need to be writable.&lt;br /&gt;
&lt;br /&gt;
== Skeleton of a preload event ==&lt;br /&gt;
&lt;br /&gt;
The following event is a skeleton for a prelude enabling Lua in your WML events. It creates a table ''H'' containing the functions from helper.lua and a table ''W'' that serves as a proxy for firing WML actions. It sets up a table ''T'' so be used for easier creation of valid WML tables. It also sets up a table ''V'' so that any access to it is redirected to the persistent WML storage.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             W = H.set_wml_action_metatable {}&lt;br /&gt;
             T = H.set_wml_tag_metatable {}&lt;br /&gt;
             V = H.set_wml_var_metatable {}&lt;br /&gt;
             _ = wesnoth.textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
             -- Define your global constants here.&lt;br /&gt;
             -- ...&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
             -- Define your global functions here.&lt;br /&gt;
             -- ...&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
It may be worth putting the whole Lua script above inside a separate file and having the ''preload'' event load it:&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; wesnoth.dofile &amp;quot;~add-ons/Whatever/file.lua&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
== Remarks ==&lt;br /&gt;
&lt;br /&gt;
The math.random function is not safe for replays and multiplayer games, since the random values will be different each time and on all the clients. Instead, the Lua code should rely on the [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] tag to synchronize random values.&lt;br /&gt;
&lt;br /&gt;
 function random(min, max)&lt;br /&gt;
   if not max then min, max = 1, min end&lt;br /&gt;
   wesnoth.fire(&amp;quot;set_variable&amp;quot;, { name = &amp;quot;LUA_random&amp;quot;, rand = string.format(&amp;quot;%d..%d&amp;quot;, min, max) })&lt;br /&gt;
   local res = wesnoth.get_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   wesnoth.set_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   return res&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference|*]]&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Variables&amp;diff=55283</id>
		<title>LuaWML/Variables</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Variables&amp;diff=55283"/>
		<updated>2014-06-29T09:28:49Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added wesnoth.get_all_vars&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions and helpers for handling WML variables and containers.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_variable ====&lt;br /&gt;
&lt;br /&gt;
Loads a WML variable with the given qualified name (argument 1) and converts it into a Lua object. Returns ''nil'' if the name does not point to anything, a scalar for a WML attribute, and a table for a WML object. The format of the table is described in [[LuaWML#Encoding WML objects into Lua tables]].&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;store_unit&amp;quot;, { variable=&amp;quot;my_unit&amp;quot;, { &amp;quot;filter&amp;quot;, { id=&amp;quot;hero&amp;quot; } } })&lt;br /&gt;
 local heros_hp = wesnoth.get_variable(&amp;quot;my_unit[0].hitpoints&amp;quot;)&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;The 'hero' unit has %d hitpoints.&amp;quot;, heros_hp))&lt;br /&gt;
&lt;br /&gt;
Argument 2, if ''true'', prevents the recursive conversion when the name points to an object; a fresh empty table is returned in this case. This is mainly used for writing proxy objects, e.g. in [[#helper.set_wml_var_metatable]].&lt;br /&gt;
&lt;br /&gt;
Note that, if the variable name happens to designate a sequence of WML objects, only the first one (index 0) is fetched. If all the WML objects with this name should have been returned, use [[#helper.get_variable_array]] instead.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_variable ====&lt;br /&gt;
&lt;br /&gt;
Converts and stores a Lua object (argument 2) to a WML variable (argument 1). A WML object is created for a table, an attribute otherwise.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;my_unit.hitpoints&amp;quot;, heros_hp + 10)&lt;br /&gt;
&lt;br /&gt;
Setting a WML variable to nil erases it.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_all_vars ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|0}} Returns all the WML variables currently set in form of a WML table. This function accepts no arguments.&lt;br /&gt;
&lt;br /&gt;
 for key, value in pairs( wesnoth.get_all_vars() ) do&lt;br /&gt;
     if type( value ) == &amp;quot;table&amp;quot; then&lt;br /&gt;
         print( key, value[1], value[2] )&lt;br /&gt;
     else&lt;br /&gt;
         print( key, value )&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== helper.set_wml_var_metatable ====&lt;br /&gt;
&lt;br /&gt;
Sets the metable of a table so that it can be used to access WML variables. Returns the table. The fields of the tables are then proxies to the WML objects with the same names; reading/writing to them will directly access the WML variables.&lt;br /&gt;
&lt;br /&gt;
 helper.set_wml_var_metatable(_G)&lt;br /&gt;
 my_persistent_variable = 42&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
it's not reccomended to use helper.set_wml_var_metatable(_G) because that limits possible gobal variables to valid wml attributes or tables. This can have some surprising effects:&lt;br /&gt;
&lt;br /&gt;
 c = { a= 9}&lt;br /&gt;
 d = c&lt;br /&gt;
 c.a = 8&lt;br /&gt;
 wesnoth.message(d.a) -- normaly prints 8 but prints 9 with helper.set_wml_var_metatable(_G)&lt;br /&gt;
&lt;br /&gt;
 local lla = { {&amp;quot;a&amp;quot;, {}}}&lt;br /&gt;
 lla[1][2] = lla&lt;br /&gt;
 la = lla -- crashes wesnoth with helper.set_wml_var_metatable(_G)&lt;br /&gt;
&lt;br /&gt;
 helper = wesnoth.require(&amp;quot;lua/helper.lua&amp;quot;)&lt;br /&gt;
 helper.set_wml_var_metatable(_G)&lt;br /&gt;
 -- some code later (maybe in another addon)&lt;br /&gt;
 H = wesnoth.require(&amp;quot;lua/helper.lua&amp;quot;) -- fails because wesnoth.require(&amp;quot;lua/helper.lua&amp;quot;) doesn' return a valid wmltable..&lt;br /&gt;
&lt;br /&gt;
 helper = wesnoth.require(&amp;quot;lua/helper.lua&amp;quot;)&lt;br /&gt;
 helper.set_wml_var_metatable(_G)&lt;br /&gt;
 -- some code later (maybe in another addon)&lt;br /&gt;
 T = helper.set_wml_tag_metatable {}  -- doesn't work&lt;br /&gt;
 V = helper.set_wml_var_metatable({}) -- doesn't work&lt;br /&gt;
&lt;br /&gt;
even if you don't use such code in your addon it's still bad because other code of modifications or eras to be used with your addon might do. And you'll mess up their code. This is also true for SP campaigns because it might interfere with ai code and we plan to enable modifications in SP too.&lt;br /&gt;
Instead you should use set_wml_var_metatable with another table ('V' in this example):&lt;br /&gt;
&lt;br /&gt;
 V = helper.set_wml_var_metatable({})&lt;br /&gt;
 V.my_persistent_variable = 42&lt;br /&gt;
&lt;br /&gt;
==== helper.get_child ====&lt;br /&gt;
&lt;br /&gt;
Returns the first sub-tag of a WML object with the given name.&lt;br /&gt;
&lt;br /&gt;
 local u = wesnoth.get_units({ id = &amp;quot;Delfador&amp;quot; })[1]&lt;br /&gt;
 local costs = helper.get_child(u.__cfg, &amp;quot;movement_costs&amp;quot;)&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Delfador needs %d points to move through a forest.&amp;quot;, costs.forest))&lt;br /&gt;
&lt;br /&gt;
If a third parameter is passed, only children having a ''id'' attribute equal to it are considered.&lt;br /&gt;
&lt;br /&gt;
==== helper.child_range ====&lt;br /&gt;
&lt;br /&gt;
Returns an iterator over all the sub-tags of a WML object with the given name.&lt;br /&gt;
&lt;br /&gt;
 local u = wesnoth.get_units({ id = &amp;quot;Delfador&amp;quot; })[1]&lt;br /&gt;
 for att in helper.child_range(u.__cfg, &amp;quot;attack&amp;quot;) do&lt;br /&gt;
     wesnoth.message(tostring(att.description))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== helper.get_variable_array ====&lt;br /&gt;
&lt;br /&gt;
Fetches all the WML container variables with given name and returns a table containing them (starting at index 1).&lt;br /&gt;
&lt;br /&gt;
 function get_recall_list(side)&lt;br /&gt;
     wesnoth.fire(&amp;quot;store_unit&amp;quot;, { x = &amp;quot;recall&amp;quot;, variable = &amp;quot;LUA_recall_list })&lt;br /&gt;
     local l = get_variable_array &amp;quot;LUA_recall_list&amp;quot;&lt;br /&gt;
     wesnoth.set_variable &amp;quot;LUA_recall_list&amp;quot;&lt;br /&gt;
     return l&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== helper.get_variable_proxy_array ====&lt;br /&gt;
&lt;br /&gt;
Creates proxies for all the WML container variables with given name and returns a table containing them (starting at index 1). This function is similar to [[#helper.get_variable_array]], except that the proxies can be used for modifying WML containers.&lt;br /&gt;
&lt;br /&gt;
==== helper.set_variable_array ====&lt;br /&gt;
&lt;br /&gt;
Creates WML container variables with given name from given table.&lt;br /&gt;
&lt;br /&gt;
 helper.set_variable_array(&amp;quot;target&amp;quot;, { t1, t2, t3 })&lt;br /&gt;
 -- target[0] &amp;lt;- t1; target[1] &amp;lt;- t2; target[2] &amp;lt;- t3&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=Maintenance_tools&amp;diff=55269</id>
		<title>Maintenance tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=Maintenance_tools&amp;diff=55269"/>
		<updated>2014-06-25T14:01:19Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added GUI.pyw&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Wesnoth source code distribution includes a couple of tools intended to help authors maintain campaigns, faction &amp;amp; unit packs, and other WML resources. These&lt;br /&gt;
are:&lt;br /&gt;
 &lt;br /&gt;
; wmlscope: a cross-reference lister, useful for finding unresolved macro and resource-file references.&lt;br /&gt;
&lt;br /&gt;
; wmllint: a utility for sanity-checking WML syntax and porting your old WML to the current version of WML.  &lt;br /&gt;
&lt;br /&gt;
; wmlindent: a utility for reindenting WML to a uniform style.&lt;br /&gt;
&lt;br /&gt;
; GUI.pyw: a graphical interface&lt;br /&gt;
&lt;br /&gt;
You will need a Python 2 interpreter on your system to use these tools.  Linux, *BSD, and Mac OS/X should already have Python 2 installed; for Windows it's a free download&lt;br /&gt;
from http://www.python.org.  You will also need to know how to run command-line tools on your system.&lt;br /&gt;
&lt;br /&gt;
If you're working with ubuntu you might have to install the package wesnoth-1.10-tools (or the convenient version).&lt;br /&gt;
 sudo apt-get install wesnoth-1.10-tools&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All three tools will require you to supply a &amp;lt;i&amp;gt;directory list&amp;lt;/i&amp;gt;.  This is a set of directories containing the WML files you want to work on.&lt;br /&gt;
&lt;br /&gt;
This page is intended as ducementation for users.  A developer's-eye discussion of the design constraints on these tools, and their limitations, can be found here [https://mail.gna.org/public/wesnoth-dev/2010-02/msg00078.html].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Note to Windows Users:&amp;lt;/u&amp;gt; This means you have to run it from the '''Command Line'''. The command line may be reached by hitting Start, then Run, then &amp;quot;cmd&amp;quot; or &amp;quot;command&amp;quot; depending on your version of Windows.&lt;br /&gt;
&lt;br /&gt;
Example uses:&lt;br /&gt;
 python wmllint path\to\files&lt;br /&gt;
 python wmlindent path\to\files&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
 &amp;quot;C:\Program Files\Python2.4\python.exe&amp;quot; data\tools\wmllint --dryrun data\core data\{multiplayer,themes} data\campaigns &lt;br /&gt;
(You have to specify the full directory path to the executable if you don't have your environment variables set up correctly).&lt;br /&gt;
The first thing you type is the path to your python executable, followed by a space. The second thing you type is the path to the desired script to run, followed by a space. The third thing you type is the path to the folder (or file) to be processed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''A convenient way of running wmllint''' on Linux (Debian Lenny) and Windows (Xp) in comparison, '''Linux''':&lt;br /&gt;
&lt;br /&gt;
Assuming we're working with wesnoth 1.9 or more advanced versions (1.10 in this case).&lt;br /&gt;
 python2 /usr/share/games/wesnoth/1.10/data/tools/wmllint --dryrun /usr/share/games/wesnoth/1.10/data/core ~/.local/share/wesnoth/1.10/data/add-ons/A_Simple_Campaign 1&amp;gt;wmllint-run.log 2&amp;gt;wmllint-err.log&lt;br /&gt;
I have these commands inside of a file named&lt;br /&gt;
 wmllint_dryrun_ASC.sh&lt;br /&gt;
and execute it by opening a shell (=terminal, console, command window, bash,...), navigating into the directory with that file and typing&lt;br /&gt;
 bash wmllint_dryrun_ASC.sh&lt;br /&gt;
The python2 command should be automatically known on Debian. The path to the script tells the python interpreter what to execute. --dryrun: A wmllint option, see below. The path to the core files is needed to let wmllint know about e.g. defined core units, followed by the path to the add-on that shall be checked; the last two commands cause the result of the wmllint usage to be written into those files in the same directory as the script.&lt;br /&gt;
'''Windows''', this is logically exactly the same as the Linux shell script above, so if you are on a Mac you can probably conclude how you need to adapt the paths:&lt;br /&gt;
 E:\Python26\python.exe E:\Programme\Wesnoth_1.8_svn\data\tools\wmllint --dryrun E:\Programme\Wesnoth_1.8_svn\data\core E:\Programme\Wesnoth_1.8_svn\userdata\data\add-ons\A_Simple_Campaign 1&amp;gt;wmllint-run.log 2&amp;gt;wmllint-err.log&lt;br /&gt;
This is the content of a .txt file, whose extension I rename to .bat and double-click onto it. Opening a command window is not needed this way.&lt;br /&gt;
Since python isn't natively installed on windows and I don't have environment variables set, the full path to python.exe is given. If your directories contain spaces it may help to include the path in quotes:&lt;br /&gt;
 &amp;quot;C:\Programs\Battle for Wesnoth 1.8\data\tools\wmllint&amp;quot;&lt;br /&gt;
Remember that you do not need to enter all of the commands/paths at once. If it doesn't work, start with only &amp;quot;python&amp;quot; or &amp;quot;C:\Python26\python.exe&amp;quot; or the like and interpret the error messages that you get. If you get an &amp;quot;unknown command&amp;quot;, python isn't installed or environment variables aren't set correctly. After that, you can add the later commands one by one.&lt;br /&gt;
&lt;br /&gt;
== wmlscope ==&lt;br /&gt;
&lt;br /&gt;
The main use for &amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; is to find WML macro references without definitions and references to resource files (sounds and images) that don't exist.  These are difficult to spot from in-game because they usually result in silence or a missing image rather than actual broken game logic.  They may happen because of typos in your WML, or because the name of a macro or the location of a resource file changed between versions of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; also checks macro invocations for consistency.  It will complain&lt;br /&gt;
if a macro is called with the wrong number of arguments.  In most cases it can deduce information about the type of the literal expected to be passed to a given macro argument by looking at the name of the formal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Meanining&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Formals requiring this type&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Literals of this type&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;side&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a single side number&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;SIDE, *_SIDE, SIDE[0-9]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric or &amp;quot;global&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;numeric&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric integer literal&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;SIDE, X, Y, RED, GREEN, BLUE, TURN, PROB, LAYER, TIME, *_SIDE, *NUMBER, *AMOUNT, *COST, *RADIUS, *_X, *_Y, *_INCREMENT, *_FACTOR, *_TIME, *_SIZE, DURATION&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;\-?[0-9]+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;percentage&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a percentage&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*PERCENTAGE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric or 0\.[0-9]+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;position&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a single x,y coordinate&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;POSITION, *_POSITION, BASE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;-?[0-9]+,-?[0-9]+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;span&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of coordinates or coordinate ranges&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*_SPAN&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a numeric, position or ([0-9]+\-[0-9]+,?|[0-9]+,?)+&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;alliance&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of side numbers&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;SIDES, *_SIDES&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a span, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;range&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;an attack range&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;RANGE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;quot;melee&amp;quot; or &amp;quot;ranged&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;alignment&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;an alignment keyword&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;ALIGN&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;quot;lawful&amp;quot; or &amp;quot;neutral&amp;quot; or &amp;quot;chaotic&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;types&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of unit types&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;TYPES&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname, name, or anything that contains spaces and matches no other type&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;terrain_pattern&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a set of terrain codes to filter&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;ADJACENT*, TERRAINLIST*, *TERRAIN_PATTERN, RESTRICTING&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a terrain_code or name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;terrain_code&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a single terrain code, perhaps with overlay&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;TERRAIN*, *TERRAIN&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname or (\*|[A-Z][a-z]+)\^([A-Z][a-z\\|/]+\Z)?&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;shortname&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a terrain code or a short, capitalized variable name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[A-Z][a-z][a-z]?&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a name or identifier&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;NAME, VAR, IMAGESTEM, ID, FLAG, *_NAME, *_ID, NAMESPACE, BUILDER, *_VAR&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;anything without spaces that matches no other type&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;optional_string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a string value (may be empty)&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;ID_STRING, NAME_STRING, DESCRIPTION, IPF&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a string, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a nonempty string not matching any of the preceding types&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;STRING, TYPE, TEXT, *_STRING, *_TYPE, *_TEXT&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname, a name, a stringliteral, or anything that contains spaces and matches no other type&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;stringliteral&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a string in doublequotes or a translated string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;quot;.*&amp;quot; or _.* but not _[a-z].*&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;image&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;an image path, perhaps with [[ImagePathFunctionWML|image path functions]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*IMAGE, PROFILE&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[A-Za-z0-9{}.][A-Za-z0-9_/+{}.-]*\.(png|jpg)(?=(~.*)?)&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;sound&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a music or sound filename&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;MUSIC, SOUND&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;string ending with &amp;quot;.wav&amp;quot; or &amp;quot;.ogg&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;filter&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;[[FilterWML|WML filter]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;FILTER&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;any non-quoted string containing &amp;quot;=&amp;quot;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;WML&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;arbitrary WML fragment&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;WML, *_WML&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;any non-quoted string containing &amp;quot;=&amp;quot;, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;affix&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a prefix, suffix, or infix for a variable name&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;AFFIX, *AFFIX, POSTFIX, ROTATION&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;a shortname or name, or the empty string&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;any&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;anything&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;*VALUE, [ARS][0-9]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;anything&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the actual argument is a macro call {.*}, then it matches any formal  Otherwise, if the formal has an identifiable type, &amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; will complain if the actual literal does not match it.&lt;br /&gt;
&lt;br /&gt;
The argument type check only works in macro calls that fit on a single line.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt; has many options for changing the reports it generates; the more advanced ones are intended for Wesnoth developers.  Invocations for the most commonly useful reports it generates are included in &amp;lt;i&amp;gt;data/tools/Makefile&amp;lt;/i&amp;gt; of the source distribution. Here are some of those reports:&lt;br /&gt;
&lt;br /&gt;
; make unresolved: Report on unresolved macro calls and resource references; also report macro argument-type mismatches.  (This is what you are most likely to want to do). &lt;br /&gt;
&lt;br /&gt;
; make all: Report all macro and resource file references, not just unresolved ones.&lt;br /&gt;
&lt;br /&gt;
; make collisions: Report on duplicate resource files.&lt;br /&gt;
&lt;br /&gt;
For more advanced users, or those who want to understand what the canned Makefile invocations are doing, here is a summary of &amp;lt;tt&amp;gt;wmlscope&amp;lt;/tt&amp;gt;'s options. Some of the more advanced options will require you to understand &lt;br /&gt;
[http://docs.python.org/lib/re-syntax.html Python regular expressions].&lt;br /&gt;
&lt;br /&gt;
; -h, --help:                 Emit a help message and quit&lt;br /&gt;
; -c, --crossreference:       Report resolved macro references (implies -w 1)&lt;br /&gt;
; -C, --collisions:           Report duplicate resource files   &lt;br /&gt;
; -d, --deflist:              Make definition list.  (This one is for campaign server maintainers.)&lt;br /&gt;
; -e &amp;lt;i&amp;gt;regexp&amp;lt;/i&amp;gt;, --exclude &amp;lt;i&amp;gt;regexp&amp;lt;/i&amp;gt;:   Ignore files matching the specified regular expression. &lt;br /&gt;
; -f &amp;lt;i&amp;gt;dir&amp;lt;/i&amp;gt;, --from &amp;lt;i&amp;gt;dir&amp;lt;/i&amp;gt;:         Report only on macros defined under &amp;lt;i&amp;gt;dir&amp;lt;/i&amp;gt;&lt;br /&gt;
; -l, --listfiles:            List files that will be processed&lt;br /&gt;
; -r &amp;lt;i&amp;gt;ddd&amp;lt;/i&amp;gt;, --refcount=&amp;lt;i&amp;gt;ddd&amp;lt;/i&amp;gt;:     Report only on macros with references in exactly &amp;lt;i&amp;gt;ddd&amp;lt;/i&amp;gt; files.&lt;br /&gt;
; -u, --unresolved:           Report unresolved macro references&lt;br /&gt;
; -w, --warnlevel:            Set to 1 to warn of duplicate macro definitions&lt;br /&gt;
; --force-used reg:          Ignore reference count 0 on names matching regexp&lt;br /&gt;
; --extracthelp:              Extract help from macro definition comments.&lt;br /&gt;
&lt;br /&gt;
== wmllint ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; is a tool for migrating your WML to the current version.  It handles two problems: &lt;br /&gt;
&lt;br /&gt;
* Resource files and macro names may change between versions of the game. &amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; knows about these changes and will tweak your WML to fit where it can.&lt;br /&gt;
&lt;br /&gt;
* Between 1.2.x and 1.3.1 the terrain-coding system used in map files underwent a major change. It changed again in a minor way between 1.3.1 and 1.3.2.  &amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; will translate your maps for you, unless you use custom terrains in which case you will have to do it by hand.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; also performs various sanity-checking operations, reporting:&lt;br /&gt;
&lt;br /&gt;
* unbalanced tags&lt;br /&gt;
* strings that need a translation mark and do not have them&lt;br /&gt;
* strings that have a translation mark and should not&lt;br /&gt;
* translatable strings containing macro references &lt;br /&gt;
* filter references by description= (id= in 1.5) not matched by an actual unit&lt;br /&gt;
* abilities or traits without matching special notes, or vice-versa&lt;br /&gt;
* consistency between recruit= and recruitment_pattern= instances&lt;br /&gt;
* double space after punctuation in translatable strings.&lt;br /&gt;
* unknown races or movement types in units&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;wmllint&amp;lt;/tt&amp;gt; takes a directory-path argument specifying the WML directories to work on.  It will modify any cfg and map files under those directories that need to be changed.  Here is a summary of its options:&lt;br /&gt;
&lt;br /&gt;
; -h, --help:                 Emit a help message and quit.&lt;br /&gt;
; -d, --dryrun:               List changes but don't perform them.&lt;br /&gt;
; -v, --verbose:              Set verbosity; more details below.&lt;br /&gt;
; -c, --clean:                Clean up -bak files.&lt;br /&gt;
; -D, --diff:                 Show diffs between unconverted and unconverted files.&lt;br /&gt;
; -r, --revert:               Revert the conversion from the -bak files.&lt;br /&gt;
; -n, --nolift:               Suppress lifting, do sanity checks only &lt;br /&gt;
&lt;br /&gt;
The verbosity option works like this:&lt;br /&gt;
&lt;br /&gt;
; -v:          lists changes.&lt;br /&gt;
; -v -v:       warns of maps already converted.&lt;br /&gt;
; -v -v -v:    names each file before it's processed.&lt;br /&gt;
; -v -v -v -v: shows verbose parse details (developers only).&lt;br /&gt;
&lt;br /&gt;
The recommended procedure is this:&lt;br /&gt;
&lt;br /&gt;
# Run it with --dryrun first to see what it will do.&lt;br /&gt;
# If the messages look good, run without --dryrun; the old content will be left in backup files with a -bak extension.&lt;br /&gt;
# Eyeball the changes with the --diff option.&lt;br /&gt;
# Use wmlscope, with a directory path including the Wesnoth mainline WML, to check that you have no unresolved references.&lt;br /&gt;
# Test the conversion.&lt;br /&gt;
# Use either --clean to remove the -bak files or --revert to undo the conversion.&lt;br /&gt;
&lt;br /&gt;
Additionally, wmllint tries to locate a spell checker on your system and spell-checks storyline and message strings.  It will work automatically with either aspell, myspell, or ispell provided you have the &amp;lt;tt&amp;gt;enchant.py&amp;lt;/tt&amp;gt; Python library installed.&lt;br /&gt;
&lt;br /&gt;
== wmlindent ==&lt;br /&gt;
&lt;br /&gt;
Call with no arguments to filter WML on standard input to reindented WML on&lt;br /&gt;
standard output.  If arguments are specified, they are taken to be files to be&lt;br /&gt;
re-indented in place; interrupting will be safe, as each reindenting&lt;br /&gt;
will be done to a copy that is atomically renamed when it's done. This&lt;br /&gt;
code never modifies anything but blank lines and leading and trailing whitespace on non-blank lines.&lt;br /&gt;
&lt;br /&gt;
The indent unit is four spaces.  Absence of an option to change this is&lt;br /&gt;
deliberate; the purpose of this tool is to prevent style wars, not encourage&lt;br /&gt;
them.&lt;br /&gt;
&lt;br /&gt;
If you don't apply this tool to your own WML, the mainline-campaign maintainers &lt;br /&gt;
will do it when and if your code is accepted into the tree.&lt;br /&gt;
&lt;br /&gt;
Note: This tool does not include a parser.  It will produce bad results on WML&lt;br /&gt;
that is syntactically unbalanced.  Unbalanced double quotes that aren't part&lt;br /&gt;
of a multiline literal will also confuse it.  You will receive warnings&lt;br /&gt;
if there's an indent open at end of file or if a closer occurs with&lt;br /&gt;
indent already zero; these two conditions strongly suggest unbalanced WML.&lt;br /&gt;
&lt;br /&gt;
== GUI.pyw ==&lt;br /&gt;
&lt;br /&gt;
Starting from version 1.11.15 and 1.13.0, a GUI (written in Tkinter, plus the themed widgets ttk) is available in the same directory as the other tools. To use it, you need to have Python &amp;gt;= 2.7.0. To start it, just double click on the GUI.pyw file. The interface is pretty much self explanatory, and allows you to run wmllint, wmlscope and wmlindent, modify their options, select an add-on, and save the tools' output as a text file.&lt;br /&gt;
&lt;br /&gt;
[[Category:Create]]&lt;br /&gt;
[[Category:Tools]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54696</id>
		<title>ConditionalActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54696"/>
		<updated>2014-04-12T09:05:30Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [switch] */ Reverted variable=, [case] and value= requirement on 1.13&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
Part of [[ActionWML]], Conditional Actions WML is used to describe container actions that create branching and flow control for WML. The [[#Conditional Actions|conditional actions]] act as gatekeepers, encapsulating other actions with [[#Condition Tags|conditions]] which must be met before an action can take place. These conditional actions also contain the actions which will take place if those conditions are met and, in some cases, what actions will take place if they are ''not'' met.&lt;br /&gt;
&lt;br /&gt;
== Conditional Actions ==&lt;br /&gt;
&lt;br /&gt;
These actions describe actions that should be executed only if certain conditions are met.&lt;br /&gt;
&lt;br /&gt;
=== [if] ===&lt;br /&gt;
&lt;br /&gt;
Executes actions only if the contained [[#Condition Tags|conditions]] are met.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[then]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[then]''': Contains [[ActionWML|actions]] which should be executed if all conditions evaluate as true ''or'' if any single '''[or]''' tag evaluates as true.&lt;br /&gt;
&lt;br /&gt;
* '''[elseif]''': {{DevFeature1.13|0}} in case that the conditions inside [if] aren't met, these tags will be evalutated one by one. If the specified conditions are met, the contained [then] tags will be executed, and the cycle will end.&lt;br /&gt;
** '''[then]''': it behaves exactly like the [then] tag inside [if].&lt;br /&gt;
&lt;br /&gt;
* '''[else]''': Contains [[ActionWML|actions]] which should be executed if any condition evaluates as false ''and'' '''all''' of the '''[or]''' tags evaluate as false.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Attention''': There are tags named [if] and [else] inside [animation] (see [[AnimationWML#.5Bif.5D_and_.5Belse.5D|AnimationWML]]), which have a different syntax.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [if]&lt;br /&gt;
     [variable]&lt;br /&gt;
        name=we.gold&lt;br /&gt;
        greater_than=$they.gold&lt;br /&gt;
     [/variable]&lt;br /&gt;
     [then]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This should be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/then]&lt;br /&gt;
     [else]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This will not be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
=== [switch] ===&lt;br /&gt;
&lt;br /&gt;
The '''[switch]''' tag is a special case because it does not use [[#Condition Tags|Condition Tags]] to control whether actions are performed. Instead, it executes different sets of actions based on the value of a variable.&lt;br /&gt;
&lt;br /&gt;
* '''variable''': The name of the variable to check.&lt;br /&gt;
* '''[case]''': Case tag which forms a block containing:&lt;br /&gt;
** '''value''': The value to test the variable's value against. This can be a comma separated list of values.&lt;br /&gt;
** [[ActionWML|Action WML]]: Action WML to execute if the variable matches the value. (The rest of the '''[case]''' block after the '''value''' attribute.)&lt;br /&gt;
* '''[else]''': Else tag which forms a block of [[ActionWML|Action WML]] to execute if no '''[case]''' block contains a '''value''' matching the value of the '''variable'''.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [switch]&lt;br /&gt;
     variable=foo&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;A&amp;quot;&lt;br /&gt;
        ... WML if foo=A ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;B&amp;quot;&lt;br /&gt;
        ... WML if foo=B ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [else]&lt;br /&gt;
        ... WML if not foo=A nor foo=B ...&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/switch]&lt;br /&gt;
&lt;br /&gt;
=== [while] ===&lt;br /&gt;
&lt;br /&gt;
Like the '''[if]''' tag, executes actions only if conditions described in the contained [[#Condition Tags|conditions]] are met. Additionally, the '''[while]''' tag ''continues'' to execute the actions until the contained [[#Condition Tags|conditions]] are no longer met. Executes a maximum of 65536 iterations per invocation.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[do]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[do]''': contains [[ActionWML|actions]] that should be executed repeatedly until some condition is false.&lt;br /&gt;
&lt;br /&gt;
The '''[while]''' tag is useful for iterating over an array.&lt;br /&gt;
An array is a list of values.&lt;br /&gt;
The ''number''th value in the array '''array''' is stored in the WML variable '''''array''[number]'''.&lt;br /&gt;
Note that if '''number''' is the value of the variable '''variable''',&lt;br /&gt;
the expression '''$''array''[$variable]''' will return the ''number''th value in ''array''.&lt;br /&gt;
&lt;br /&gt;
==== 'FOREACH' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to create a ''for-each'' iteration format. This is useful, for example, when you want to iterate over each row in a table. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#FOREACH FOREACH] and [http://www.wesnoth.org/macro-reference.xhtml#NEXT NEXT] macros.&lt;br /&gt;
&lt;br /&gt;
==== 'REPEAT' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to execute the same  [[ActionWML|actions]] repeatedly for a specified number of times. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#REPEAT REPEAT] macro.&lt;br /&gt;
&lt;br /&gt;
=== [command] ===&lt;br /&gt;
&lt;br /&gt;
This tag is more of an Unconditional Action: when it is encountered, the [[ActionWML|actions]] in its content are simply executed once. In practice, this tag serves little purpose. However, it may be used to arrange actions together in logical groups, for example, with actions that are stored in an array and later inserted.&lt;br /&gt;
(It is also used inside of [set_menu_item] and [option] of [[InterfaceActionsWML]].)&lt;br /&gt;
&lt;br /&gt;
== Condition Tags ==&lt;br /&gt;
&lt;br /&gt;
===True Condition Tags===&lt;br /&gt;
These tags describe conditions which must be met before an action can take place. Some or all of them are used in the various [[#Conditional Actions|Conditional Actions]].&lt;br /&gt;
&lt;br /&gt;
; [true]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields true. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [false]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields false. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [have_unit]&lt;br /&gt;
: A unit with greater than zero hit points matching this filter exists.&lt;br /&gt;
:* [[StandardUnitFilter]] '''*''': Selection criteria. Do not use a [filter] tag.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of units equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
:* '''search_recall_list''': ''(Optional)'' If 'yes', search through recall list too. (Default is 'no')&lt;br /&gt;
&lt;br /&gt;
; [have_location]&lt;br /&gt;
: A location matching this filter exists.&lt;br /&gt;
:* [[StandardLocationFilter]]: Selection criteria.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of locations equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; [variable]&lt;br /&gt;
: Test the value of a WML [[VariablesWML|variable]] against another value.&lt;br /&gt;
:* '''name''': The name of the variable to test.&lt;br /&gt;
:* ''&amp;lt;comparison&amp;gt;'': '''One''' of the following keys must be used to compare the value of the named variable, represented as ''$name'' below, against another value:&lt;br /&gt;
:** '''contains''': ''$name'' contains this string value.&lt;br /&gt;
:** '''equals''': ''$name'' is equal (string wise) to this value.&lt;br /&gt;
:** '''not_equals''': ''$name'' is not equal (string wise) to this value.&lt;br /&gt;
:** '''numerical_equals''': ''$name'' is equal (numerically) to this value. &lt;br /&gt;
:** '''numerical_not_equals''': ''$name'' is not equal (numerically) to this value. '''*'''&amp;lt;br /&amp;gt;'''*''' Using equals is faster. The point of numerical_equals and boolean_equals is not performance, it's representation. For instance, &amp;quot;1&amp;quot; and &amp;quot;1.0&amp;quot; are not equal as strings but they are equal as numbers; and &amp;quot;yes&amp;quot; and &amp;quot;true&amp;quot; are not equal as strings but they are equal as booleans. (This also explains why equals is faster: it is a straightforward comparison that doesn't try to understand what you have written.)&lt;br /&gt;
:** '''greater_than''': ''$name'' is greater than this value.&lt;br /&gt;
:** '''greater_than_equal_to''': ''$name'' is greater than or equal to this value.&lt;br /&gt;
:** '''less_than''': ''$name'' is less than this value.&lt;br /&gt;
:** '''less_than_equal_to''': ''$name'' is less than or equal to this value.&lt;br /&gt;
:** '''boolean_equals''': ''$name'' has an equivalent boolean value. '''*'''&lt;br /&gt;
:** '''boolean_not_equals''': ''$name'' does not have an equivalent boolean value. '''*'''&lt;br /&gt;
====Boolean Values====&lt;br /&gt;
When values are evaluated as boolean values they are checked to see if they are ''false'' or ''true''.&lt;br /&gt;
&lt;br /&gt;
* These values are evaluated as ''true'': '''&amp;quot;yes&amp;quot;''' and '''&amp;quot;true&amp;quot;'''&lt;br /&gt;
* These values are evaluated as ''false'': '''&amp;quot;no&amp;quot;''', '''&amp;quot;false&amp;quot;''' and '''&amp;quot;&amp;quot;'''(uninitialized)&lt;br /&gt;
** However, in contexts where ''true'' is defined as the default value, an uninitialized value would be considered true. &lt;br /&gt;
&lt;br /&gt;
'''Warning:''' Do not use &amp;quot;off&amp;quot;, &amp;quot;on&amp;quot;, integers, floating-point numbers or anything else than the above as booleans.&lt;br /&gt;
&lt;br /&gt;
=== Meta-Condition Tags ===&lt;br /&gt;
&lt;br /&gt;
These tags aren't really conditions, themselves. Instead they are wrapped around condition tags to group them into multiple conditions that must all be met, lists of conditions that only one must be met, or conditions that must not be met. These are handled in top-to-bottom order in any combination you can think of. One important thing to remember is if you are using '''[or]''' tags, the first conditional statement should ''not'' have an '''[or]''' tag wrapped around it.&lt;br /&gt;
&lt;br /&gt;
; [and]&lt;br /&gt;
: A condition which must evaluate to true in addition to any other conditions that precede it. This is useful as a bracket for complex conditions, but not strictly necessary.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[and]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
; [or]&lt;br /&gt;
: A condition which, when false, has no effect, but when true, allows previously failed conditions to be ignored. &lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[or]''' tag evaluates to true. &lt;br /&gt;
&lt;br /&gt;
; [not]&lt;br /&gt;
: Similar to [and], but its contents must be false. Thus it reverses the evaluation of its contents. Since a normal condition tag without contents is always considered true, an empty [not] is always considered false.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[not]''' tag evaluates to false. If these evaluate to false, the '''[not]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When multiple meta-conditions are encountered one after another in a containing tag, the evaluation order is as follows:&lt;br /&gt;
# the immediate contents of the containing tag are evaluated first to determine if there is a successful match known as a &amp;quot;true&amp;quot; condition&lt;br /&gt;
# this true or false result is combined with the top meta-condition to produce another true or false result&lt;br /&gt;
# this result is combined with the next meta-condition, and so on. However, if the engine recognizes that no remaining meta-conditions might reverse the result, it will cleverly skip them.&lt;br /&gt;
# if the final result is a successful match, then the [[:Category:ActionsWML|action]] will take place.&lt;br /&gt;
&lt;br /&gt;
For more details on use of meta-conditions, see [[AdvancedConditionalWML|these examples]].&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[VariablesWML]]&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[DirectActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54695</id>
		<title>ConditionalActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54695"/>
		<updated>2014-04-12T09:03:34Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [while] */ Reverted [do] requirement on 1.13&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
Part of [[ActionWML]], Conditional Actions WML is used to describe container actions that create branching and flow control for WML. The [[#Conditional Actions|conditional actions]] act as gatekeepers, encapsulating other actions with [[#Condition Tags|conditions]] which must be met before an action can take place. These conditional actions also contain the actions which will take place if those conditions are met and, in some cases, what actions will take place if they are ''not'' met.&lt;br /&gt;
&lt;br /&gt;
== Conditional Actions ==&lt;br /&gt;
&lt;br /&gt;
These actions describe actions that should be executed only if certain conditions are met.&lt;br /&gt;
&lt;br /&gt;
=== [if] ===&lt;br /&gt;
&lt;br /&gt;
Executes actions only if the contained [[#Condition Tags|conditions]] are met.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[then]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[then]''': Contains [[ActionWML|actions]] which should be executed if all conditions evaluate as true ''or'' if any single '''[or]''' tag evaluates as true.&lt;br /&gt;
&lt;br /&gt;
* '''[elseif]''': {{DevFeature1.13|0}} in case that the conditions inside [if] aren't met, these tags will be evalutated one by one. If the specified conditions are met, the contained [then] tags will be executed, and the cycle will end.&lt;br /&gt;
** '''[then]''': it behaves exactly like the [then] tag inside [if].&lt;br /&gt;
&lt;br /&gt;
* '''[else]''': Contains [[ActionWML|actions]] which should be executed if any condition evaluates as false ''and'' '''all''' of the '''[or]''' tags evaluate as false.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Attention''': There are tags named [if] and [else] inside [animation] (see [[AnimationWML#.5Bif.5D_and_.5Belse.5D|AnimationWML]]), which have a different syntax.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [if]&lt;br /&gt;
     [variable]&lt;br /&gt;
        name=we.gold&lt;br /&gt;
        greater_than=$they.gold&lt;br /&gt;
     [/variable]&lt;br /&gt;
     [then]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This should be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/then]&lt;br /&gt;
     [else]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This will not be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
=== [switch] ===&lt;br /&gt;
&lt;br /&gt;
The '''[switch]''' tag is a special case because it does not use [[#Condition Tags|Condition Tags]] to control whether actions are performed. Instead, it executes different sets of actions based on the value of a variable.&lt;br /&gt;
&lt;br /&gt;
* '''variable''': The name of the variable to check. {{DevFeature1.13|0}} This key is required.&lt;br /&gt;
* '''[case]''': {{DevFeature1.13|0}} At least one [case] is required. On 1.11.x / 1.12.x [case] tags are not required.&amp;lt;br&amp;gt;Case tag which forms a block containing:&lt;br /&gt;
** '''value''': The value to test the variable's value against. This can be a comma separated list of values. {{DevFeature1.13|0}} This key is required.&lt;br /&gt;
** [[ActionWML|Action WML]]: Action WML to execute if the variable matches the value. (The rest of the '''[case]''' block after the '''value''' attribute.)&lt;br /&gt;
* '''[else]''': Else tag which forms a block of [[ActionWML|Action WML]] to execute if no '''[case]''' block contains a '''value''' matching the value of the '''variable'''.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [switch]&lt;br /&gt;
     variable=foo&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;A&amp;quot;&lt;br /&gt;
        ... WML if foo=A ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;B&amp;quot;&lt;br /&gt;
        ... WML if foo=B ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [else]&lt;br /&gt;
        ... WML if not foo=A nor foo=B ...&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/switch]&lt;br /&gt;
&lt;br /&gt;
=== [while] ===&lt;br /&gt;
&lt;br /&gt;
Like the '''[if]''' tag, executes actions only if conditions described in the contained [[#Condition Tags|conditions]] are met. Additionally, the '''[while]''' tag ''continues'' to execute the actions until the contained [[#Condition Tags|conditions]] are no longer met. Executes a maximum of 65536 iterations per invocation.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[do]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[do]''': contains [[ActionWML|actions]] that should be executed repeatedly until some condition is false.&lt;br /&gt;
&lt;br /&gt;
The '''[while]''' tag is useful for iterating over an array.&lt;br /&gt;
An array is a list of values.&lt;br /&gt;
The ''number''th value in the array '''array''' is stored in the WML variable '''''array''[number]'''.&lt;br /&gt;
Note that if '''number''' is the value of the variable '''variable''',&lt;br /&gt;
the expression '''$''array''[$variable]''' will return the ''number''th value in ''array''.&lt;br /&gt;
&lt;br /&gt;
==== 'FOREACH' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to create a ''for-each'' iteration format. This is useful, for example, when you want to iterate over each row in a table. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#FOREACH FOREACH] and [http://www.wesnoth.org/macro-reference.xhtml#NEXT NEXT] macros.&lt;br /&gt;
&lt;br /&gt;
==== 'REPEAT' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to execute the same  [[ActionWML|actions]] repeatedly for a specified number of times. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#REPEAT REPEAT] macro.&lt;br /&gt;
&lt;br /&gt;
=== [command] ===&lt;br /&gt;
&lt;br /&gt;
This tag is more of an Unconditional Action: when it is encountered, the [[ActionWML|actions]] in its content are simply executed once. In practice, this tag serves little purpose. However, it may be used to arrange actions together in logical groups, for example, with actions that are stored in an array and later inserted.&lt;br /&gt;
(It is also used inside of [set_menu_item] and [option] of [[InterfaceActionsWML]].)&lt;br /&gt;
&lt;br /&gt;
== Condition Tags ==&lt;br /&gt;
&lt;br /&gt;
===True Condition Tags===&lt;br /&gt;
These tags describe conditions which must be met before an action can take place. Some or all of them are used in the various [[#Conditional Actions|Conditional Actions]].&lt;br /&gt;
&lt;br /&gt;
; [true]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields true. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [false]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields false. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [have_unit]&lt;br /&gt;
: A unit with greater than zero hit points matching this filter exists.&lt;br /&gt;
:* [[StandardUnitFilter]] '''*''': Selection criteria. Do not use a [filter] tag.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of units equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
:* '''search_recall_list''': ''(Optional)'' If 'yes', search through recall list too. (Default is 'no')&lt;br /&gt;
&lt;br /&gt;
; [have_location]&lt;br /&gt;
: A location matching this filter exists.&lt;br /&gt;
:* [[StandardLocationFilter]]: Selection criteria.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of locations equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; [variable]&lt;br /&gt;
: Test the value of a WML [[VariablesWML|variable]] against another value.&lt;br /&gt;
:* '''name''': The name of the variable to test.&lt;br /&gt;
:* ''&amp;lt;comparison&amp;gt;'': '''One''' of the following keys must be used to compare the value of the named variable, represented as ''$name'' below, against another value:&lt;br /&gt;
:** '''contains''': ''$name'' contains this string value.&lt;br /&gt;
:** '''equals''': ''$name'' is equal (string wise) to this value.&lt;br /&gt;
:** '''not_equals''': ''$name'' is not equal (string wise) to this value.&lt;br /&gt;
:** '''numerical_equals''': ''$name'' is equal (numerically) to this value. &lt;br /&gt;
:** '''numerical_not_equals''': ''$name'' is not equal (numerically) to this value. '''*'''&amp;lt;br /&amp;gt;'''*''' Using equals is faster. The point of numerical_equals and boolean_equals is not performance, it's representation. For instance, &amp;quot;1&amp;quot; and &amp;quot;1.0&amp;quot; are not equal as strings but they are equal as numbers; and &amp;quot;yes&amp;quot; and &amp;quot;true&amp;quot; are not equal as strings but they are equal as booleans. (This also explains why equals is faster: it is a straightforward comparison that doesn't try to understand what you have written.)&lt;br /&gt;
:** '''greater_than''': ''$name'' is greater than this value.&lt;br /&gt;
:** '''greater_than_equal_to''': ''$name'' is greater than or equal to this value.&lt;br /&gt;
:** '''less_than''': ''$name'' is less than this value.&lt;br /&gt;
:** '''less_than_equal_to''': ''$name'' is less than or equal to this value.&lt;br /&gt;
:** '''boolean_equals''': ''$name'' has an equivalent boolean value. '''*'''&lt;br /&gt;
:** '''boolean_not_equals''': ''$name'' does not have an equivalent boolean value. '''*'''&lt;br /&gt;
====Boolean Values====&lt;br /&gt;
When values are evaluated as boolean values they are checked to see if they are ''false'' or ''true''.&lt;br /&gt;
&lt;br /&gt;
* These values are evaluated as ''true'': '''&amp;quot;yes&amp;quot;''' and '''&amp;quot;true&amp;quot;'''&lt;br /&gt;
* These values are evaluated as ''false'': '''&amp;quot;no&amp;quot;''', '''&amp;quot;false&amp;quot;''' and '''&amp;quot;&amp;quot;'''(uninitialized)&lt;br /&gt;
** However, in contexts where ''true'' is defined as the default value, an uninitialized value would be considered true. &lt;br /&gt;
&lt;br /&gt;
'''Warning:''' Do not use &amp;quot;off&amp;quot;, &amp;quot;on&amp;quot;, integers, floating-point numbers or anything else than the above as booleans.&lt;br /&gt;
&lt;br /&gt;
=== Meta-Condition Tags ===&lt;br /&gt;
&lt;br /&gt;
These tags aren't really conditions, themselves. Instead they are wrapped around condition tags to group them into multiple conditions that must all be met, lists of conditions that only one must be met, or conditions that must not be met. These are handled in top-to-bottom order in any combination you can think of. One important thing to remember is if you are using '''[or]''' tags, the first conditional statement should ''not'' have an '''[or]''' tag wrapped around it.&lt;br /&gt;
&lt;br /&gt;
; [and]&lt;br /&gt;
: A condition which must evaluate to true in addition to any other conditions that precede it. This is useful as a bracket for complex conditions, but not strictly necessary.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[and]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
; [or]&lt;br /&gt;
: A condition which, when false, has no effect, but when true, allows previously failed conditions to be ignored. &lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[or]''' tag evaluates to true. &lt;br /&gt;
&lt;br /&gt;
; [not]&lt;br /&gt;
: Similar to [and], but its contents must be false. Thus it reverses the evaluation of its contents. Since a normal condition tag without contents is always considered true, an empty [not] is always considered false.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[not]''' tag evaluates to false. If these evaluate to false, the '''[not]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When multiple meta-conditions are encountered one after another in a containing tag, the evaluation order is as follows:&lt;br /&gt;
# the immediate contents of the containing tag are evaluated first to determine if there is a successful match known as a &amp;quot;true&amp;quot; condition&lt;br /&gt;
# this true or false result is combined with the top meta-condition to produce another true or false result&lt;br /&gt;
# this result is combined with the next meta-condition, and so on. However, if the engine recognizes that no remaining meta-conditions might reverse the result, it will cleverly skip them.&lt;br /&gt;
# if the final result is a successful match, then the [[:Category:ActionsWML|action]] will take place.&lt;br /&gt;
&lt;br /&gt;
For more details on use of meta-conditions, see [[AdvancedConditionalWML|these examples]].&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[VariablesWML]]&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[DirectActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54388</id>
		<title>ConditionalActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54388"/>
		<updated>2014-04-05T09:47:43Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [if] */ Added back support for missing [then] tags&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
Part of [[ActionWML]], Conditional Actions WML is used to describe container actions that create branching and flow control for WML. The [[#Conditional Actions|conditional actions]] act as gatekeepers, encapsulating other actions with [[#Condition Tags|conditions]] which must be met before an action can take place. These conditional actions also contain the actions which will take place if those conditions are met and, in some cases, what actions will take place if they are ''not'' met.&lt;br /&gt;
&lt;br /&gt;
== Conditional Actions ==&lt;br /&gt;
&lt;br /&gt;
These actions describe actions that should be executed only if certain conditions are met.&lt;br /&gt;
&lt;br /&gt;
=== [if] ===&lt;br /&gt;
&lt;br /&gt;
Executes actions only if the contained [[#Condition Tags|conditions]] are met.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[then]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[then]''': Contains [[ActionWML|actions]] which should be executed if all conditions evaluate as true ''or'' if any single '''[or]''' tag evaluates as true.&lt;br /&gt;
&lt;br /&gt;
* '''[elseif]''': {{DevFeature1.13|0}} in case that the conditions inside [if] aren't met, these tags will be evalutated one by one. If the specified conditions are met, the contained [then] tags will be executed, and the cycle will end.&lt;br /&gt;
** '''[then]''': it behaves exactly like the [then] tag inside [if].&lt;br /&gt;
&lt;br /&gt;
* '''[else]''': Contains [[ActionWML|actions]] which should be executed if any condition evaluates as false ''and'' '''all''' of the '''[or]''' tags evaluate as false.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Attention''': There are tags named [if] and [else] inside [animation] (see [[AnimationWML#.5Bif.5D_and_.5Belse.5D|AnimationWML]]), which have a different syntax.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [if]&lt;br /&gt;
     [variable]&lt;br /&gt;
        name=we.gold&lt;br /&gt;
        greater_than=$they.gold&lt;br /&gt;
     [/variable]&lt;br /&gt;
     [then]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This should be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/then]&lt;br /&gt;
     [else]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This will not be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
=== [switch] ===&lt;br /&gt;
&lt;br /&gt;
The '''[switch]''' tag is a special case because it does not use [[#Condition Tags|Condition Tags]] to control whether actions are performed. Instead, it executes different sets of actions based on the value of a variable.&lt;br /&gt;
&lt;br /&gt;
* '''variable''': The name of the variable to check. {{DevFeature1.13|0}} This key is required.&lt;br /&gt;
* '''[case]''': {{DevFeature1.13|0}} At least one [case] is required. On 1.11.x / 1.12.x [case] tags are not required.&amp;lt;br&amp;gt;Case tag which forms a block containing:&lt;br /&gt;
** '''value''': The value to test the variable's value against. This can be a comma separated list of values. {{DevFeature1.13|0}} This key is required.&lt;br /&gt;
** [[ActionWML|Action WML]]: Action WML to execute if the variable matches the value. (The rest of the '''[case]''' block after the '''value''' attribute.)&lt;br /&gt;
* '''[else]''': Else tag which forms a block of [[ActionWML|Action WML]] to execute if no '''[case]''' block contains a '''value''' matching the value of the '''variable'''.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [switch]&lt;br /&gt;
     variable=foo&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;A&amp;quot;&lt;br /&gt;
        ... WML if foo=A ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;B&amp;quot;&lt;br /&gt;
        ... WML if foo=B ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [else]&lt;br /&gt;
        ... WML if not foo=A nor foo=B ...&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/switch]&lt;br /&gt;
&lt;br /&gt;
=== [while] ===&lt;br /&gt;
&lt;br /&gt;
Like the '''[if]''' tag, executes actions only if conditions described in the contained [[#Condition Tags|conditions]] are met. Additionally, the '''[while]''' tag ''continues'' to execute the actions until the contained [[#Condition Tags|conditions]] are no longer met. Executes a maximum of 65536 iterations per invocation.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[do]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[do]''': contains [[ActionWML|actions]] that should be executed repeatedly until some condition is false. {{DevFeature1.13|0}} At least one [do] tag is required.&lt;br /&gt;
&lt;br /&gt;
The '''[while]''' tag is useful for iterating over an array.&lt;br /&gt;
An array is a list of values.&lt;br /&gt;
The ''number''th value in the array '''array''' is stored in the WML variable '''''array''[number]'''.&lt;br /&gt;
Note that if '''number''' is the value of the variable '''variable''',&lt;br /&gt;
the expression '''$''array''[$variable]''' will return the ''number''th value in ''array''.&lt;br /&gt;
&lt;br /&gt;
==== 'FOREACH' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to create a ''for-each'' iteration format. This is useful, for example, when you want to iterate over each row in a table. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#FOREACH FOREACH] and [http://www.wesnoth.org/macro-reference.xhtml#NEXT NEXT] macros.&lt;br /&gt;
&lt;br /&gt;
==== 'REPEAT' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to execute the same  [[ActionWML|actions]] repeatedly for a specified number of times. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#REPEAT REPEAT] macro.&lt;br /&gt;
&lt;br /&gt;
=== [command] ===&lt;br /&gt;
&lt;br /&gt;
This tag is more of an Unconditional Action: when it is encountered, the [[ActionWML|actions]] in its content are simply executed once. In practice, this tag serves little purpose. However, it may be used to arrange actions together in logical groups, for example, with actions that are stored in an array and later inserted.&lt;br /&gt;
(It is also used inside of [set_menu_item] and [option] of [[InterfaceActionsWML]].)&lt;br /&gt;
&lt;br /&gt;
== Condition Tags ==&lt;br /&gt;
&lt;br /&gt;
===True Condition Tags===&lt;br /&gt;
These tags describe conditions which must be met before an action can take place. Some or all of them are used in the various [[#Conditional Actions|Conditional Actions]].&lt;br /&gt;
&lt;br /&gt;
; [true]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields true. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [false]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields false. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [have_unit]&lt;br /&gt;
: A unit with greater than zero hit points matching this filter exists.&lt;br /&gt;
:* [[StandardUnitFilter]] '''*''': Selection criteria. Do not use a [filter] tag.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of units equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
:* '''search_recall_list''': ''(Optional)'' If 'yes', search through recall list too. (Default is 'no')&lt;br /&gt;
&lt;br /&gt;
; [have_location]&lt;br /&gt;
: A location matching this filter exists.&lt;br /&gt;
:* [[StandardLocationFilter]]: Selection criteria.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of locations equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; [variable]&lt;br /&gt;
: Test the value of a WML [[VariablesWML|variable]] against another value.&lt;br /&gt;
:* '''name''': The name of the variable to test.&lt;br /&gt;
:* ''&amp;lt;comparison&amp;gt;'': '''One''' of the following keys must be used to compare the value of the named variable, represented as ''$name'' below, against another value:&lt;br /&gt;
:** '''contains''': ''$name'' contains this string value.&lt;br /&gt;
:** '''equals''': ''$name'' is equal (string wise) to this value.&lt;br /&gt;
:** '''not_equals''': ''$name'' is not equal (string wise) to this value.&lt;br /&gt;
:** '''numerical_equals''': ''$name'' is equal (numerically) to this value. &lt;br /&gt;
:** '''numerical_not_equals''': ''$name'' is not equal (numerically) to this value. '''*'''&amp;lt;br /&amp;gt;'''*''' Using equals is faster. The point of numerical_equals and boolean_equals is not performance, it's representation. For instance, &amp;quot;1&amp;quot; and &amp;quot;1.0&amp;quot; are not equal as strings but they are equal as numbers; and &amp;quot;yes&amp;quot; and &amp;quot;true&amp;quot; are not equal as strings but they are equal as booleans. (This also explains why equals is faster: it is a straightforward comparison that doesn't try to understand what you have written.)&lt;br /&gt;
:** '''greater_than''': ''$name'' is greater than this value.&lt;br /&gt;
:** '''greater_than_equal_to''': ''$name'' is greater than or equal to this value.&lt;br /&gt;
:** '''less_than''': ''$name'' is less than this value.&lt;br /&gt;
:** '''less_than_equal_to''': ''$name'' is less than or equal to this value.&lt;br /&gt;
:** '''boolean_equals''': ''$name'' has an equivalent boolean value. '''*'''&lt;br /&gt;
:** '''boolean_not_equals''': ''$name'' does not have an equivalent boolean value. '''*'''&lt;br /&gt;
====Boolean Values====&lt;br /&gt;
When values are evaluated as boolean values they are checked to see if they are ''false'' or ''true''.&lt;br /&gt;
&lt;br /&gt;
* These values are evaluated as ''true'': '''&amp;quot;yes&amp;quot;''' and '''&amp;quot;true&amp;quot;'''&lt;br /&gt;
* These values are evaluated as ''false'': '''&amp;quot;no&amp;quot;''', '''&amp;quot;false&amp;quot;''' and '''&amp;quot;&amp;quot;'''(uninitialized)&lt;br /&gt;
** However, in contexts where ''true'' is defined as the default value, an uninitialized value would be considered true. &lt;br /&gt;
&lt;br /&gt;
'''Warning:''' Do not use &amp;quot;off&amp;quot;, &amp;quot;on&amp;quot;, integers, floating-point numbers or anything else than the above as booleans.&lt;br /&gt;
&lt;br /&gt;
=== Meta-Condition Tags ===&lt;br /&gt;
&lt;br /&gt;
These tags aren't really conditions, themselves. Instead they are wrapped around condition tags to group them into multiple conditions that must all be met, lists of conditions that only one must be met, or conditions that must not be met. These are handled in top-to-bottom order in any combination you can think of. One important thing to remember is if you are using '''[or]''' tags, the first conditional statement should ''not'' have an '''[or]''' tag wrapped around it.&lt;br /&gt;
&lt;br /&gt;
; [and]&lt;br /&gt;
: A condition which must evaluate to true in addition to any other conditions that precede it. This is useful as a bracket for complex conditions, but not strictly necessary.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[and]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
; [or]&lt;br /&gt;
: A condition which, when false, has no effect, but when true, allows previously failed conditions to be ignored. &lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[or]''' tag evaluates to true. &lt;br /&gt;
&lt;br /&gt;
; [not]&lt;br /&gt;
: Similar to [and], but its contents must be false. Thus it reverses the evaluation of its contents. Since a normal condition tag without contents is always considered true, an empty [not] is always considered false.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[not]''' tag evaluates to false. If these evaluate to false, the '''[not]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When multiple meta-conditions are encountered one after another in a containing tag, the evaluation order is as follows:&lt;br /&gt;
# the immediate contents of the containing tag are evaluated first to determine if there is a successful match known as a &amp;quot;true&amp;quot; condition&lt;br /&gt;
# this true or false result is combined with the top meta-condition to produce another true or false result&lt;br /&gt;
# this result is combined with the next meta-condition, and so on. However, if the engine recognizes that no remaining meta-conditions might reverse the result, it will cleverly skip them.&lt;br /&gt;
# if the final result is a successful match, then the [[:Category:ActionsWML|action]] will take place.&lt;br /&gt;
&lt;br /&gt;
For more details on use of meta-conditions, see [[AdvancedConditionalWML|these examples]].&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[VariablesWML]]&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[DirectActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=IntroWML&amp;diff=54382</id>
		<title>IntroWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=IntroWML&amp;diff=54382"/>
		<updated>2014-04-04T10:08:56Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* The [story] tag */ [elseif] support from 1.13.x&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== The [story] tag ==&lt;br /&gt;
&lt;br /&gt;
The '''[story]''' tag is a series of images and text to display as the first part of the intro screen.&lt;br /&gt;
&lt;br /&gt;
'''[part]''' is a special tag recognized only beneath '''[story]'''. Each '''[part]''' represents one image and text.&lt;br /&gt;
The part is displayed until the user clicks on the &amp;quot;Next&amp;gt;&amp;gt;&amp;gt;&amp;quot; button.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[part]''':&lt;br /&gt;
* '''background''': the image to display. Story images are usually created specially for this purpose, except for the map. In {{DevFeature1.11}}, this key has been deprecated; use '''[background_layer]''' instead.&lt;br /&gt;
* '''scale_background''': Whether to scale the background, default yes. In {{DevFeature1.11}}, this key has been deprecated; use '''[background_layer]''' instead.&lt;br /&gt;
* '''story''': (translatable) the text to display below the image.&lt;br /&gt;
* '''show_title''': whether to display the title of the scenario at the top&lt;br /&gt;
* '''title''': specifies a custom title to display instead of the name of the scenario. If specified, it implies '''show_title=yes'''.&lt;br /&gt;
* '''music''': change to this music&lt;br /&gt;
* '''sound''': a list of sound files; the engine will choose one at random and play it once while displaying the story part.&lt;br /&gt;
* '''[background_layer]''': {{DevFeature1.11}} a layer of the background of the story screen.&lt;br /&gt;
** '''image''': path to the image file.&lt;br /&gt;
** '''scale_vertically''': whether the image should be scaled to fill the screen in the vertical dimension. Default yes.&lt;br /&gt;
** '''scale_horizontally''': whether the image should be scaled to fill the screen in the horizontal dimension. Default yes.&lt;br /&gt;
** '''scale''': a shortcut to set scale_vertically and scale_horizontally at once. If specified, the values of the former two keys will be ignored.&lt;br /&gt;
** '''keep_aspect_ratio''': whether the aspect ratio of the image should be preserved while scaling. Default yes.&lt;br /&gt;
** '''tile_vertically''': whether the image should be tiled in the vertical direction. Tiling happens after aligning the image to the center of the screen. Default no.&lt;br /&gt;
** '''tile_horizontally''': whether the image should be tiled in the horizontal direction. Tiling happens after aligning the image to the center of the screen. Default no.&lt;br /&gt;
** '''tile''': a shortcut to set tile_vertically and tile_horizontally at once. If specified, the values of the former two keys will be ignored.&lt;br /&gt;
** '''base_layer''': whether is this the layer to align the overlay images to. Default no.&lt;br /&gt;
* '''[image]''': an image to display.&lt;br /&gt;
** '''x''', '''y''': the location in pixels to draw the image. The x,y pixel location is relative to the image specified in background, but not in a normal way.  The background image is scaled up or down to fill the screen resolution, but images are never scaled in size.  Their coordinates, however, are scaled.  It's basically a big pain in the rear.  Example: I have a background image at 640x480 and an overlay at 640x480.  To horizontally center the overlay on a 1024x768 screen, I want to position it at x=192.  This is because 1024-640 = 384 total extra pixel space, then 384/2 = 192.  This results in equal space on both sides of the overlay.  However, now you have to account for the background scaling.  The background image at 640 is scaled up to 1024, a scaling factor of 1.6.  All image locations are also scaled up, so the overlay is not drawn at x=192, rather it is drawn at x=192*1.6 or x=307!  To compensate for this, divide the desired pixel location by the scaling factor.  In the example, x_compensated=192/1.6 or x_compensated=120. {{DevFeature1.11}} In version 1.11.2 and later, you can specify which background overlay you want to use as a base for the coordinates. See '''[background_layer]''' for details.&lt;br /&gt;
** '''centered''': If &amp;quot;yes&amp;quot;, use the center of the image when placing at the x,y coordinates, which is useful since this image is not scaled like the background is (and by centering no need to worry about this).&lt;br /&gt;
** '''file''': the image to display.&lt;br /&gt;
** '''delay''': the time to delay drawing this image.&lt;br /&gt;
* '''text_layout''': specifies the area of the screen where the story text will be displayed. It allows the ''top'', ''middle'' and ''bottom'' values; the latter is used by default.&lt;br /&gt;
* '''title_alignment''': specifies the alignment of the title box. It allows the ''left'', ''center'' and ''right'' values; the first is used by default.&lt;br /&gt;
&lt;br /&gt;
The '''[deprecated_message]''', '''[wml_message]''', '''[image]''', and '''[insert_tag]''' tags are allowed beneath '''[story]'''.  Most other WML tags will not be recognized in this context. Note, however, that messages produced by the first two tags will not appear in the game interface until the actual game map appears.&lt;br /&gt;
&lt;br /&gt;
The only other tags currently recognized within '''[story]''' and '''[part]''' are '''[if]'''/'''[then]'''/'''[else]''' ({{DevFeature1.13|0}}: also '''[elseif]''') and '''[switch]'''/'''[case]'''. These can be used to show parts conditionally on the values of variables.&lt;br /&gt;
&lt;br /&gt;
See also the journey and battle macros, in the [http://www.wesnoth.org/macro-reference.xhtml#file:image-utils.cfg Macro Reference]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54381</id>
		<title>ConditionalActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54381"/>
		<updated>2014-04-04T10:07:36Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [while] */ Mandatory [do] from 1.13.x&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
Part of [[ActionWML]], Conditional Actions WML is used to describe container actions that create branching and flow control for WML. The [[#Conditional Actions|conditional actions]] act as gatekeepers, encapsulating other actions with [[#Condition Tags|conditions]] which must be met before an action can take place. These conditional actions also contain the actions which will take place if those conditions are met and, in some cases, what actions will take place if they are ''not'' met.&lt;br /&gt;
&lt;br /&gt;
== Conditional Actions ==&lt;br /&gt;
&lt;br /&gt;
These actions describe actions that should be executed only if certain conditions are met.&lt;br /&gt;
&lt;br /&gt;
=== [if] ===&lt;br /&gt;
&lt;br /&gt;
Executes actions only if the contained [[#Condition Tags|conditions]] are met.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[then]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[then]''': Contains [[ActionWML|actions]] which should be executed if all conditions evaluate as true ''or'' if any single '''[or]''' tag evaluates as true. {{DevFeature1.13|0}} At least one [then] tag is required.&lt;br /&gt;
&lt;br /&gt;
* '''[elseif]''': {{DevFeature1.13|0}} in case that the conditions inside [if] aren't met, these tags will be evalutated one by one. If the specified conditions are met, the contained [then] tags will be executed, and the cycle will end.&lt;br /&gt;
** '''[then]''': it behaves exactly like the [then] tag inside [if]. At least one inside every [elseif] is required.&lt;br /&gt;
&lt;br /&gt;
* '''[else]''': Contains [[ActionWML|actions]] which should be executed if any condition evaluates as false ''and'' '''all''' of the '''[or]''' tags evaluate as false.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Attention''': There are tags named [if] and [else] inside [animation] (see [[AnimationWML#.5Bif.5D_and_.5Belse.5D|AnimationWML]]), which have a different syntax.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [if]&lt;br /&gt;
     [variable]&lt;br /&gt;
        name=we.gold&lt;br /&gt;
        greater_than=$they.gold&lt;br /&gt;
     [/variable]&lt;br /&gt;
     [then]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This should be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/then]&lt;br /&gt;
     [else]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This will not be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
=== [switch] ===&lt;br /&gt;
&lt;br /&gt;
The '''[switch]''' tag is a special case because it does not use [[#Condition Tags|Condition Tags]] to control whether actions are performed. Instead, it executes different sets of actions based on the value of a variable.&lt;br /&gt;
&lt;br /&gt;
* '''variable''': The name of the variable to check. {{DevFeature1.13|0}} This key is required.&lt;br /&gt;
* '''[case]''': {{DevFeature1.13|0}} At least one [case] is required. On 1.11.x / 1.12.x [case] tags are not required.&amp;lt;br&amp;gt;Case tag which forms a block containing:&lt;br /&gt;
** '''value''': The value to test the variable's value against. &lt;br /&gt;
This can be a comma separated list of values. {{DevFeature1.13|0}} This key is required.&lt;br /&gt;
** [[ActionWML|Action WML]]: Action WML to execute if the variable matches the value. (The rest of the '''[case]''' block after the '''value''' attribute.)&lt;br /&gt;
* '''[else]''': Else tag which forms a block of [[ActionWML|Action WML]] to execute if no '''[case]''' block contains a '''value''' matching the value of the '''variable'''.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [switch]&lt;br /&gt;
     variable=foo&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;A&amp;quot;&lt;br /&gt;
        ... WML if foo=A ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;B&amp;quot;&lt;br /&gt;
        ... WML if foo=B ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [else]&lt;br /&gt;
        ... WML if not foo=A nor foo=B ...&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/switch]&lt;br /&gt;
&lt;br /&gt;
=== [while] ===&lt;br /&gt;
&lt;br /&gt;
Like the '''[if]''' tag, executes actions only if conditions described in the contained [[#Condition Tags|conditions]] are met. Additionally, the '''[while]''' tag ''continues'' to execute the actions until the contained [[#Condition Tags|conditions]] are no longer met. Executes a maximum of 65536 iterations per invocation.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[do]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[do]''': contains [[ActionWML|actions]] that should be executed repeatedly until some condition is false. {{DevFeature1.13|0}} At least one [do] tag is required.&lt;br /&gt;
&lt;br /&gt;
The '''[while]''' tag is useful for iterating over an array.&lt;br /&gt;
An array is a list of values.&lt;br /&gt;
The ''number''th value in the array '''array''' is stored in the WML variable '''''array''[number]'''.&lt;br /&gt;
Note that if '''number''' is the value of the variable '''variable''',&lt;br /&gt;
the expression '''$''array''[$variable]''' will return the ''number''th value in ''array''.&lt;br /&gt;
&lt;br /&gt;
==== 'FOREACH' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to create a ''for-each'' iteration format. This is useful, for example, when you want to iterate over each row in a table. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#FOREACH FOREACH] and [http://www.wesnoth.org/macro-reference.xhtml#NEXT NEXT] macros.&lt;br /&gt;
&lt;br /&gt;
==== 'REPEAT' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to execute the same  [[ActionWML|actions]] repeatedly for a specified number of times. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#REPEAT REPEAT] macro.&lt;br /&gt;
&lt;br /&gt;
=== [command] ===&lt;br /&gt;
&lt;br /&gt;
This tag is more of an Unconditional Action: when it is encountered, the [[ActionWML|actions]] in its content are simply executed once. In practice, this tag serves little purpose. However, it may be used to arrange actions together in logical groups, for example, with actions that are stored in an array and later inserted.&lt;br /&gt;
(It is also used inside of [set_menu_item] and [option] of [[InterfaceActionsWML]].)&lt;br /&gt;
&lt;br /&gt;
== Condition Tags ==&lt;br /&gt;
&lt;br /&gt;
===True Condition Tags===&lt;br /&gt;
These tags describe conditions which must be met before an action can take place. Some or all of them are used in the various [[#Conditional Actions|Conditional Actions]].&lt;br /&gt;
&lt;br /&gt;
; [true]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields true. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [false]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields false. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [have_unit]&lt;br /&gt;
: A unit with greater than zero hit points matching this filter exists.&lt;br /&gt;
:* [[StandardUnitFilter]] '''*''': Selection criteria. Do not use a [filter] tag.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of units equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
:* '''search_recall_list''': ''(Optional)'' If 'yes', search through recall list too. (Default is 'no')&lt;br /&gt;
&lt;br /&gt;
; [have_location]&lt;br /&gt;
: A location matching this filter exists.&lt;br /&gt;
:* [[StandardLocationFilter]]: Selection criteria.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of locations equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; [variable]&lt;br /&gt;
: Test the value of a WML [[VariablesWML|variable]] against another value.&lt;br /&gt;
:* '''name''': The name of the variable to test.&lt;br /&gt;
:* ''&amp;lt;comparison&amp;gt;'': '''One''' of the following keys must be used to compare the value of the named variable, represented as ''$name'' below, against another value:&lt;br /&gt;
:** '''contains''': ''$name'' contains this string value.&lt;br /&gt;
:** '''equals''': ''$name'' is equal (string wise) to this value.&lt;br /&gt;
:** '''not_equals''': ''$name'' is not equal (string wise) to this value.&lt;br /&gt;
:** '''numerical_equals''': ''$name'' is equal (numerically) to this value. &lt;br /&gt;
:** '''numerical_not_equals''': ''$name'' is not equal (numerically) to this value. '''*'''&amp;lt;br /&amp;gt;'''*''' Using equals is faster. The point of numerical_equals and boolean_equals is not performance, it's representation. For instance, &amp;quot;1&amp;quot; and &amp;quot;1.0&amp;quot; are not equal as strings but they are equal as numbers; and &amp;quot;yes&amp;quot; and &amp;quot;true&amp;quot; are not equal as strings but they are equal as booleans. (This also explains why equals is faster: it is a straightforward comparison that doesn't try to understand what you have written.)&lt;br /&gt;
:** '''greater_than''': ''$name'' is greater than this value.&lt;br /&gt;
:** '''greater_than_equal_to''': ''$name'' is greater than or equal to this value.&lt;br /&gt;
:** '''less_than''': ''$name'' is less than this value.&lt;br /&gt;
:** '''less_than_equal_to''': ''$name'' is less than or equal to this value.&lt;br /&gt;
:** '''boolean_equals''': ''$name'' has an equivalent boolean value. '''*'''&lt;br /&gt;
:** '''boolean_not_equals''': ''$name'' does not have an equivalent boolean value. '''*'''&lt;br /&gt;
====Boolean Values====&lt;br /&gt;
When values are evaluated as boolean values they are checked to see if they are ''false'' or ''true''.&lt;br /&gt;
&lt;br /&gt;
* These values are evaluated as ''true'': '''&amp;quot;yes&amp;quot;''' and '''&amp;quot;true&amp;quot;'''&lt;br /&gt;
* These values are evaluated as ''false'': '''&amp;quot;no&amp;quot;''', '''&amp;quot;false&amp;quot;''' and '''&amp;quot;&amp;quot;'''(uninitialized)&lt;br /&gt;
** However, in contexts where ''true'' is defined as the default value, an uninitialized value would be considered true. &lt;br /&gt;
&lt;br /&gt;
'''Warning:''' Do not use &amp;quot;off&amp;quot;, &amp;quot;on&amp;quot;, integers, floating-point numbers or anything else than the above as booleans.&lt;br /&gt;
&lt;br /&gt;
=== Meta-Condition Tags ===&lt;br /&gt;
&lt;br /&gt;
These tags aren't really conditions, themselves. Instead they are wrapped around condition tags to group them into multiple conditions that must all be met, lists of conditions that only one must be met, or conditions that must not be met. These are handled in top-to-bottom order in any combination you can think of. One important thing to remember is if you are using '''[or]''' tags, the first conditional statement should ''not'' have an '''[or]''' tag wrapped around it.&lt;br /&gt;
&lt;br /&gt;
; [and]&lt;br /&gt;
: A condition which must evaluate to true in addition to any other conditions that precede it. This is useful as a bracket for complex conditions, but not strictly necessary.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[and]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
; [or]&lt;br /&gt;
: A condition which, when false, has no effect, but when true, allows previously failed conditions to be ignored. &lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[or]''' tag evaluates to true. &lt;br /&gt;
&lt;br /&gt;
; [not]&lt;br /&gt;
: Similar to [and], but its contents must be false. Thus it reverses the evaluation of its contents. Since a normal condition tag without contents is always considered true, an empty [not] is always considered false.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[not]''' tag evaluates to false. If these evaluate to false, the '''[not]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When multiple meta-conditions are encountered one after another in a containing tag, the evaluation order is as follows:&lt;br /&gt;
# the immediate contents of the containing tag are evaluated first to determine if there is a successful match known as a &amp;quot;true&amp;quot; condition&lt;br /&gt;
# this true or false result is combined with the top meta-condition to produce another true or false result&lt;br /&gt;
# this result is combined with the next meta-condition, and so on. However, if the engine recognizes that no remaining meta-conditions might reverse the result, it will cleverly skip them.&lt;br /&gt;
# if the final result is a successful match, then the [[:Category:ActionsWML|action]] will take place.&lt;br /&gt;
&lt;br /&gt;
For more details on use of meta-conditions, see [[AdvancedConditionalWML|these examples]].&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[VariablesWML]]&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[DirectActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54380</id>
		<title>ConditionalActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54380"/>
		<updated>2014-04-04T10:06:33Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [switch] */ Mandatory variable=, [case] and value= from 1.13.x&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
Part of [[ActionWML]], Conditional Actions WML is used to describe container actions that create branching and flow control for WML. The [[#Conditional Actions|conditional actions]] act as gatekeepers, encapsulating other actions with [[#Condition Tags|conditions]] which must be met before an action can take place. These conditional actions also contain the actions which will take place if those conditions are met and, in some cases, what actions will take place if they are ''not'' met.&lt;br /&gt;
&lt;br /&gt;
== Conditional Actions ==&lt;br /&gt;
&lt;br /&gt;
These actions describe actions that should be executed only if certain conditions are met.&lt;br /&gt;
&lt;br /&gt;
=== [if] ===&lt;br /&gt;
&lt;br /&gt;
Executes actions only if the contained [[#Condition Tags|conditions]] are met.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[then]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[then]''': Contains [[ActionWML|actions]] which should be executed if all conditions evaluate as true ''or'' if any single '''[or]''' tag evaluates as true. {{DevFeature1.13|0}} At least one [then] tag is required.&lt;br /&gt;
&lt;br /&gt;
* '''[elseif]''': {{DevFeature1.13|0}} in case that the conditions inside [if] aren't met, these tags will be evalutated one by one. If the specified conditions are met, the contained [then] tags will be executed, and the cycle will end.&lt;br /&gt;
** '''[then]''': it behaves exactly like the [then] tag inside [if]. At least one inside every [elseif] is required.&lt;br /&gt;
&lt;br /&gt;
* '''[else]''': Contains [[ActionWML|actions]] which should be executed if any condition evaluates as false ''and'' '''all''' of the '''[or]''' tags evaluate as false.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Attention''': There are tags named [if] and [else] inside [animation] (see [[AnimationWML#.5Bif.5D_and_.5Belse.5D|AnimationWML]]), which have a different syntax.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [if]&lt;br /&gt;
     [variable]&lt;br /&gt;
        name=we.gold&lt;br /&gt;
        greater_than=$they.gold&lt;br /&gt;
     [/variable]&lt;br /&gt;
     [then]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This should be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/then]&lt;br /&gt;
     [else]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This will not be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
=== [switch] ===&lt;br /&gt;
&lt;br /&gt;
The '''[switch]''' tag is a special case because it does not use [[#Condition Tags|Condition Tags]] to control whether actions are performed. Instead, it executes different sets of actions based on the value of a variable.&lt;br /&gt;
&lt;br /&gt;
* '''variable''': The name of the variable to check. {{DevFeature1.13|0}} This key is required.&lt;br /&gt;
* '''[case]''': {{DevFeature1.13|0}} At least one [case] is required. On 1.11.x / 1.12.x [case] tags are not required.&amp;lt;br&amp;gt;Case tag which forms a block containing:&lt;br /&gt;
** '''value''': The value to test the variable's value against. &lt;br /&gt;
This can be a comma separated list of values. {{DevFeature1.13|0}} This key is required.&lt;br /&gt;
** [[ActionWML|Action WML]]: Action WML to execute if the variable matches the value. (The rest of the '''[case]''' block after the '''value''' attribute.)&lt;br /&gt;
* '''[else]''': Else tag which forms a block of [[ActionWML|Action WML]] to execute if no '''[case]''' block contains a '''value''' matching the value of the '''variable'''.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [switch]&lt;br /&gt;
     variable=foo&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;A&amp;quot;&lt;br /&gt;
        ... WML if foo=A ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;B&amp;quot;&lt;br /&gt;
        ... WML if foo=B ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [else]&lt;br /&gt;
        ... WML if not foo=A nor foo=B ...&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/switch]&lt;br /&gt;
&lt;br /&gt;
=== [while] ===&lt;br /&gt;
&lt;br /&gt;
Like the '''[if]''' tag, executes actions only if conditions described in the contained [[#Condition Tags|conditions]] are met. Additionally, the '''[while]''' tag ''continues'' to execute the actions until the contained [[#Condition Tags|conditions]] are no longer met. Executes a maximum of 65536 iterations per invocation.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[do]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[do]''': contains [[ActionWML|actions]] that should be executed repeatedly until some condition is false.&lt;br /&gt;
&lt;br /&gt;
The '''[while]''' tag is useful for iterating over an array.&lt;br /&gt;
An array is a list of values.&lt;br /&gt;
The ''number''th value in the array '''array''' is stored in the WML variable '''''array''[number]'''.&lt;br /&gt;
Note that if '''number''' is the value of the variable '''variable''',&lt;br /&gt;
the expression '''$''array''[$variable]''' will return the ''number''th value in ''array''.&lt;br /&gt;
&lt;br /&gt;
==== 'FOREACH' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to create a ''for-each'' iteration format. This is useful, for example, when you want to iterate over each row in a table. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#FOREACH FOREACH] and [http://www.wesnoth.org/macro-reference.xhtml#NEXT NEXT] macros.&lt;br /&gt;
&lt;br /&gt;
==== 'REPEAT' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to execute the same  [[ActionWML|actions]] repeatedly for a specified number of times. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#REPEAT REPEAT] macro.&lt;br /&gt;
&lt;br /&gt;
=== [command] ===&lt;br /&gt;
&lt;br /&gt;
This tag is more of an Unconditional Action: when it is encountered, the [[ActionWML|actions]] in its content are simply executed once. In practice, this tag serves little purpose. However, it may be used to arrange actions together in logical groups, for example, with actions that are stored in an array and later inserted.&lt;br /&gt;
(It is also used inside of [set_menu_item] and [option] of [[InterfaceActionsWML]].)&lt;br /&gt;
&lt;br /&gt;
== Condition Tags ==&lt;br /&gt;
&lt;br /&gt;
===True Condition Tags===&lt;br /&gt;
These tags describe conditions which must be met before an action can take place. Some or all of them are used in the various [[#Conditional Actions|Conditional Actions]].&lt;br /&gt;
&lt;br /&gt;
; [true]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields true. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [false]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields false. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [have_unit]&lt;br /&gt;
: A unit with greater than zero hit points matching this filter exists.&lt;br /&gt;
:* [[StandardUnitFilter]] '''*''': Selection criteria. Do not use a [filter] tag.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of units equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
:* '''search_recall_list''': ''(Optional)'' If 'yes', search through recall list too. (Default is 'no')&lt;br /&gt;
&lt;br /&gt;
; [have_location]&lt;br /&gt;
: A location matching this filter exists.&lt;br /&gt;
:* [[StandardLocationFilter]]: Selection criteria.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of locations equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; [variable]&lt;br /&gt;
: Test the value of a WML [[VariablesWML|variable]] against another value.&lt;br /&gt;
:* '''name''': The name of the variable to test.&lt;br /&gt;
:* ''&amp;lt;comparison&amp;gt;'': '''One''' of the following keys must be used to compare the value of the named variable, represented as ''$name'' below, against another value:&lt;br /&gt;
:** '''contains''': ''$name'' contains this string value.&lt;br /&gt;
:** '''equals''': ''$name'' is equal (string wise) to this value.&lt;br /&gt;
:** '''not_equals''': ''$name'' is not equal (string wise) to this value.&lt;br /&gt;
:** '''numerical_equals''': ''$name'' is equal (numerically) to this value. &lt;br /&gt;
:** '''numerical_not_equals''': ''$name'' is not equal (numerically) to this value. '''*'''&amp;lt;br /&amp;gt;'''*''' Using equals is faster. The point of numerical_equals and boolean_equals is not performance, it's representation. For instance, &amp;quot;1&amp;quot; and &amp;quot;1.0&amp;quot; are not equal as strings but they are equal as numbers; and &amp;quot;yes&amp;quot; and &amp;quot;true&amp;quot; are not equal as strings but they are equal as booleans. (This also explains why equals is faster: it is a straightforward comparison that doesn't try to understand what you have written.)&lt;br /&gt;
:** '''greater_than''': ''$name'' is greater than this value.&lt;br /&gt;
:** '''greater_than_equal_to''': ''$name'' is greater than or equal to this value.&lt;br /&gt;
:** '''less_than''': ''$name'' is less than this value.&lt;br /&gt;
:** '''less_than_equal_to''': ''$name'' is less than or equal to this value.&lt;br /&gt;
:** '''boolean_equals''': ''$name'' has an equivalent boolean value. '''*'''&lt;br /&gt;
:** '''boolean_not_equals''': ''$name'' does not have an equivalent boolean value. '''*'''&lt;br /&gt;
====Boolean Values====&lt;br /&gt;
When values are evaluated as boolean values they are checked to see if they are ''false'' or ''true''.&lt;br /&gt;
&lt;br /&gt;
* These values are evaluated as ''true'': '''&amp;quot;yes&amp;quot;''' and '''&amp;quot;true&amp;quot;'''&lt;br /&gt;
* These values are evaluated as ''false'': '''&amp;quot;no&amp;quot;''', '''&amp;quot;false&amp;quot;''' and '''&amp;quot;&amp;quot;'''(uninitialized)&lt;br /&gt;
** However, in contexts where ''true'' is defined as the default value, an uninitialized value would be considered true. &lt;br /&gt;
&lt;br /&gt;
'''Warning:''' Do not use &amp;quot;off&amp;quot;, &amp;quot;on&amp;quot;, integers, floating-point numbers or anything else than the above as booleans.&lt;br /&gt;
&lt;br /&gt;
=== Meta-Condition Tags ===&lt;br /&gt;
&lt;br /&gt;
These tags aren't really conditions, themselves. Instead they are wrapped around condition tags to group them into multiple conditions that must all be met, lists of conditions that only one must be met, or conditions that must not be met. These are handled in top-to-bottom order in any combination you can think of. One important thing to remember is if you are using '''[or]''' tags, the first conditional statement should ''not'' have an '''[or]''' tag wrapped around it.&lt;br /&gt;
&lt;br /&gt;
; [and]&lt;br /&gt;
: A condition which must evaluate to true in addition to any other conditions that precede it. This is useful as a bracket for complex conditions, but not strictly necessary.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[and]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
; [or]&lt;br /&gt;
: A condition which, when false, has no effect, but when true, allows previously failed conditions to be ignored. &lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[or]''' tag evaluates to true. &lt;br /&gt;
&lt;br /&gt;
; [not]&lt;br /&gt;
: Similar to [and], but its contents must be false. Thus it reverses the evaluation of its contents. Since a normal condition tag without contents is always considered true, an empty [not] is always considered false.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[not]''' tag evaluates to false. If these evaluate to false, the '''[not]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When multiple meta-conditions are encountered one after another in a containing tag, the evaluation order is as follows:&lt;br /&gt;
# the immediate contents of the containing tag are evaluated first to determine if there is a successful match known as a &amp;quot;true&amp;quot; condition&lt;br /&gt;
# this true or false result is combined with the top meta-condition to produce another true or false result&lt;br /&gt;
# this result is combined with the next meta-condition, and so on. However, if the engine recognizes that no remaining meta-conditions might reverse the result, it will cleverly skip them.&lt;br /&gt;
# if the final result is a successful match, then the [[:Category:ActionsWML|action]] will take place.&lt;br /&gt;
&lt;br /&gt;
For more details on use of meta-conditions, see [[AdvancedConditionalWML|these examples]].&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[VariablesWML]]&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[DirectActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54379</id>
		<title>ConditionalActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=54379"/>
		<updated>2014-04-04T10:01:59Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [if] */ added [elseif]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
Part of [[ActionWML]], Conditional Actions WML is used to describe container actions that create branching and flow control for WML. The [[#Conditional Actions|conditional actions]] act as gatekeepers, encapsulating other actions with [[#Condition Tags|conditions]] which must be met before an action can take place. These conditional actions also contain the actions which will take place if those conditions are met and, in some cases, what actions will take place if they are ''not'' met.&lt;br /&gt;
&lt;br /&gt;
== Conditional Actions ==&lt;br /&gt;
&lt;br /&gt;
These actions describe actions that should be executed only if certain conditions are met.&lt;br /&gt;
&lt;br /&gt;
=== [if] ===&lt;br /&gt;
&lt;br /&gt;
Executes actions only if the contained [[#Condition Tags|conditions]] are met.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[then]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[then]''': Contains [[ActionWML|actions]] which should be executed if all conditions evaluate as true ''or'' if any single '''[or]''' tag evaluates as true. {{DevFeature1.13|0}} At least one [then] tag is required.&lt;br /&gt;
&lt;br /&gt;
* '''[elseif]''': {{DevFeature1.13|0}} in case that the conditions inside [if] aren't met, these tags will be evalutated one by one. If the specified conditions are met, the contained [then] tags will be executed, and the cycle will end.&lt;br /&gt;
** '''[then]''': it behaves exactly like the [then] tag inside [if]. At least one inside every [elseif] is required.&lt;br /&gt;
&lt;br /&gt;
* '''[else]''': Contains [[ActionWML|actions]] which should be executed if any condition evaluates as false ''and'' '''all''' of the '''[or]''' tags evaluate as false.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Attention''': There are tags named [if] and [else] inside [animation] (see [[AnimationWML#.5Bif.5D_and_.5Belse.5D|AnimationWML]]), which have a different syntax.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [if]&lt;br /&gt;
     [variable]&lt;br /&gt;
        name=we.gold&lt;br /&gt;
        greater_than=$they.gold&lt;br /&gt;
     [/variable]&lt;br /&gt;
     [then]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This should be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/then]&lt;br /&gt;
     [else]&lt;br /&gt;
        [message]&lt;br /&gt;
           message=This will not be easy!&lt;br /&gt;
        [/message]&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/if]&lt;br /&gt;
&lt;br /&gt;
=== [switch] ===&lt;br /&gt;
&lt;br /&gt;
The '''[switch]''' tag is a special case because it does not use [[#Condition Tags|Condition Tags]] to control whether actions are performed. Instead, it executes different sets of actions based on the value of a variable.&lt;br /&gt;
&lt;br /&gt;
* '''variable''': The name of the variable to check.&lt;br /&gt;
* '''[case]''': Case tag which forms a block containing:&lt;br /&gt;
** '''value''': The value to test the variable's value against. &lt;br /&gt;
This can be a comma separated list of values.&lt;br /&gt;
** [[ActionWML|Action WML]]: Action WML to execute if the variable matches the value. (The rest of the '''[case]''' block after the '''value''' attribute.)&lt;br /&gt;
* '''[else]''': Else tag which forms a block of [[ActionWML|Action WML]] to execute if no '''[case]''' block contains a '''value''' matching the value of the '''variable'''.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [switch]&lt;br /&gt;
     variable=foo&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;A&amp;quot;&lt;br /&gt;
        ... WML if foo=A ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;B&amp;quot;&lt;br /&gt;
        ... WML if foo=B ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [else]&lt;br /&gt;
        ... WML if not foo=A nor foo=B ...&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/switch]&lt;br /&gt;
&lt;br /&gt;
=== [while] ===&lt;br /&gt;
&lt;br /&gt;
Like the '''[if]''' tag, executes actions only if conditions described in the contained [[#Condition Tags|conditions]] are met. Additionally, the '''[while]''' tag ''continues'' to execute the actions until the contained [[#Condition Tags|conditions]] are no longer met. Executes a maximum of 65536 iterations per invocation.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[do]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[do]''': contains [[ActionWML|actions]] that should be executed repeatedly until some condition is false.&lt;br /&gt;
&lt;br /&gt;
The '''[while]''' tag is useful for iterating over an array.&lt;br /&gt;
An array is a list of values.&lt;br /&gt;
The ''number''th value in the array '''array''' is stored in the WML variable '''''array''[number]'''.&lt;br /&gt;
Note that if '''number''' is the value of the variable '''variable''',&lt;br /&gt;
the expression '''$''array''[$variable]''' will return the ''number''th value in ''array''.&lt;br /&gt;
&lt;br /&gt;
==== 'FOREACH' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to create a ''for-each'' iteration format. This is useful, for example, when you want to iterate over each row in a table. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#FOREACH FOREACH] and [http://www.wesnoth.org/macro-reference.xhtml#NEXT NEXT] macros.&lt;br /&gt;
&lt;br /&gt;
==== 'REPEAT' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to execute the same  [[ActionWML|actions]] repeatedly for a specified number of times. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#REPEAT REPEAT] macro.&lt;br /&gt;
&lt;br /&gt;
=== [command] ===&lt;br /&gt;
&lt;br /&gt;
This tag is more of an Unconditional Action: when it is encountered, the [[ActionWML|actions]] in its content are simply executed once. In practice, this tag serves little purpose. However, it may be used to arrange actions together in logical groups, for example, with actions that are stored in an array and later inserted.&lt;br /&gt;
(It is also used inside of [set_menu_item] and [option] of [[InterfaceActionsWML]].)&lt;br /&gt;
&lt;br /&gt;
== Condition Tags ==&lt;br /&gt;
&lt;br /&gt;
===True Condition Tags===&lt;br /&gt;
These tags describe conditions which must be met before an action can take place. Some or all of them are used in the various [[#Conditional Actions|Conditional Actions]].&lt;br /&gt;
&lt;br /&gt;
; [true]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields true. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [false]&lt;br /&gt;
: {{DevFeature1.11|10}} Represents a condition that always yields false. Takes no arguments.&lt;br /&gt;
&lt;br /&gt;
; [have_unit]&lt;br /&gt;
: A unit with greater than zero hit points matching this filter exists.&lt;br /&gt;
:* [[StandardUnitFilter]] '''*''': Selection criteria. Do not use a [filter] tag.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of units equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
:* '''search_recall_list''': ''(Optional)'' If 'yes', search through recall list too. (Default is 'no')&lt;br /&gt;
&lt;br /&gt;
; [have_location]&lt;br /&gt;
: A location matching this filter exists.&lt;br /&gt;
:* [[StandardLocationFilter]]: Selection criteria.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of locations equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; [variable]&lt;br /&gt;
: Test the value of a WML [[VariablesWML|variable]] against another value.&lt;br /&gt;
:* '''name''': The name of the variable to test.&lt;br /&gt;
:* ''&amp;lt;comparison&amp;gt;'': '''One''' of the following keys must be used to compare the value of the named variable, represented as ''$name'' below, against another value:&lt;br /&gt;
:** '''contains''': ''$name'' contains this string value.&lt;br /&gt;
:** '''equals''': ''$name'' is equal (string wise) to this value.&lt;br /&gt;
:** '''not_equals''': ''$name'' is not equal (string wise) to this value.&lt;br /&gt;
:** '''numerical_equals''': ''$name'' is equal (numerically) to this value. &lt;br /&gt;
:** '''numerical_not_equals''': ''$name'' is not equal (numerically) to this value. '''*'''&amp;lt;br /&amp;gt;'''*''' Using equals is faster. The point of numerical_equals and boolean_equals is not performance, it's representation. For instance, &amp;quot;1&amp;quot; and &amp;quot;1.0&amp;quot; are not equal as strings but they are equal as numbers; and &amp;quot;yes&amp;quot; and &amp;quot;true&amp;quot; are not equal as strings but they are equal as booleans. (This also explains why equals is faster: it is a straightforward comparison that doesn't try to understand what you have written.)&lt;br /&gt;
:** '''greater_than''': ''$name'' is greater than this value.&lt;br /&gt;
:** '''greater_than_equal_to''': ''$name'' is greater than or equal to this value.&lt;br /&gt;
:** '''less_than''': ''$name'' is less than this value.&lt;br /&gt;
:** '''less_than_equal_to''': ''$name'' is less than or equal to this value.&lt;br /&gt;
:** '''boolean_equals''': ''$name'' has an equivalent boolean value. '''*'''&lt;br /&gt;
:** '''boolean_not_equals''': ''$name'' does not have an equivalent boolean value. '''*'''&lt;br /&gt;
====Boolean Values====&lt;br /&gt;
When values are evaluated as boolean values they are checked to see if they are ''false'' or ''true''.&lt;br /&gt;
&lt;br /&gt;
* These values are evaluated as ''true'': '''&amp;quot;yes&amp;quot;''' and '''&amp;quot;true&amp;quot;'''&lt;br /&gt;
* These values are evaluated as ''false'': '''&amp;quot;no&amp;quot;''', '''&amp;quot;false&amp;quot;''' and '''&amp;quot;&amp;quot;'''(uninitialized)&lt;br /&gt;
** However, in contexts where ''true'' is defined as the default value, an uninitialized value would be considered true. &lt;br /&gt;
&lt;br /&gt;
'''Warning:''' Do not use &amp;quot;off&amp;quot;, &amp;quot;on&amp;quot;, integers, floating-point numbers or anything else than the above as booleans.&lt;br /&gt;
&lt;br /&gt;
=== Meta-Condition Tags ===&lt;br /&gt;
&lt;br /&gt;
These tags aren't really conditions, themselves. Instead they are wrapped around condition tags to group them into multiple conditions that must all be met, lists of conditions that only one must be met, or conditions that must not be met. These are handled in top-to-bottom order in any combination you can think of. One important thing to remember is if you are using '''[or]''' tags, the first conditional statement should ''not'' have an '''[or]''' tag wrapped around it.&lt;br /&gt;
&lt;br /&gt;
; [and]&lt;br /&gt;
: A condition which must evaluate to true in addition to any other conditions that precede it. This is useful as a bracket for complex conditions, but not strictly necessary.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[and]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
; [or]&lt;br /&gt;
: A condition which, when false, has no effect, but when true, allows previously failed conditions to be ignored. &lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[or]''' tag evaluates to true. &lt;br /&gt;
&lt;br /&gt;
; [not]&lt;br /&gt;
: Similar to [and], but its contents must be false. Thus it reverses the evaluation of its contents. Since a normal condition tag without contents is always considered true, an empty [not] is always considered false.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[not]''' tag evaluates to false. If these evaluate to false, the '''[not]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When multiple meta-conditions are encountered one after another in a containing tag, the evaluation order is as follows:&lt;br /&gt;
# the immediate contents of the containing tag are evaluated first to determine if there is a successful match known as a &amp;quot;true&amp;quot; condition&lt;br /&gt;
# this true or false result is combined with the top meta-condition to produce another true or false result&lt;br /&gt;
# this result is combined with the next meta-condition, and so on. However, if the engine recognizes that no remaining meta-conditions might reverse the result, it will cleverly skip them.&lt;br /&gt;
# if the final result is a successful match, then the [[:Category:ActionsWML|action]] will take place.&lt;br /&gt;
&lt;br /&gt;
For more details on use of meta-conditions, see [[AdvancedConditionalWML|these examples]].&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[VariablesWML]]&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[DirectActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=51413</id>
		<title>DirectActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=51413"/>
		<updated>2013-06-16T15:29:23Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [harm_unit] */ Modifications to animate= and fire_event= for 1.11&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== Direct actions ==&lt;br /&gt;
&lt;br /&gt;
Direct actions are actions that have a direct effect on gameplay. They can be used inside of [[EventWML|events]].&lt;br /&gt;
&lt;br /&gt;
The following tags are actions:&lt;br /&gt;
&lt;br /&gt;
=== [endlevel] ===&lt;br /&gt;
Ends the scenario.&lt;br /&gt;
* '''result''': before the scenario is over, all events with ''name=result'' are triggered. If ''result=victory'', the player progresses to the next level (i.e., the next scenario in single player); if ''result=defeat'', the game returns to the main menu. &lt;br /&gt;
&lt;br /&gt;
When the result is &amp;quot;victory&amp;quot; the following keys can be used:&lt;br /&gt;
* '''bonus''': whether the player should get bonus gold (maximum possible gold that could have been earned by waiting the level out). The default is bonus=yes.&lt;br /&gt;
* '''carryover_report''': whether the player should receive a summary of the scenario outcome, the default is carryover_report=yes.&lt;br /&gt;
* '''save''': whether a start-of-scenario save should be created for the next scenario, the default is save=yes. Do not confuse this with saving of replays for the current scenario.&lt;br /&gt;
* '''replay_save''': whether a replay save for the current scenario is allowed, the default is replay_save=yes. If yes, the player's settings in preferences will be used to determine if a replay is saved. If no, will override and not save a replay.&lt;br /&gt;
* '''linger_mode''': If ...=yes, the screen is greyed out and there's the possibility to save before advancing to the next scenario, the default is linger_mode=yes.&lt;br /&gt;
* '''reveal_map''': (Multiplayer only) (Default is 'yes') If 'no', shroud doesn't disappear when game ended.&lt;br /&gt;
* '''next_scenario''': (default specified in '''[scenario]''' tag) the ID of the next scenario that should be played.  All units that side 1 controls at this point become available for recall in ''next_scenario''.&lt;br /&gt;
* '''carryover_percentage''': by default 80% of the gold is carried over to the next scenario, with this key the amount can be changed.&lt;br /&gt;
* '''carryover_add''': if true the gold will be added to the starting gold the next scenario, if false the next scenario will start with the amount of the current scenario (after taxes) or the minimum in the next scenario. Default is false.&lt;br /&gt;
* '''music''': (default specified in '''[scenario]''' or '''[game_config]''' tags) a comma-separated list of music tracks from which one will be chosen and played once after any events related to the end of level result are executed; by default, victory_music is used on victory, and defeat_music on defeat.&lt;br /&gt;
* '''end_credits''': {{DevFeature1.11}} Whether to display the credits screen at the end of a single-player campaign. Defaults to ''yes''. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text''': (translatable) Text that is shown centered in a black screen at the end of a campaign. Defaults to &amp;quot;The End&amp;quot;. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
* '''end_text_duration''': Delay, in milliseconds, before displaying the game credits at the end of a campaign. In other words, for how much time '''end_text''' is displayed on screen. Defaults to 3500. Note that this has cumulative effects over the campaign - it persists even if the endlevel does not trigger the end of the campaign. See also [[CampaignWML]].&lt;br /&gt;
&lt;br /&gt;
=== [unit] ===&lt;br /&gt;
Places a unit on the map.  For syntax see [[SingleUnitWML]].&lt;br /&gt;
* {{Short Note:Predefined Macro|GENERIC_UNIT}}&lt;br /&gt;
* '''to_variable''':  spawn directly into a variable instead of on the map.&lt;br /&gt;
&lt;br /&gt;
=== [recall] ===&lt;br /&gt;
Recalls a unit.  The unit is recalled free of charge, and is placed near the leader.&lt;br /&gt;
* [[StandardUnitFilter]]: the first matching unit will be recalled.  If no units match this tag is ignored. Do not use a [filter] tag. If a comma separated list is given, every unit currently considered for recall is checked against all the types (not each single one of the types against all units).&lt;br /&gt;
* '''x,y''': the unit is placed here instead of next to the leader.&lt;br /&gt;
* '''show''': yes/no, default yes: whether the unit is animated (faded in) or instantly displayed&lt;br /&gt;
* '''fire_event''': boolean yes|no (default no); whether any according prerecall or recall events shall be fired.&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit (a nearby passable hex is chosen).&lt;br /&gt;
&lt;br /&gt;
=== [teleport] ===&lt;br /&gt;
Teleports a unit on map. {{Short Note:Predefined Macro|TELEPORT_UNIT}}&lt;br /&gt;
* '''[filter]''': [[StandardUnitFilter]] the first unit matching this filter will be teleported.&lt;br /&gt;
* '''x,y''': the position to teleport to.&lt;br /&gt;
* '''clear_shroud''': should shroud be cleared on arrival&lt;br /&gt;
* '''animate''': should a teleport animation be played (if the unit doesn't have a teleport animation, it will fade out/fade in)&lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): normally, units will not be teleported into terrain that is impassable for them. Setting this attribute to &amp;quot;no&amp;quot; permits it.&lt;br /&gt;
&lt;br /&gt;
(Note: There is also a ability named teleport, see [[AbilitiesWML]].)&lt;br /&gt;
&lt;br /&gt;
=== [terrain_mask] ===&lt;br /&gt;
Changes the terrain on the map.  See [[TerrainMaskWML]].&lt;br /&gt;
&lt;br /&gt;
=== [terrain] ===&lt;br /&gt;
Changes the terrain on the map.&lt;br /&gt;
* '''terrain''': the character of the terrain to use.  See [[TerrainCodesWML]] to see what letter a type of terrain uses.&lt;br /&gt;
* [[StandardLocationFilter]]. This [[StandardLocationFilter]]'s terrain= key is used for the new terrain, filtering by terrain can be done with a nested [[StandardLocationFilter]]: [and]terrain=terrain_string_to_be_filtered_for.&lt;br /&gt;
* '''layer''': (overlay|base|both, default=both) only change the specified layer.&lt;br /&gt;
* '''replace_if_failed''': (default=no) When replacing just one layer failed, try to replace the whole terrain. If '''terrain''' is an overlay only terrain, use the default_base as base layer. If the terrain has no default base, do nothing.&lt;br /&gt;
Note: When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages it that there are too many choices to make; should a unit loose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [gold] ===&lt;br /&gt;
Gives sides gold.&lt;br /&gt;
* '''amount''': the amount of gold to give.&lt;br /&gt;
* '''side''': (default=1) the number of the side to give the gold to. Can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument {{DevFeature1.11}}: [gold][filter_side] is deprecated, use the new inline SSF.&lt;br /&gt;
&lt;br /&gt;
=== [unstore_unit] ===&lt;br /&gt;
Creates a unit from a game variable, and activates it on the playing field.  This must be a specific variable describing a unit, and may not be an array -- to unstore an entire array, iterate over it.  The variable is not cleared.  See also [[InternalActionsWML#.5Bstore_unit.5D|[store_unit]]], [[ConditionalActionsWML#.5Bwhile.5D|[while]]] and [[InternalActionsWML#.5Bclear_variable.5D|[clear_variable]]].&lt;br /&gt;
* '''variable''': the name of the variable.&lt;br /&gt;
* '''find_vacant''': whether the unit should be placed on the nearest vacant tile to its specified location.  If this is set to 'no'(default), then any unit on the same tile as the unit being unstored will be destroyed. &lt;br /&gt;
* '''check_passability''': (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit. This key has no effect if find_vacant=no (no check performed then). Before 1.9 this key is always &amp;quot;no&amp;quot;.&lt;br /&gt;
* '''text''': (translatable) floating text to display above the unit, such as a damage amount&lt;br /&gt;
* '''red''', '''green''', '''blue''': (default=0,0,0) the color to display the text in. Values vary from 0-255. You may find it convenient to use the {COLOR_HARM} or {COLOR_HEAL} macro instead. (Use {COLOR_HARM} or {COLOR_HEAL} instead of the whole red,green,blue= line.)&lt;br /&gt;
* '''advance''': (default=true) if true the unit is advanced if it has enough XP. When modifying XP make sure to do it from inside a [[EventWML#Multiplayer_safety|synchronized event]] or it may lead to OOS errors especially when several advancement paths exist. Note that advance and post advance events are called, so infinite loops can happen.&lt;br /&gt;
* '''fire_event''': (boolean yes|no, default no) Whether any advance/post advance events shall be fired if an advancement takes place, no effect otherwise.&lt;br /&gt;
* '''animate''': {{DevFeature1.11}} (boolean yes|no, default yes) Whether &amp;quot;levelout&amp;quot; and &amp;quot;levelin&amp;quot; (or fade to white and back) animations shall be played if an advancement takes place, no effect otherwise.&lt;br /&gt;
* '''x''' ,'''y''': override unit location, &amp;quot;x,y=recall,recall&amp;quot; will put the unit on the unit's side's recall list.&lt;br /&gt;
Units can be unstored with negative (or zero) hit points. This can be useful if modifying a unit in its last_breath event (as the unit's death is already the next step), but tends to look wrong in other cases. In particular, it is possible to have units with negative hit points in play. Such units are aberrations, subject to unusual behavior as the game compensates for them. (For example, such units are currently automatically hit&amp;amp;ndash;and killed&amp;amp;ndash;in combat.) The details of the unusual behavior are subject to change between stable releases without warning.&lt;br /&gt;
&lt;br /&gt;
=== [allow_recruit] ===&lt;br /&gt;
Allows a side to recruit units it couldn't previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that is being allowed to recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [allow_extra_recruit] ===&lt;br /&gt;
Allows a leader to recruit units it couldn't previously recruit.&lt;br /&gt;
These types add to the types the leader can recruit because of [side]recruit=.&lt;br /&gt;
* '''extra_recruit''': the types of units that the unit can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_recruit] ===&lt;br /&gt;
Prevents a side from recruiting units it could previously recruit.&lt;br /&gt;
* '''type''': the types of units that the side can no longer recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that may no longer recruit the units. This can be a comma-separated list note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_extra_recruit] ===&lt;br /&gt;
Prevents a leader from recruiting units it could previously recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the side can no longer recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [set_recruit] ===&lt;br /&gt;
Sets the units a side can recruit.&lt;br /&gt;
* '''recruit''': the types of units that the side can now recruit.&lt;br /&gt;
* '''side''': (default=1) the number of the side that is having its recruitment set. This can be a comma-separated list. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
&lt;br /&gt;
=== [set_extra_recruit] === &lt;br /&gt;
Sets the units a leader can recruit.&lt;br /&gt;
* '''extra_recruit''': the types of units that the leader can now recruit.&lt;br /&gt;
* '''[[StandardUnitFilter]]''': All units matching this filter are modified. Does not match on recall list units.&lt;br /&gt;
&lt;br /&gt;
=== [modify_side] ===&lt;br /&gt;
Modifies some details of a given side in the middle of a scenario.  '''The following listed properties are the only properties that [modify_side] can affect!'''&lt;br /&gt;
* '''side''': (default=1) the number of the side that is to be changed. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* '''income''': the income given at the begining of each turn.&lt;br /&gt;
* '''recruit''': a list of unit types, replacing the side's current recruitment list.&lt;br /&gt;
* '''team_name''': the team in which the side plays the scenario.&lt;br /&gt;
* '''user_team_name''': a translatable string representing the team's description. This has no effect on alliances. Defaults to ''team_name''.&lt;br /&gt;
* '''gold''': the amount of gold the side owns.&lt;br /&gt;
* '''village_gold''': the income setting per village for the side.&lt;br /&gt;
* '''controller''': the identifier string of the side's controller. Uses the same syntax of the ''controller'' key in the [[SideWML|[side]]] tag.&lt;br /&gt;
* '''fog''': a boolean string (yes/no) describing the status of Fog for the side.&lt;br /&gt;
* '''shroud''': a boolean string describing the status of Shroud for the side.&lt;br /&gt;
* '''hidden''': a boolean string specifying whether side is shown in status table.&lt;br /&gt;
* '''color''': {{DevFeature1.11}} a team color range specification, name (e.g. &amp;quot;red&amp;quot;, &amp;quot;blue&amp;quot;), or number (e.g. &amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;) for this side. The default color range names, numbers, and definitions can be found in data/core/team_colors.cfg.&lt;br /&gt;
* '''[ai]''': replaces a side's AI parameters with the new specified ones. Uses the same syntax described in [[AiWML]].  Note that [modify_side][ai] works for all simple AI parameters and some, but not all of the more complex ones. If in doubt, use [http://wiki.wesnoth.org/AiWML#Adding_and_Deleting_Aspects_with_the_.5Bmodify_ai.5D_Tag [modify_ai]] instead, which always works.&lt;br /&gt;
* '''switch_ai''': replaces a side ai with a new AI from specified file(ignoring those AI parameters above). Path to file follows the usual WML convention.&lt;br /&gt;
* '''reset_maps''': {{DevFeature1.11}} If set to &amp;quot;yes&amp;quot;, then the shroud is spread to all hexes, covering the parts of the map that had already been explored by the side, including hexes currently seen. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if shroud is on, but this is evaluated after shroud= (and before shroud_data=).&lt;br /&gt;
* '''reset_view''': {{DevFeature1.11}} If set to &amp;quot;yes&amp;quot;, then the fog of war is spread to all hexes, covering the parts of the map that had already been seen this turn by the side, including hexes currently seen, excluding hexes affected by multi-turn {{tag|DirectActionsWML|lift_fog}}. (Seen hexes will be cleared at the end of most events; they can also be manually cleared with {{tag|InterfaceActionsWML|redraw}}.) This is only effective if fog is on, but this is evaluated after fog=.&lt;br /&gt;
* '''share_maps''': change the share_maps side attribute. Be sure to use shroud=yes for that side and have it as an ally&lt;br /&gt;
* '''share_view''': change the share_view side attribute. Be sure to use fog=yes for that side and have it as an ally&lt;br /&gt;
* '''shroud_data''': changes to the side's shroud, using the same format as when defining the [side].&lt;br /&gt;
* '''suppress_end_turn_confirmation''': {{DevFeature1.11}} Boolean value controlling whether or not a player is asked for confirmation when skipping a turn.&lt;br /&gt;
&lt;br /&gt;
=== [modify_turns] ===&lt;br /&gt;
Modifies the turn limit in the middle of a scenario.&lt;br /&gt;
* '''value''': the new turn limit.&lt;br /&gt;
* '''add''': if used instead of ''value'', specifies the number of turns to add to the current limit (can be negative).&lt;br /&gt;
* '''current''': changes the current turn number after applying turn limit modifications, if any. It is not possible to change the turn number to exceed the turn limit (1 &amp;lt;= current turns &amp;lt;= max turns).&lt;br /&gt;
&lt;br /&gt;
=== [allow_end_turn] ===&lt;br /&gt;
Allows human players to end their turn through the user interface if they were previously affected by the '''[disallow_end_turn]''' action. This action doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
=== [disallow_end_turn] ===&lt;br /&gt;
Disallows human players to end their turn through the user interface. This action doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' on Wesnoth versions prior to 1.10.6, there are two bugs affecting this WML action. First, its effect was lost when reloading from a saved game ([https://gna.org/bugs/?20350 bug #20350]); second, its effect persisted when advancing scenarios in a campaign ([https://gna.org/bugs/?20351 bug #20351]).&lt;br /&gt;
&lt;br /&gt;
A known workaround for both issues would be to use [[PreprocessorRef#.23ifver_and_.23ifnver|#ifver]]-based preprocessor macros to include additional code for Wesnoth 1.10.5 and earlier taking advantage of unique ''preload'', ''victory'', and ''defeat'' [[EventWML|event handlers]], such as the following:&lt;br /&gt;
&lt;br /&gt;
 #ifver WESNOTH_VERSION &amp;gt; 1.10.5&lt;br /&gt;
 &lt;br /&gt;
 #define DISALLOW_END_TURN&lt;br /&gt;
     [disallow_end_turn][/disallow_end_turn]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #define ALLOW_END_TURN&lt;br /&gt;
     [allow_end_turn][/allow_end_turn]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #else&lt;br /&gt;
 &lt;br /&gt;
 #define DISALLOW_END_TURN&lt;br /&gt;
     [disallow_end_turn][/disallow_end_turn]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20350_workaround&lt;br /&gt;
         name=preload&lt;br /&gt;
 &lt;br /&gt;
         [disallow_end_turn][/disallow_end_turn]&lt;br /&gt;
     [/event]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20351_workaround&lt;br /&gt;
         name=victory,defeat&lt;br /&gt;
 &lt;br /&gt;
         [allow_end_turn][/allow_end_turn]&lt;br /&gt;
     [/event]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #define ALLOW_END_TURN&lt;br /&gt;
     [allow_end_turn][/allow_end_turn]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20350_workaround&lt;br /&gt;
         remove=yes&lt;br /&gt;
     [/event]&lt;br /&gt;
 &lt;br /&gt;
     [event]&lt;br /&gt;
         id=bug_20351_workaround&lt;br /&gt;
         remove=yes&lt;br /&gt;
     [/event]&lt;br /&gt;
 #enddef&lt;br /&gt;
 &lt;br /&gt;
 #endif&lt;br /&gt;
&lt;br /&gt;
=== [capture_village] ===&lt;br /&gt;
Changes the ownership of a village.&lt;br /&gt;
* [[StandardLocationFilter]]: all village locations matching the filter are affected.&lt;br /&gt;
* '''side''': the side that takes control of the village. This side needs to have a leader (canrecruit=yes). If the side key is not given, the village will become neutral (unless [filter_side] is present, in which case that side fiter decides, see below).&lt;br /&gt;
* '''[filter_side]''' with [[StandardSideFilter]] tags and keys as arguments; if both this tag and inline side= are present it's an error. Otherwise, the first matching side gets ownership (or the village becomes neutral if none match).&lt;br /&gt;
* '''fire_event''' (boolean yes|no, default: no): Whether any capture events shall be fired.&lt;br /&gt;
&lt;br /&gt;
=== [kill] ===&lt;br /&gt;
Removes all units (including units in a recall list) that match the filter from the game.&lt;br /&gt;
* [[StandardUnitFilter]]: Selection criterion; do not use a [filter] tag.&lt;br /&gt;
* '''animate''': if 'yes', displays the unit dying (fading away).&lt;br /&gt;
* '''fire_event''': if 'yes', triggers any appropriate 'die' events (See [[EventWML]]). Note that events are only fired for killed units that have been on the map (as opposed to recall list).&lt;br /&gt;
* '''[secondary_unit]''' with a [[StandardUnitFilter]] as argument. Do not use a [filter] tag. Has an effect only if fire_event=yes. The first on-map unit matching the filter becomes second_unit in any fired die and last breath events. If an on-map unit matches and if there are several units killed with a single [kill] tag, second_unit is this same unit for all of them. If no on-map unit matches or [secondary_unit] isn't present, the variable second_unit in each of the die and last breath events is always the same as the variable unit (the dying unit).&lt;br /&gt;
&lt;br /&gt;
=== [move_unit] ===&lt;br /&gt;
works like the MOVE_UNIT macro.&lt;br /&gt;
* [[StandardUnitFilter]] as argument; do not use a [filter] tag. All units matching the filter are moved. If the target location is occupied, the nearest free location is chosen.&lt;br /&gt;
* '''to_x''' (unsigned integer): The units are moved to this x coordinate. Can be a comma-separated list, in which case the unit follows this given path during the move.&lt;br /&gt;
* '''to_y''' (unsigned integer): The units are moved to this y coordinate. Can be a comma-separated list.&lt;br /&gt;
* '''fire_event''' (optional, boolean yes|no, default no): Whether any according moveto events shall be fired. The target location ($x1, $y1 in the event) may not be the same location that the unit was tried to be moved to, if the original target location is occupied or impassable.&lt;br /&gt;
* '''check_passability''' (boolean yes|no, default yes): Whether the terrain the unit is moved to should be checked for suiting the unit. (If it does not, a nearby suitable hex is chosen.)&lt;br /&gt;
&lt;br /&gt;
=== [modify_ai] ===&lt;br /&gt;
Changes AI objects (aspects, goals, candidate actions or stages) for a specified side. See [[AiWML#Adding_and_Deleting_Aspects_with_the_.5Bmodify_ai.5D_Tag|AiWML]] for full description.&lt;br /&gt;
&lt;br /&gt;
* '''action''' (string): Takes values 'add', 'change', 'delete' or 'try_delete' to do just that for the AI object.&lt;br /&gt;
* '''path''' (string): Describes which AI object is to be modified.  &lt;br /&gt;
* '''[facet]''', '''[goal]''', '''[candidate_action]''' or '''[stage]''': Details about the AI object to be modified.&lt;br /&gt;
* [[StandardSideFilter]] {{DevFeature1.11}} tags and keys; default for empty side= is all sides, as usual in a SSF.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument {{DevFeature1.11}}: [modify_ai][filter_side] is deprecated, use the new inline SSF.&lt;br /&gt;
&lt;br /&gt;
=== [modify_unit] ===&lt;br /&gt;
works similar to the MODIFY_UNIT macro.&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. All units matching this filter are modified. Matches on recall list units too.&lt;br /&gt;
* Accepts generally the syntax inside of wml unit variables created by [store_unit] which can be viewed in a savefile or by using the :inspect command. Can add traits with immediate effect. Cannot remove things. Subtags with the same name must be written in the correct order to match them with the tag they are supposed to modify.&lt;br /&gt;
example usage (see also the test scenario):&lt;br /&gt;
 [modify_unit]&lt;br /&gt;
   [filter]&lt;br /&gt;
     x,y=38,6&lt;br /&gt;
   [/filter]&lt;br /&gt;
   hitpoints=10&lt;br /&gt;
   {TRAIT_HEALTHY}&lt;br /&gt;
 [/modify_unit]&lt;br /&gt;
&lt;br /&gt;
The unit which is currently modified is accessible via $this_unit, e.g. hitpoints = &amp;quot;$($this_unit.hitpoints / 2)&amp;quot; to set the hitpoints of all units to half of their particular maxima. This this_unit variable is independent from the this_unit variable available in the SUF used to determine which units to modify (first all matching units are gathered, and then all those are modified).&lt;br /&gt;
&lt;br /&gt;
note: The syntax allowed is somehow vague. Just try things and possibly correct/add/modify this documentation. (a [http://forums.wesnoth.org/viewtopic.php?f=21&amp;amp;t=31676&amp;amp; forum thread] discusses some related issues).&lt;br /&gt;
&lt;br /&gt;
=== [transform_unit] ===&lt;br /&gt;
Transforms every unit matching the filter to the given unit type. Keeps intact hit points, experience and status. If the unit is transformed to a non-living type (undead or mechanical), it will be also unpoisoned.&lt;br /&gt;
{{DevFeature1.11}} Hit points will be changed if necessary to respect the transformed unit's maximum hit points.&lt;br /&gt;
* [[StandardUnitFilter]]: do not use a [filter] tag.&lt;br /&gt;
* '''transform_to''': the unit type in which all the units matching the filter will be transformed. If missing, the units will follow their normal advancement.&lt;br /&gt;
&lt;br /&gt;
=== [petrify] ===&lt;br /&gt;
&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are petrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [unpetrify] ===&lt;br /&gt;
* [[StandardUnitFilter]] as an argument. Do not use a [filter] tag. All units matching this filter are unpetrified. Recall list units are included.&lt;br /&gt;
&lt;br /&gt;
=== [object] ===&lt;br /&gt;
Gives some unit an object which modifies their stats in some way.&lt;br /&gt;
* '''id''': (Optional) when the object is picked up, a flag is set for ''id''.  The object cannot be picked up if a flag for ''id'' has been set.  This means that any object with an id can only be used once, even if first_time_only=no is set for the event. This restriction is per level. In a campaign objects with the same id can be assigned once per level.&lt;br /&gt;
* '''delayed_variable_substitution''' (boolean yes|no, default no): If set to &amp;quot;yes&amp;quot;, the wml block contained in this [object] is not variable-substituted at execution time of the event where this [object] is within. You need this to work around a bug when adding ABILITY_TELEPORT via an [object] or when using [object][effect][filter]with a $this_unit (see http://gna.org/bugs/index.php?18893).&lt;br /&gt;
* '''[effect]''': one or more effect elements may be listed.  See [[EffectWML]] for a description of [effect].&lt;br /&gt;
* '''duration''':&lt;br /&gt;
**if 'level', effects only last until the end of the level (note : 'level' is the scenario, so this doesn't mean it last until the unit levels-up). {{DevFeature1.11}} 'level' has been renamed to 'scenario'.&lt;br /&gt;
**if 'forever' or not set, effects never wear off.&lt;br /&gt;
** {{DevFeature1.11}} if 'turn', effects only last until the start of the unit's next turn (when the unit refreshes movement and attacks). (Like other start-of-turn behavior, objects with a duration of &amp;quot;turn&amp;quot; won't expire before turn 2.)&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. The first unit found that matches the filter will be given the object. Only on-map units are considered. If no unit matches or no [filter] is supplied, it is tried to apply the object to the unit at the $x1,$y1 location of the event where this [object] is in. The case of no unit being at that spot is handled in the same way as no unit matching a given filter ([else] commands executed, cannot_use_message displayed)&lt;br /&gt;
* '''[then]''': a subtag that lets you execute actions if the filter conditions are met.  The most common action that should be inside here is a '''[remove_item]''' tag, but you could probably put any tags that otherwise work in a [then] tag.&lt;br /&gt;
* '''[else]''': a subtag that lets you execute actions if the filter conditions are *not* met.&lt;br /&gt;
* '''silent''': whether or not messages should be suppressed. Default is &amp;quot;no&amp;quot;.&lt;br /&gt;
* '''image''': the displayed image of the object.&lt;br /&gt;
* '''name''': (translatable) displayed as a caption of the image.&lt;br /&gt;
&lt;br /&gt;
* '''description''': (translatable) displayed as a message of the image.&lt;br /&gt;
* '''cannot_use_message''': (translatable) displayed instead of '''description''' if no unit passes the filter test.&lt;br /&gt;
&lt;br /&gt;
=== [remove_shroud] ===&lt;br /&gt;
Removes some shroud from the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to remove shroud. This can be a comma-separated list of sides. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles for which shroud should be removed&lt;br /&gt;
&lt;br /&gt;
=== [place_shroud] ===&lt;br /&gt;
Places some shroud on the map for a certain side (only relevant for sides that have shroud=yes).&lt;br /&gt;
* '''side''': (default=1) the side for which to place shroud. This can be a comma-separated list. note: Default side=1 for empty side= is deprecated.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] as argument&lt;br /&gt;
* [[StandardLocationFilter]]: the range of tiles on which shroud should be placed&lt;br /&gt;
&lt;br /&gt;
=== [lift_fog] ===&lt;br /&gt;
{{DevFeature1.11}}Lifts the fog of war from parts of the map for a certain side (only relevant for sides that have fog=yes), allowing a player to witness what occurs there even if that player has no units within vision range.&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the tiles from which fog should be lifted.&lt;br /&gt;
* '''multiturn''': ''yes/no, default:no''. The default (not multiturn) causes fog to be removed in the same way that normal vision works; the cleared tiles will remain cleared until fog is recalculated (which normally happens when a side ends its turn). When multiturn is set to &amp;quot;yes&amp;quot;, the cleared tiles remain clear until {{tag||reset_fog}} cancels the clearing. This allows tiles to remain clear for multiple turns, or to be refogged before the end of the current turn (without also refogging all tiles). Multiturn lifted fog is not shared with allies (even when share_view=yes).&lt;br /&gt;
&lt;br /&gt;
=== [reset_fog] ===&lt;br /&gt;
{{DevFeature1.11}}The primary use of this tag is to remove multiturn lifted fog (created by {{tag||lift_fog}}), which causes the fog to reset to what it would have been had WML not interfered. (That is, hexes that a side's units could not see at any point this turn will be re-fogged, while seen hexes remain defogged.)&lt;br /&gt;
* '''[filter_side]''' with a [[StandardSideFilter]] indicating which sides should be affected.&lt;br /&gt;
* [[StandardLocationFilter]]: the fog reset will be restricted to these tiles.&lt;br /&gt;
* '''reset_view''': ''yes/no, default: no'' If set to &amp;quot;yes&amp;quot;, then in addition to removing multiturn fog, the side's current view is canceled (independent of the SLF). This means that all hexes will become fogged for the side unless multiturn fog exists outside the tiles selected by the SLF. Normally, one would want the currently seen hexes to become clear of fog; this is done automatically at the end of many events, and it can be done manually with {{tag|InterfaceActionsWML|redraw}}.&lt;br /&gt;
Omitting both the SSF and the SLF would cancel all earlier uses of [lift_fog].&lt;br /&gt;
Additionally setting reset_view=&amp;quot;yes&amp;quot; would cause the side's entire map to be fogged (unless an ally keeps hexes clear by sharing its view).&lt;br /&gt;
&lt;br /&gt;
=== [allow_undo] ===&lt;br /&gt;
&lt;br /&gt;
Normally when an event with a handler fires, the player's undo stack is cleared, preventing all actions performed so far from being undone. Including this tag in the event handler prevents the stack from being cleared for this reason, allowing the player to undo actions. (However, the stack might still be cleared for other reasons, such as fog being cleared or combat occurring.) In the common cases, this means '''[allow_undo]''' allows the current action to be undone even though an event was handled. There is a less common case, though &amp;amp;mdash; specifically when handling a menu item, where there is no current action &amp;amp;mdash; and in this case, '''[allow_undo]''' means merely that earlier actions can still be undone.&lt;br /&gt;
* {{DevFeature1.11}} Using this tag in a menu item has an additional side effect in 1.11. Starting with version 1.11.1, executing a WML menu item normally counts as doing something as far as the &amp;quot;you have not started your turn yet&amp;quot; dialog is concerned. However, a menu item whose handler includes '''[allow_undo]''' will not count.&lt;br /&gt;
&lt;br /&gt;
This tag does nothing during recruit and recall actions, as the game incorrectly ignores whether or not an event fired during those times. {{DevFeature1.11}} This has been fixed in the latest development release.&lt;br /&gt;
&lt;br /&gt;
The types of actions that can be undone are movement, recruitment, recalling, and dismissing a unit from the recall list. If an action is undone, only the position (or existence) of the involved unit will be restored; any altered variables or changes to the game will remain changed after the action is undone.  It is up to the scenario designer to avoid abusing this command.&lt;br /&gt;
* Technically, if '''[allow_undo]''' is inside an '''[event]''' with ''first_time_only=yes'' (the default setting), and the user undoes the event, then the state of the game has changed in this way: the event will not fire a second time, even though the user undid the action the first time.&lt;br /&gt;
&lt;br /&gt;
=== [heal_unit] ===&lt;br /&gt;
Heal a unit. The variable '''$heal_amount''' will be set to the exact number of points healed (i.e can be lesser than the parameter '''amount''' if the unit is fully healed). $heal_amount contains only the number of hitpoints the first unit that was found got healed.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] All matching on-map units are healed. If no filter is supplied, it is tried to take the unit at $x1, $y1.&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] all the units matching the filter ''and'' having the ''heals'' ability will have their animation played (if ''animate'' is set to true) for each of the units healed.&lt;br /&gt;
*  '''amount''': (integer, default full) the maximum points the unit(s) will be healed. Can't set below 1 or above max_hitpoints. If &amp;quot;full&amp;quot;, sets hitpoints to max_hitpoints. Before 1.9 the default is 0.&lt;br /&gt;
*  '''animate''': a boolean which indicate if the healing animations must be played. (default no)&lt;br /&gt;
*  '''moves''': (integer, default 0) The maximum current movement points the units will be &amp;quot;healed&amp;quot;. Can't set below 0 or above max_moves. If &amp;quot;full&amp;quot;, sets moves to max_moves.&lt;br /&gt;
* '''restore_attacks''': (boolean, default no) Whether the units' attacks_left should be reset to their max_attacks (usually 1).&lt;br /&gt;
* '''restore_statuses''': (boolean, default yes) Whether standard statuses should be reset to &amp;quot;no&amp;quot;. This affects poisoned, slowed, petrified and unhealable. Before 1.9 this is always &amp;quot;no&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== [harm_unit] ===&lt;br /&gt;
Harms every unit matching the filter, for the specific damage amount.&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] all matching units will be harmed (required).&lt;br /&gt;
*  '''[filter_second]''': [[StandardUnitFilter]] if present, the first matching unit will attack all the units matching the filter above.&lt;br /&gt;
*  '''amount''': the amount of damage that will be done (required).&lt;br /&gt;
*  '''alignment''': (default neutral) applies an alignment to the damage, this means that if alignment=chaotic, the damage will be increased at night and reduced at day.&lt;br /&gt;
*  '''damage_type''': if present, amount will be altered by unit resistance to the damage type specified.&lt;br /&gt;
*  '''kill''': (default yes) if yes, when a harmed unit goes to or below 0 HP, it is killed; if no its HP are set to 1.&lt;br /&gt;
*  '''fire_event''': (default no) if yes, when a unit is killed by harming, the corresponding events are fired. {{DevFeature1.11}} If yes, also the corresponding advance and post advance events are fired.&lt;br /&gt;
*  '''animate''': (default no) if yes, scrolls to each unit before harming it and plays its defense (or attack, if it's the harmer) and death animations. Special values supported, other than the usual yes and no, are &amp;quot;attacker&amp;quot;, that means only the harmer will be animated, and &amp;quot;defender&amp;quot;, that means only the harmed units will be animated. {{DevFeature1.11}} If the supplied value is yes, attacker or defender also advancement animations are played.&lt;br /&gt;
*  '''[primary_attack], [secondary_attack]''': these set the weapon against which the harmed units will defend, and that the harming unit will use to attack, respectively (notice this is the opposite of '''[filter]''' and '''[filter_second]''' above). This allows for playing specific defense and attack animations. Both tags are expected to contain a [[FilterWML#Filtering_Weapons|Standard Weapon Filter]].&lt;br /&gt;
*  '''delay''': if animate=yes, sets the delay (in milliseconds, default 500) between each unit harming.&lt;br /&gt;
*  '''variable''': if present, the damage caused to the unit, altered by resistances, will be stored in a WML array with the given name, under the &amp;quot;harm_amount&amp;quot; key.&lt;br /&gt;
*  '''poisoned, slowed, petrified, unhealable''': (default no) if yes, every harmed unit that doesn't already have such status will have it set.&lt;br /&gt;
*  '''experience''': if yes, and there is a harmer, experience will be attributed like in regular combat.&lt;br /&gt;
*  '''resistance_multiplier''': {{DevFeature1.11}} the harmed unit's resistance is multiplied by the supplied value; this means that a value lower than 1 increases it, and a value greater than 1 decreases it. Default value is 1, that means no modification.&lt;br /&gt;
&lt;br /&gt;
=== [time_area] ===&lt;br /&gt;
How a day should progress in a given area. Everywhere not specified in a [time_area] tag is affected by the [time] tags in the [scenario] tag.&lt;br /&gt;
* [[StandardLocationFilter]]: the locations to affect. ''note: only for [event][time_area]s - at scenario toplevel [time_area] does not support [[StandardLocationFilter]], only location ranges''&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
* '''id''': an unique identifier assigned to a time_area. Optional, unless you want to remove the time_area later. Can be a comma-separated list when removing time_areas, see below.&lt;br /&gt;
* '''remove''': (boolean) yes/no value. Indicates whether the specified time_area should be removed. Requires an identifier. If no identifier is used, however, all time_areas are removed.&lt;br /&gt;
&lt;br /&gt;
''Example:'' (caves in parts of a map)&lt;br /&gt;
 [time_area]&lt;br /&gt;
     x=1-2,4-5&lt;br /&gt;
     y=1-2,1-2&lt;br /&gt;
     {UNDERGROUND}&lt;br /&gt;
 [/time_area]&lt;br /&gt;
&lt;br /&gt;
=== [end_turn] ===&lt;br /&gt;
End the current side's turn. The current event is finished before the turn is ended. Also, if the current event (where the tag appears) has been fired by another event, that event (and the complete stack of other possible parent events) is ended before [end_turn] comes into affect. Also, events following the event stack that fired [end_turn] are not omitted (e.g. [end_turn] is used by a side turn event and a turn refresh event does something afterwards).&lt;br /&gt;
&lt;br /&gt;
=== [replace_map] ===&lt;br /&gt;
&lt;br /&gt;
Replaces the entire map.&lt;br /&gt;
* '''map''': Content of a wesnoth map file. example:&lt;br /&gt;
 map=&amp;quot;{campaigns/Heir_To_The_Throne/maps/01_The_Elves_Besieged.map}&amp;quot;&lt;br /&gt;
* '''expand''': if 'yes', allows the map size to increase. The expansion direction is currently always bottom-right.&lt;br /&gt;
* '''shrink''': if 'yes', allows the map size to decrease. If the map size is reduced, any units that would no longer be on the map due to its coordinates no longer existing will be put into the recall list.&lt;br /&gt;
Note: When a hex changes from a village terrain to a non-village terrain, and a team owned that village it loses that village. When a hex changes from a non-village terrain to a village terrain and there is a unit on that hex it does not automatically capture the village. The reason for not capturing villages it that there are too many choices to make; should a unit loose its movement points, should capture events be fired. It is easier to do this as wanted by the author in WML.&lt;br /&gt;
&lt;br /&gt;
=== [replace_schedule] ===&lt;br /&gt;
Replace the time of day schedule of the entire scenario.&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
&lt;br /&gt;
=== [tunnel] ===&lt;br /&gt;
&lt;br /&gt;
Create a tunnel between some locations, later usable by units to move from source hex to target hex (using the movement cost of unit on the target terrain). ([http://forums.wesnoth.org/viewtopic.php?f=21&amp;amp;t=14749&amp;amp;p=405667&amp;amp;hilit=tunnel#p405667 source])&lt;br /&gt;
&lt;br /&gt;
* '''id''' identifier for the tunnel, to allow removing (optional).&lt;br /&gt;
* '''remove''': (boolean) yes/no value. If yes, removes all defined tunnels with the same ID (then only id= is necessary). (default: no)&lt;br /&gt;
* '''bidirectional''': (boolean) if yes, creates also a tunnel in the other direction. (default: yes)&lt;br /&gt;
* '''always_visible''': (boolean) if yes, the possible movement of enemies under fog can be seen. (default: no)&lt;br /&gt;
* '''[source]''': [[StandardLocationFilter]] the source hex(es) (required).&lt;br /&gt;
* '''[target]''': [[StandardLocationFilter]] the target hex(es) (required).&lt;br /&gt;
* '''[filter]''': [[StandardUnitFilter]] the units which can use the tunnel (required). Leave empty for &amp;quot;all units&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
(Note: The tunnel tag can also be used inside the [[AbilitiesWML|[teleport]]] ability, without remove= and id=).&lt;br /&gt;
&lt;br /&gt;
== Useful Macros ==&lt;br /&gt;
There are some predefined macros that you find useful for direct actions. You can find a complete list along with a detailed explanation of how they work [http://www.wesnoth.org/macro-reference.xhtml here].&lt;br /&gt;
* '''{MOVE_UNIT}''': Moves a unit to another location in the map and the player sees the movement (unlike [teleport])&lt;br /&gt;
* '''{FULL_HEAL}''': Brings a unit to full HP&lt;br /&gt;
* '''{LOYAL_UNIT}''': Create a loyal unit&lt;br /&gt;
* '''{MODIFY_TERRAIN_MASK}''': Modify an area of terrain&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=48308</id>
		<title>LuaWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=48308"/>
		<updated>2013-01-03T13:33:05Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* Miscellaneous */ Added wesnoth.get_time_stamp and helper.shuffle&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
== The '''[lua]''' tag ==&lt;br /&gt;
&lt;br /&gt;
This tag is a part of [[ActionWML]], thus can be used inside [event] and at other places where [[ActionWML]] can be used. It makes it possible to write actions with the [http://www.lua.org Lua 5.2] language.&lt;br /&gt;
&lt;br /&gt;
The tag supports only the '''code''' key, which is a string containing the Lua scripts. Since Lua makes usage of the quotes and the { and } symbols, it is certainly wise to enclose the script between stronger quotes, as they prevent the preprocessor from performing macro expansion and tokenization.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; wesnoth.message &amp;quot;Hello World!&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
The Lua kernel can also be accessed from the [[CommandMode|command mode]]:&lt;br /&gt;
&lt;br /&gt;
 :lua local u = wesnoth.get_units({ id = &amp;quot;Konrad&amp;quot; })[1]; u.moves = 5&lt;br /&gt;
&lt;br /&gt;
The '''[args]''' sub-tag can be used to pass a WML object to the script via its variadic local variable &amp;quot;'''...'''&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; local t = ...; wesnoth.message(tostring(t.text)) &amp;gt;&amp;gt;&lt;br /&gt;
     [args]&lt;br /&gt;
         text = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/args]&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
== Global environment ==&lt;br /&gt;
&lt;br /&gt;
All the Lua scripts of a scenario share the same global environment (aka Lua state). For instance, a function defined in an event can be used in all the events that happen after it.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             function narrator(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
In the example above, the redundant structure could be hidden behind macros. But it may be better to simply define a new WML tag.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             -- The function is now local, since its name does not have to be&lt;br /&gt;
             -- visible outside this Lua scripts.&lt;br /&gt;
             local function handler(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
             -- Create a new tag named [narrator].&lt;br /&gt;
             wesnoth.register_wml_action(&amp;quot;narrator&amp;quot;, handler)&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
The global environment is not preserved over save/load cycles. Therefore, storing values in the global environment is generally a bad idea (unless it has been redirected to WML variables, see [[LuaWML:Variables#set_wml_var_metatable|helper.set_wml_var_metatable]]). The only time assigning global variables (including function definitions) makes sense is during a [[EventWML#Predefined 'name' Key Values|preload]] event, as this event is always run. Therefore, helper functions defined at that time will be available to all the later scripts.&lt;br /&gt;
&lt;br /&gt;
The global environment initially contains the following modules: [http://www.lua.org/manual/5.1/manual.html#5.1 basic] (no name), [http://www.lua.org/manual/5.1/manual.html#5.4 string], [http://www.lua.org/manual/5.1/manual.html#5.5 table], and [http://www.lua.org/manual/5.1/manual.html#5.6 math]. A '''wesnoth''' module is also available, it provides access to the [[#Interface to the C++ engine|C++ engine]]. Besides, the functions clock, date, time and difftime from the [http://www.lua.org/manual/5.1/manual.html#5.8 os] library (Keep in mind that they aren't multiplayer- and replay-save.) and traceback from the [http://www.lua.org/manual/5.1/manual.html#5.9 debug] library are also available.&lt;br /&gt;
&lt;br /&gt;
At the start of a script, the variadic local variable '''...''' (three dots) is a proxy table representing [[#Encoding WML objects into Lua tables|WML data]]. This table is the content of the '''[args]''' sub-tag of the '''[lua]''' tag, if any.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following WML event is taken from Wesnoth' tutorial. It will serve as an example to present how Lua scripts are embedded into Wesnoth. The event is fired whenever a unit from side 1 (that is, the hero controlled by the user) moves to a tile that is not the one set in the WML variable ''target_hex''.&lt;br /&gt;
&lt;br /&gt;
 # General catch for them moving to the wrong place.&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [if]&lt;br /&gt;
         [variable]&lt;br /&gt;
             name=target_hex.is_set&lt;br /&gt;
             equals=yes&lt;br /&gt;
         [/variable]&lt;br /&gt;
         [then]&lt;br /&gt;
             [if]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=x1&lt;br /&gt;
                     equals=$target_hex.x&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=y1&lt;br /&gt;
                     equals=$target_hex.y&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [then]&lt;br /&gt;
                 [/then]&lt;br /&gt;
                 [else]&lt;br /&gt;
                     [redraw][/redraw]&lt;br /&gt;
                     [message]&lt;br /&gt;
                         speaker=narrator&lt;br /&gt;
                         message=_ &amp;quot;*Oops!&lt;br /&gt;
 You moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot; +&lt;br /&gt;
                         _ &amp;quot;&lt;br /&gt;
 *Left click or press spacebar to continue...&amp;quot;&lt;br /&gt;
                     [/message]&lt;br /&gt;
                 [/else]&lt;br /&gt;
             [/if]&lt;br /&gt;
         [/then]&lt;br /&gt;
     [/if]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
A Lua script that performs the same action is presented below.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             local event_data = wesnoth.current.event_context&lt;br /&gt;
             if target_hex.is_set and&lt;br /&gt;
                (event_data.x1 ~= target_hex.x or event_data.y1 ~= target_hex.y)&lt;br /&gt;
             then&lt;br /&gt;
                 W.redraw()&lt;br /&gt;
                 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Here is a more detailed explanation of the Lua code. Its first line&lt;br /&gt;
&lt;br /&gt;
 local event_data = wesnoth.current.event_context&lt;br /&gt;
&lt;br /&gt;
puts the event data into the ''event_data'' local variable. Since it is a ''moveto'' event, the ''event_data'' table contains the destination of the unit in the ''x1'' and ''y1'' fields.&lt;br /&gt;
&lt;br /&gt;
The next two lines then test&lt;br /&gt;
&lt;br /&gt;
 if target_hex.is_set and&lt;br /&gt;
    (event_data.x1 ~= target_hex.x or event_data.y1 ~= target_hex.y)&lt;br /&gt;
&lt;br /&gt;
whether the variable ''target_hex'' matches the event parameters. Since ''target_hex'' is not a local variable, it is taken from the global environment (a table implicitly named ''_G'', so it is actually ''_G.target_hex''). The global environment is not persistent, so it cannot be used to store data. In order to make it useful, it was mapped to the storage of WML variables by the following ''preload'' event.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             -- skipping some other initializations&lt;br /&gt;
             -- ...&lt;br /&gt;
             H.set_wml_var_metatable(_G)&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Without a prelude redirecting ''_G'', the conditional would have been written&lt;br /&gt;
&lt;br /&gt;
 if wesnoth.get_variable(&amp;quot;target_hex.is_set&amp;quot;) and&lt;br /&gt;
    (event_data.x1 ~= wesnoth.get_variable(&amp;quot;target_hex.x&amp;quot;) or event_data.y1 ~= wesnoth.get_variable(&amp;quot;target_hex.y&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The body of the conditional then performs the [[InterfaceActionsWML#Other interface tags|[redraw]]] action.&lt;br /&gt;
&lt;br /&gt;
 W.redraw()&lt;br /&gt;
&lt;br /&gt;
Again, this short syntax is made possible by a line of the prelude that makes ''W'' a proxy for performing WML actions.&lt;br /&gt;
&lt;br /&gt;
 W = H.set_wml_action_metatable {}&lt;br /&gt;
&lt;br /&gt;
Without this shortcut, the first statement would have been written&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;redraw&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Finally the script displays a message by&lt;br /&gt;
&lt;br /&gt;
 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The ''narrator_says'' function is defined in the prelude too, since the construct behind it occurs several times in the tutorial. In plain WML, macros would have been used instead. The definition of the function is&lt;br /&gt;
&lt;br /&gt;
 function narrator_says(m)&lt;br /&gt;
     W.message { speaker=&amp;quot;narrator&amp;quot;,&lt;br /&gt;
                 message = m .. _ &amp;quot;\n*Left click or press spacebar to continue...&amp;quot; }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The function fires a [[InterfaceActionsWML#.5Bmessage.5D|[message]]] action and passes a WML object containing the usual two fields to it. The second field is initialized by concatenating the function argument with another string. Both strings are prefixed by the ''_'' symbol to mark them as translatable. (Note that ''_'' is just a unary function, not a keyword.) Again, this is made possible by a specific line of the prelude:&lt;br /&gt;
&lt;br /&gt;
 _ = wesnoth.textdomain &amp;quot;wesnoth-tutorial&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A longer translation of the tutorial is available at [https://gna.org/patch/download.php?file_id=5483].&lt;br /&gt;
&lt;br /&gt;
== Interface to the engine and helper functions ==&lt;br /&gt;
&lt;br /&gt;
Functionalities of the game engine are available through the functions of the '''wesnoth''' global table. Some of these functions return proxy tables. Writes to fields marked &amp;quot;read-only&amp;quot; are ignored. The '''__cfg''' fields return plain tables; in particular, writes do not modify the original object, and reads return the values from the time the dump was performed.&lt;br /&gt;
&lt;br /&gt;
Some helper functions are provided by the '''lua/helper.lua''' library. They are stored inside a table that is returned when loading the library with [[LuaWML:Files#wesnoth.require|wesnoth.require]].&lt;br /&gt;
&lt;br /&gt;
 helper = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== WML variables ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]]&lt;br /&gt;
* [[LuaWML:Variables#helper.set_wml_var_metatable|helper.set_wml_var_metatable]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_child|helper.get_child]]&lt;br /&gt;
* [[LuaWML:Variables#helper.child_range|helper.child_range]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_array|helper.get_variable_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_proxy_array|helper.get_variable_proxy_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.set_variable_array|helper.set_variable_array]]&lt;br /&gt;
&lt;br /&gt;
=== Events and WML actions ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire|wesnoth.fire]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.wml_actions|wesnoth.wml_actions]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.game_events|wesnoth.game_events]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire_event|wesnoth.fire_event]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.eval_conditional|wesnoth.eval_conditional]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.tovconfig|wesnoth.tovconfig]]&lt;br /&gt;
* [[LuaWML:Events#helper.set_wml_action_metatable|helper.set_wml_action_metatable]]&lt;br /&gt;
* [[LuaWML:Events#helper.wml_error|helper.wml_error]]&lt;br /&gt;
* [[LuaWML:Events#helper.literal|helper.literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.parsed|helper.parsed]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_literal|helper.shallow_literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_parsed|helper.shallow_parsed]]&lt;br /&gt;
&lt;br /&gt;
=== User interface ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Display#wesnoth.message|wesnoth.message]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.clear_messages|wesnoth.clear_messages]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.textdomain|wesnoth.textdomain]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.delay|wesnoth.delay]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.float_label|wesnoth.float_label]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_hex|wesnoth.select_hex]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.scroll_to_tile|wesnoth.scroll_to_tile]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.lock_view|wesnoth.lock_view]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.view_locked|wesnoth.view_locked]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.play_sound|wesnoth.play_sound]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_music|wesnoth.set_music]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_dialog|wesnoth.show_dialog]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_value|wesnoth.set_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_dialog_value|wesnoth.get_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_active|wesnoth.set_dialog_active]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_callback|wesnoth.set_dialog_callback]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_canvas|wesnoth.set_dialog_canvas]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_displayed_unit|wesnoth.get_displayed_unit]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.theme_items|wesnoth.theme_items]]&lt;br /&gt;
* [[LuaWML:Display#helper.get_user_choice|helper.get_user_choice]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_time_of_day|wesnoth.get_time_of_day]]&lt;br /&gt;
&lt;br /&gt;
=== Map and terrains ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_map_size|wesnoth.get_map_size]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain|wesnoth.get_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.set_terrain|wesnoth.set_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain_info|wesnoth.get_terrain_info]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_selected_tile|wesnoth.get_selected_tile]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_locations|wesnoth.get_locations]]&lt;br /&gt;
* {{DevFeature1.11}}[[LuaWML:Tiles#wesnoth.get_villages|wesnoth.get_villages]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.match_location|wesnoth.match_location]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_tile_overlay|wesnoth.add_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_tile_overlay|wesnoth.remove_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_image|items.place_image]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_halo|items.place_halo]]&lt;br /&gt;
* [[LuaWML:Tiles#items.remove|items.remove]]&lt;br /&gt;
&lt;br /&gt;
=== Units ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_units|wesnoth.get_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit|wesnoth.get_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.match_unit|wesnoth.match_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_unit|wesnoth.put_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_recall_units|wesnoth.get_recall_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_recall_unit|wesnoth.put_recall_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.create_unit|wesnoth.create_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.copy_unit|wesnoth.copy_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.extract_unit|wesnoth.extract_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_modification|wesnoth.add_modification]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_resistance|wesnoth.unit_resistance]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_defense|wesnoth.unit_defense]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_movement_cost|wesnoth.unit_movement_cost]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_ability|wesnoth.unit_ability]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type_ids|wesnoth.get_unit_type_ids]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type|wesnoth.get_unit_type]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_types|wesnoth.unit_types]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.races|wesnoth.races]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_traits|wesnoth.get_traits]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.simulate_combat|wesnoth.simulate_combat]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.transform_unit|wesnoth.transform_unit]]&lt;br /&gt;
&lt;br /&gt;
=== Sides ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_side|wesnoth.get_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.sides|wesnoth.sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_sides|wesnoth.get_sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_village_owner|wesnoth.get_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.set_village_owner|wesnoth.set_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.is_enemy|wesnoth.is_enemy]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.match_side|wesnoth.match_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_starting_location|wesnoth.get_starting_location]]&lt;br /&gt;
* [[LuaWML:Sides#helper.all_teams|helper.all_teams]]&lt;br /&gt;
&lt;br /&gt;
=== Pathfinder ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_path|wesnoth.find_path]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_vacant_tile|wesnoth.find_vacant_tile]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_reach|wesnoth.find_reach]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.distance_between|helper.distance_between]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.adjacent_tiles|helper.adjacent_tiles]]&lt;br /&gt;
&lt;br /&gt;
=== Lua files ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Files#wesnoth.dofile|wesnoth.dofile]]&lt;br /&gt;
* [[LuaWML:Files#wesnoth.require|wesnoth.require]]&lt;br /&gt;
&lt;br /&gt;
=== Location sets ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Location_set#location_set.create|location_set.create]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_pairs|location_set.of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_wml_var|location_set.of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:empty|location_set:empty]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:size|location_set:size]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:clear|location_set:clear]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:get|location_set:get]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:insert|location_set:insert]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:remove|location_set:remove]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_pairs|location_set:of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_wml_var|location_set:of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_pairs|location_set:to_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_stable_pairs|location_set:to_stable_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_wml_var|location_set:to_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union|location_set:union]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter|location_set:inter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:iter|location_set:iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:stable_iter|location_set:stable_iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:filter|location_set:filter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union_merge|location_set:union_merge]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter_merge|location_set:inter_merge]]&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.game_config|wesnoth.game_config]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.current|wesnoth.current]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.synchronize_choice|wesnoth.synchronize_choice]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_image_size|wesnoth.get_image_size]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compare_versions|wesnoth.compare_versions]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.have_file|wesnoth.have_file]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.debug|wesnoth.debug]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_time_stamp|wesnoth.get_time_stamp]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#helper.set_wml_tag_metatable|helper.set_wml_tag_metatable]]&lt;br /&gt;
* [[LuaWML:Misc#helper.modify_unit|helper.modify_unit]]&lt;br /&gt;
* [[LuaWML:Misc#helper.move_unit_fake|helper.move_unit_fake]]&lt;br /&gt;
* [[LuaWML:Misc#helper.rand|helper.rand]]&lt;br /&gt;
* [[LuaWML:Misc#helper.round|helper.round]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#helper.shuffle|helper.shuffle]] {{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
== Encoding WML objects into Lua tables ==&lt;br /&gt;
&lt;br /&gt;
Function [[LuaWML:Events#wesnoth.fire|wesnoth.fire]] expects a table representing a WML object as its second argument (if needed). Function [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]] allows to modify whole WML objects, again by passing it a table. Function [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]] transforms a WML object into a table, if its second argument is not set to ''true''. All these tables have the same format.&lt;br /&gt;
&lt;br /&gt;
Scalar fields are transformed into WML attributes. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     a_bool = true,&lt;br /&gt;
     an_int = 42,&lt;br /&gt;
     a_float = 1.25,&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;,&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     a_bool = &amp;quot;yes&amp;quot;&lt;br /&gt;
     an_int = &amp;quot;42&amp;quot;&lt;br /&gt;
     a_float = &amp;quot;1.25&amp;quot;&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
WML child objects are not stored as Lua named fields, since several of them can have the same tag. Moreover, their tags can conflict with the attribute keys. So child objects are stored as pairs string + table in the unnamed fields in definition order. This means that for every subtag appearing in the wml code there is an additional table &amp;quot;layer&amp;quot; in the corresponding WML table of the form {[1] = &amp;quot;tag_name&amp;quot;, [2] = {}} which is equivalent to {&amp;quot;tag_name&amp;quot;, {}}. [1] etc are the unnamed fields (as opposed to wml attributes). The table under [2] in this subtable then holds the wml attributes from inside the wml subtag. So every subtag other than the toplevel tag corresponds to two nested tables each. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { v = 1, w = 2 } },&lt;br /&gt;
     { &amp;quot;foo&amp;quot;, { x = false } },&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     { &amp;quot;foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     foo = 42&lt;br /&gt;
     [bar]&lt;br /&gt;
         v = 1&lt;br /&gt;
         w = 2&lt;br /&gt;
     [/bar]&lt;br /&gt;
     [foo]&lt;br /&gt;
         x = no&lt;br /&gt;
     [/foo]&lt;br /&gt;
     [bar]&lt;br /&gt;
         y = foo&lt;br /&gt;
     [bar]&lt;br /&gt;
     [foobar]&lt;br /&gt;
         z = 5&lt;br /&gt;
         [barfoo]&lt;br /&gt;
         [/barfoo]&lt;br /&gt;
     [/foobar]&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
Both tables above are also equivalent to this WML table, where all unnamed fields are displayed:&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     [1] = { [1] = &amp;quot;bar&amp;quot;, [2] = { v = 1, w = 2 } },&lt;br /&gt;
     [2] = { [1] = &amp;quot;foo&amp;quot;, [2] = { x = false } },&lt;br /&gt;
     [3] = { [1] = &amp;quot;bar&amp;quot;, [2] = { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     [4] = { [1] = &amp;quot;foobar&amp;quot;, [2] = { z = 5, [1] = { [1] = &amp;quot;barfoo&amp;quot;, [2] = {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
So assuming ''cfg'' contains the above WML object, the following accesses are possible:&lt;br /&gt;
&lt;br /&gt;
 a_int = cfg.foo        -- &amp;quot;dummy.foo&amp;quot;, 42&lt;br /&gt;
 a_string = cfg[3][2].y -- &amp;quot;dummy.bar[1].y&amp;quot;, &amp;quot;foo&amp;quot;&lt;br /&gt;
 a_table = cfg[4][2]    -- &amp;quot;dummy.foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } }&lt;br /&gt;
&lt;br /&gt;
Consider using the [[LuaWML:Variables#helper.get_child|helper.get_child]] and [[LuaWML:Variables#helper.child_range|helper.child_range]] to ease the access to subtags.&lt;br /&gt;
&lt;br /&gt;
Functions registered by [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]] receive their data in a userdata object which has the exact same structure as above. It is read-only however. Accessing fields or children performs variable substitution on the fly. Its '''__parsed''' and '''__literal''' fields provide translations to plain tables (therefore writable). '''__literal''' returns the original text of the data (including dollar symbols in attributes and [insert_tag] children), while '''__parsed''' performs a variable substitution.&lt;br /&gt;
&lt;br /&gt;
For instance, if you cannot stand any longer the fact that '''first_time_only''' is set to yes by default for the '''[event]''' tag, you can redefine it. But we have to be careful not to cause variable substitution, since the engine would perform a second variable substitution afterwards.&lt;br /&gt;
&lt;br /&gt;
 local old_event_handler&lt;br /&gt;
 old_event_handler = register_wml_action(&amp;quot;event&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         -- Get the plain text from the user.&lt;br /&gt;
         local new_cfg = cfg.__literal&lt;br /&gt;
         -- The expression below is equivalent to cfg.__parsed.first_time_only,&lt;br /&gt;
         -- only faster. It is needed, since the first_time_only attribute may&lt;br /&gt;
         -- reference variables.&lt;br /&gt;
         local first = cfg.first_time_only&lt;br /&gt;
         -- Modify the default behavior of first_time_only.&lt;br /&gt;
         if first == nil then first = false end&lt;br /&gt;
         new_cfg.first_time_only = first&lt;br /&gt;
         -- Call the engine handler.&lt;br /&gt;
         old_event_handler(new_cfg)&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Note that, since the object is a userdata and not a table, '''pairs''' and '''ipairs''' are unfortunately not usable on it. So scripts have to work at a lower level. For instance, the following function returns the first sub-tag with a given name and it works both on WML tables and WML userdata:&lt;br /&gt;
&lt;br /&gt;
 function get_child(cfg, name)&lt;br /&gt;
     for i = 1, #cfg do&lt;br /&gt;
         local v = cfg[i]&lt;br /&gt;
         if v[1] == name then return v[2] end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Another approach for handling userdata and tables in the same way, would be to convert the former into the latter beforehand:&lt;br /&gt;
&lt;br /&gt;
 if getmetatable(cfg) == &amp;quot;wml object&amp;quot; then cfg = cfg.__parsed end&lt;br /&gt;
&lt;br /&gt;
The WML userdata provides two other special fields: '''__shallow_parsed''' and '''__shallow_literal'''. They return a table corresponding to the WML userdata with variable substitution performed on the attributes (or not). [insert_tag] tags have also been parsed, so the number of children is faithful. But contrarily to '''__parsed''' and '''__literal''', the process is not recursive: all the children are still WML userdata and variable substitution can still happen for them. These shallow translators are meant as optimized versions of the deep ones, when only the toplevel attributes need to be writable.&lt;br /&gt;
&lt;br /&gt;
== Skeleton of a preload event ==&lt;br /&gt;
&lt;br /&gt;
The following event is a skeleton for a prelude enabling Lua in your WML events. It creates a table ''H'' containing the functions from helper.lua and a table ''W'' that serves as a proxy for firing WML actions. It also sets up the global environment so that any access to an undefined global variable is redirected to the persistent WML storage.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             W = H.set_wml_action_metatable {}&lt;br /&gt;
             _ = wesnoth.textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
             -- Define your global constants here.&lt;br /&gt;
             -- ...&lt;br /&gt;
 &lt;br /&gt;
             H.set_wml_var_metatable(_G)&lt;br /&gt;
 &lt;br /&gt;
             -- Define your global functions here.&lt;br /&gt;
             -- ...&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
It may be worth putting the whole Lua script above inside a separate file and having the ''preload'' event load it:&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; wesnoth.dofile &amp;quot;~add-ons/Whatever/file.lua&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
== Remarks ==&lt;br /&gt;
&lt;br /&gt;
The math.random function is not safe for replays and multiplayer games, since the random values will be different each time and on all the clients. Instead, the Lua code should rely on the [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] tag to synchronize random values.&lt;br /&gt;
&lt;br /&gt;
 function random(min, max)&lt;br /&gt;
   if not max then min, max = 1, min end&lt;br /&gt;
   wesnoth.fire(&amp;quot;set_variable&amp;quot;, { name = &amp;quot;LUA_random&amp;quot;, rand = string.format(&amp;quot;%d..%d&amp;quot;, min, max) })&lt;br /&gt;
   local res = wesnoth.get_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   wesnoth.set_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   return res&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference|*]]&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Misc&amp;diff=48307</id>
		<title>LuaWML/Misc</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Misc&amp;diff=48307"/>
		<updated>2013-01-03T13:30:52Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added helper.shuffle()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes miscellaneous [[LuaWML]] objects and helpers.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.game_config ====&lt;br /&gt;
&lt;br /&gt;
Contrarily to the other values of the ''wesnoth'' table, ''game_config'' is simply a proxy table. Its fields offer an interface to the global settings of Wesnoth:&lt;br /&gt;
&lt;br /&gt;
* '''version''': string (read only)&lt;br /&gt;
* '''base_income''': integer (read/write)&lt;br /&gt;
* '''village_income''': integer (read/write)&lt;br /&gt;
* '''poison_amount''': integer (read/write)&lt;br /&gt;
* '''rest_heal_amount''': integer (read/write)&lt;br /&gt;
* '''recall_cost''': integer (read/write)&lt;br /&gt;
* '''kill_experience''': integer (read/write)&lt;br /&gt;
* '''last_turn''': integer (read/write) turn limit, maximum number of turns&lt;br /&gt;
* '''debug''': boolean (read only)&lt;br /&gt;
* '''mp_debug''': boolean (read only) {{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
 -- Poison a bit weak? Let's boost it!&lt;br /&gt;
 wesnoth.game_config.poison_amount = 15&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.current ====&lt;br /&gt;
&lt;br /&gt;
As with ''game_config'', ''current'' is a proxy table. Its fields are getter for game-related properties:&lt;br /&gt;
&lt;br /&gt;
* '''side''': integer (read only)&lt;br /&gt;
* '''turn''': integer (read only)&lt;br /&gt;
* '''event_context''': WML table with attributes ''name'', ''x1'', ''y1'', ''x2'', ''y2'', and children ''weapon'', ''second_weapon'', describing the trigger for the current event.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Turn %d, side %d is playing.&amp;quot;, wesnoth.current.turn, wesnoth.current.side))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.synchronize_choice ====&lt;br /&gt;
&lt;br /&gt;
Recovers a WML table that was computed on one client only or was stored in a replay. The actual computation is performed by the function passed as the first argument, assuming that the client is the side currently playing. For all the other clients, the function will not be called. An optional second function can be passed; if present, it will be used instead of the first one when the client happens to be an AI (hence not enable to interact with a user interface).&lt;br /&gt;
&lt;br /&gt;
 local result = wesnoth.synchronize_choice(&lt;br /&gt;
   function()&lt;br /&gt;
     -- Called only on the client handling the current side, if it is a human.&lt;br /&gt;
     local choice = 0&lt;br /&gt;
     wesnoth.show_dialog(&lt;br /&gt;
       some_dialog_cfg, nil,&lt;br /&gt;
       function()&lt;br /&gt;
         choice = wesnoth.get_dialog_value &amp;quot;some_list&amp;quot;&lt;br /&gt;
       end)&lt;br /&gt;
     return { value = choice }&lt;br /&gt;
   end,&lt;br /&gt;
   function()&lt;br /&gt;
     -- Called only on the client handling the current side, if it is an AI.&lt;br /&gt;
     return { value = math.random(some_list_size) }&lt;br /&gt;
   end)&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Selected item: %d&amp;quot;, result.value))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_image_size ====&lt;br /&gt;
&lt;br /&gt;
Returns the width and height of an image.&lt;br /&gt;
&lt;br /&gt;
 local w, h = wesnoth.get_image_size &amp;quot;units/transport/galleon.png&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.compare_versions ====&lt;br /&gt;
&lt;br /&gt;
Takes two versions strings and an operator, returns whether the comparison yields true.&lt;br /&gt;
Follows the same rules like the #ifver preprocessor statement.&lt;br /&gt;
&lt;br /&gt;
 local function version_is_sufficient(required)&lt;br /&gt;
  if not wesnoth.compare_versions then return false end&lt;br /&gt;
  return wesnoth.compare_versions(wesnoth.game_config.version, &amp;quot;&amp;gt;=&amp;quot;, required)&lt;br /&gt;
 end&lt;br /&gt;
 local required = &amp;quot;1.9.6+svn&amp;quot;&lt;br /&gt;
 if not version_is_sufficient(required) then wesnoth.message(string.format(&lt;br /&gt;
  &amp;quot;Your BfW version is insufficient, please get BfW %s or greater!&amp;quot;, required)) end&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.have_file ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}}Checks if the file (not necessarily a Lua file) or the directory passed as argument exists. Returns true if the file exists, false otherwise. Follows the same rules like the #ifhave preprocessor statement.&lt;br /&gt;
&lt;br /&gt;
 -- Does the user have installed the UMC Music Book 1?&lt;br /&gt;
 local umc_music = wesnoth.have_file( &amp;quot;~add-ons/UMC_Music_Book_1/_main.cfg&amp;quot; )&lt;br /&gt;
 -- and if we want to check for the folder?&lt;br /&gt;
 local music_folder = wesnoth.have_file( &amp;quot;~add-ons/UMC_Music_Book_1/&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.debug ====&lt;br /&gt;
&lt;br /&gt;
Takes a userdata with metatable wml object or a wml table and dumps its content into a pretty string.&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;number&amp;quot;, 100)&lt;br /&gt;
 local vconfig = wesnoth.tovconfig({ key = &amp;quot;$number&amp;quot;, another_key = true,&lt;br /&gt;
     {&amp;quot;a_subtag&amp;quot;, { a_key_in_the_subtag = &amp;quot;foo&amp;quot; }}&lt;br /&gt;
 })&lt;br /&gt;
 wesnoth.message(wesnoth.debug(vconfig))&lt;br /&gt;
 wesnoth.message(wesnoth.debug(vconfig.__literal))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_time_stamp ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}}This function retrieves the current time stamp, that is the amount of milliseconds passed from when the SDL library was initialized. It takes no arguments and returns an integer.&lt;br /&gt;
'''WARNING:''' this function uses the same code as [set_variable] time=stamp, and so it is MP-unsafe. It is provided only for benchmark purposes and AI development, although it should work inside wesnoth.synchronize_choice() as well.&lt;br /&gt;
 local stamp = wesnoth.get_time_stamp()&lt;br /&gt;
&lt;br /&gt;
==== helper.set_wml_tag_metatable ====&lt;br /&gt;
&lt;br /&gt;
Sets the metable of a table so that it can be used to create subtags with less brackets. Returns the table. The fields of the table are simple wrappers around table constructors.&lt;br /&gt;
&lt;br /&gt;
 T = helper.set_wml_tag_metatable {}&lt;br /&gt;
 W.event { name = &amp;quot;new turn&amp;quot;, T.message { speaker = &amp;quot;narrator&amp;quot;, message = &amp;quot;?&amp;quot; } }&lt;br /&gt;
&lt;br /&gt;
==== helper.modify_unit ====&lt;br /&gt;
&lt;br /&gt;
Modifies all the units satisfying the given filter (argument 1) with some WML attributes/objects (argument 2). This is a Lua implementation of the [http://www.wesnoth.org/macro-reference.xhtml MODIFY_UNIT] macro.&lt;br /&gt;
&lt;br /&gt;
 helper.modify_unit({ id=&amp;quot;Delfador&amp;quot; }, { moves=0 })&lt;br /&gt;
&lt;br /&gt;
==== helper.move_unit_fake ====&lt;br /&gt;
&lt;br /&gt;
Fakes the move of a unit satisfying the given filter (argument 1) to the given position (argument 2). This is a Lua implementation of the [http://www.wesnoth.org/macro-reference.xhtml MOVE_UNIT] macro.&lt;br /&gt;
&lt;br /&gt;
 helper.move_unit_fake({ id=&amp;quot;Delfador&amp;quot; }, 14, 8)&lt;br /&gt;
&lt;br /&gt;
==== helper.rand ====&lt;br /&gt;
&lt;br /&gt;
(A shortcut to set_variable's rand= since math.rand is an OOS magnet and therefore disabled.) Pass a string like you would to set_variable's rand=.&lt;br /&gt;
&lt;br /&gt;
create a random unit at (1, 1) on side=1 :&lt;br /&gt;
 wesnoth.put_unit(1, 1, { type = helper.rand(&amp;quot;Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Scout&amp;quot;) })&lt;br /&gt;
&lt;br /&gt;
==== helper.round ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}}Unlike other languages (Python, Perl, Javascript, ...), Lua does not include a round function. This helper function allows rounding numbers, following the &amp;quot;round half away from zero method&amp;quot;, see Wikipedia [[http://en.wikipedia.org/wiki/Rounding_numbers#Round_half_away_from_zero]]. Returns the number rounded to the nearest integer.&lt;br /&gt;
&lt;br /&gt;
 -- this number will be rounded up&lt;br /&gt;
 helper.round(345.67) -- returns 346&lt;br /&gt;
 -- this one will be rounded down&lt;br /&gt;
 helper.round(543.21) -- returns 543&lt;br /&gt;
 -- an integer stays integer&lt;br /&gt;
 helper.round(123) -- returns 123&lt;br /&gt;
 -- works also for negative numbers&lt;br /&gt;
 helper.round(-369.84) -- returns -370&lt;br /&gt;
 helper.round(-246.42) -- returns -246&lt;br /&gt;
&lt;br /&gt;
==== helper.shuffle ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}}This function randomly sorts in place the elements of the table passed as argument, following the Fisher-Yates algorithm. It returns no value.&lt;br /&gt;
'''WARNING:''' this function uses Lua's math.random(), and so it is MP-unsafe. It is provided mainly for AI development, although it should work inside wesnoth.synchronize_choice() as well.&lt;br /&gt;
 local locs = wesnoth.get_locations( { terrain=&amp;quot;G*&amp;quot; } )&lt;br /&gt;
 helper.shuffle( locs )&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Misc&amp;diff=48306</id>
		<title>LuaWML/Misc</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Misc&amp;diff=48306"/>
		<updated>2013-01-03T13:28:06Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added wesnoth.get_time_stamp()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes miscellaneous [[LuaWML]] objects and helpers.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.game_config ====&lt;br /&gt;
&lt;br /&gt;
Contrarily to the other values of the ''wesnoth'' table, ''game_config'' is simply a proxy table. Its fields offer an interface to the global settings of Wesnoth:&lt;br /&gt;
&lt;br /&gt;
* '''version''': string (read only)&lt;br /&gt;
* '''base_income''': integer (read/write)&lt;br /&gt;
* '''village_income''': integer (read/write)&lt;br /&gt;
* '''poison_amount''': integer (read/write)&lt;br /&gt;
* '''rest_heal_amount''': integer (read/write)&lt;br /&gt;
* '''recall_cost''': integer (read/write)&lt;br /&gt;
* '''kill_experience''': integer (read/write)&lt;br /&gt;
* '''last_turn''': integer (read/write) turn limit, maximum number of turns&lt;br /&gt;
* '''debug''': boolean (read only)&lt;br /&gt;
* '''mp_debug''': boolean (read only) {{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
 -- Poison a bit weak? Let's boost it!&lt;br /&gt;
 wesnoth.game_config.poison_amount = 15&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.current ====&lt;br /&gt;
&lt;br /&gt;
As with ''game_config'', ''current'' is a proxy table. Its fields are getter for game-related properties:&lt;br /&gt;
&lt;br /&gt;
* '''side''': integer (read only)&lt;br /&gt;
* '''turn''': integer (read only)&lt;br /&gt;
* '''event_context''': WML table with attributes ''name'', ''x1'', ''y1'', ''x2'', ''y2'', and children ''weapon'', ''second_weapon'', describing the trigger for the current event.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Turn %d, side %d is playing.&amp;quot;, wesnoth.current.turn, wesnoth.current.side))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.synchronize_choice ====&lt;br /&gt;
&lt;br /&gt;
Recovers a WML table that was computed on one client only or was stored in a replay. The actual computation is performed by the function passed as the first argument, assuming that the client is the side currently playing. For all the other clients, the function will not be called. An optional second function can be passed; if present, it will be used instead of the first one when the client happens to be an AI (hence not enable to interact with a user interface).&lt;br /&gt;
&lt;br /&gt;
 local result = wesnoth.synchronize_choice(&lt;br /&gt;
   function()&lt;br /&gt;
     -- Called only on the client handling the current side, if it is a human.&lt;br /&gt;
     local choice = 0&lt;br /&gt;
     wesnoth.show_dialog(&lt;br /&gt;
       some_dialog_cfg, nil,&lt;br /&gt;
       function()&lt;br /&gt;
         choice = wesnoth.get_dialog_value &amp;quot;some_list&amp;quot;&lt;br /&gt;
       end)&lt;br /&gt;
     return { value = choice }&lt;br /&gt;
   end,&lt;br /&gt;
   function()&lt;br /&gt;
     -- Called only on the client handling the current side, if it is an AI.&lt;br /&gt;
     return { value = math.random(some_list_size) }&lt;br /&gt;
   end)&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Selected item: %d&amp;quot;, result.value))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_image_size ====&lt;br /&gt;
&lt;br /&gt;
Returns the width and height of an image.&lt;br /&gt;
&lt;br /&gt;
 local w, h = wesnoth.get_image_size &amp;quot;units/transport/galleon.png&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.compare_versions ====&lt;br /&gt;
&lt;br /&gt;
Takes two versions strings and an operator, returns whether the comparison yields true.&lt;br /&gt;
Follows the same rules like the #ifver preprocessor statement.&lt;br /&gt;
&lt;br /&gt;
 local function version_is_sufficient(required)&lt;br /&gt;
  if not wesnoth.compare_versions then return false end&lt;br /&gt;
  return wesnoth.compare_versions(wesnoth.game_config.version, &amp;quot;&amp;gt;=&amp;quot;, required)&lt;br /&gt;
 end&lt;br /&gt;
 local required = &amp;quot;1.9.6+svn&amp;quot;&lt;br /&gt;
 if not version_is_sufficient(required) then wesnoth.message(string.format(&lt;br /&gt;
  &amp;quot;Your BfW version is insufficient, please get BfW %s or greater!&amp;quot;, required)) end&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.have_file ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}}Checks if the file (not necessarily a Lua file) or the directory passed as argument exists. Returns true if the file exists, false otherwise. Follows the same rules like the #ifhave preprocessor statement.&lt;br /&gt;
&lt;br /&gt;
 -- Does the user have installed the UMC Music Book 1?&lt;br /&gt;
 local umc_music = wesnoth.have_file( &amp;quot;~add-ons/UMC_Music_Book_1/_main.cfg&amp;quot; )&lt;br /&gt;
 -- and if we want to check for the folder?&lt;br /&gt;
 local music_folder = wesnoth.have_file( &amp;quot;~add-ons/UMC_Music_Book_1/&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.debug ====&lt;br /&gt;
&lt;br /&gt;
Takes a userdata with metatable wml object or a wml table and dumps its content into a pretty string.&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;number&amp;quot;, 100)&lt;br /&gt;
 local vconfig = wesnoth.tovconfig({ key = &amp;quot;$number&amp;quot;, another_key = true,&lt;br /&gt;
     {&amp;quot;a_subtag&amp;quot;, { a_key_in_the_subtag = &amp;quot;foo&amp;quot; }}&lt;br /&gt;
 })&lt;br /&gt;
 wesnoth.message(wesnoth.debug(vconfig))&lt;br /&gt;
 wesnoth.message(wesnoth.debug(vconfig.__literal))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_time_stamp ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}}This function retrieves the current time stamp, that is the amount of milliseconds passed from when the SDL library was initialized. It takes no arguments and returns an integer.&lt;br /&gt;
'''WARNING:''' this function uses the same code as [set_variable] time=stamp, and so it is MP-unsafe. It is provided only for benchmark purposes and AI development, although it should work inside wesnoth.synchronize_choice() as well.&lt;br /&gt;
 local stamp = wesnoth.get_time_stamp()&lt;br /&gt;
&lt;br /&gt;
==== helper.set_wml_tag_metatable ====&lt;br /&gt;
&lt;br /&gt;
Sets the metable of a table so that it can be used to create subtags with less brackets. Returns the table. The fields of the table are simple wrappers around table constructors.&lt;br /&gt;
&lt;br /&gt;
 T = helper.set_wml_tag_metatable {}&lt;br /&gt;
 W.event { name = &amp;quot;new turn&amp;quot;, T.message { speaker = &amp;quot;narrator&amp;quot;, message = &amp;quot;?&amp;quot; } }&lt;br /&gt;
&lt;br /&gt;
==== helper.modify_unit ====&lt;br /&gt;
&lt;br /&gt;
Modifies all the units satisfying the given filter (argument 1) with some WML attributes/objects (argument 2). This is a Lua implementation of the [http://www.wesnoth.org/macro-reference.xhtml MODIFY_UNIT] macro.&lt;br /&gt;
&lt;br /&gt;
 helper.modify_unit({ id=&amp;quot;Delfador&amp;quot; }, { moves=0 })&lt;br /&gt;
&lt;br /&gt;
==== helper.move_unit_fake ====&lt;br /&gt;
&lt;br /&gt;
Fakes the move of a unit satisfying the given filter (argument 1) to the given position (argument 2). This is a Lua implementation of the [http://www.wesnoth.org/macro-reference.xhtml MOVE_UNIT] macro.&lt;br /&gt;
&lt;br /&gt;
 helper.move_unit_fake({ id=&amp;quot;Delfador&amp;quot; }, 14, 8)&lt;br /&gt;
&lt;br /&gt;
==== helper.rand ====&lt;br /&gt;
&lt;br /&gt;
(A shortcut to set_variable's rand= since math.rand is an OOS magnet and therefore disabled.) Pass a string like you would to set_variable's rand=.&lt;br /&gt;
&lt;br /&gt;
create a random unit at (1, 1) on side=1 :&lt;br /&gt;
 wesnoth.put_unit(1, 1, { type = helper.rand(&amp;quot;Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Scout&amp;quot;) })&lt;br /&gt;
&lt;br /&gt;
==== helper.round ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}}Unlike other languages (Python, Perl, Javascript, ...), Lua does not include a round function. This helper function allows rounding numbers, following the &amp;quot;round half away from zero method&amp;quot;, see Wikipedia [[http://en.wikipedia.org/wiki/Rounding_numbers#Round_half_away_from_zero]]. Returns the number rounded to the nearest integer.&lt;br /&gt;
&lt;br /&gt;
 -- this number will be rounded up&lt;br /&gt;
 helper.round(345.67) -- returns 346&lt;br /&gt;
 -- this one will be rounded down&lt;br /&gt;
 helper.round(543.21) -- returns 543&lt;br /&gt;
 -- an integer stays integer&lt;br /&gt;
 helper.round(123) -- returns 123&lt;br /&gt;
 -- works also for negative numbers&lt;br /&gt;
 helper.round(-369.84) -- returns -370&lt;br /&gt;
 helper.round(-246.42) -- returns -246&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=48058</id>
		<title>LuaWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=48058"/>
		<updated>2012-12-15T17:57:30Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* Miscellaneous */ Added link to wesnoth.have_file() and DevFeature template to helper.round()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
== The '''[lua]''' tag ==&lt;br /&gt;
&lt;br /&gt;
This tag is a part of [[ActionWML]], thus can be used inside [event] and at other places where [[ActionWML]] can be used. It makes it possible to write actions with the [http://www.lua.org Lua 5.2] language.&lt;br /&gt;
&lt;br /&gt;
The tag supports only the '''code''' key, which is a string containing the Lua scripts. Since Lua makes usage of the quotes and the { and } symbols, it is certainly wise to enclose the script between stronger quotes, as they prevent the preprocessor from performing macro expansion and tokenization.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; wesnoth.message &amp;quot;Hello World!&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
The Lua kernel can also be accessed from the [[CommandMode|command mode]]:&lt;br /&gt;
&lt;br /&gt;
 :lua local u = wesnoth.get_units({ id = &amp;quot;Konrad&amp;quot; })[1]; u.moves = 5&lt;br /&gt;
&lt;br /&gt;
The '''[args]''' sub-tag can be used to pass a WML object to the script via its variadic local variable &amp;quot;'''...'''&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; local t = ...; wesnoth.message(tostring(t.text)) &amp;gt;&amp;gt;&lt;br /&gt;
     [args]&lt;br /&gt;
         text = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/args]&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
== Global environment ==&lt;br /&gt;
&lt;br /&gt;
All the Lua scripts of a scenario share the same global environment (aka Lua state). For instance, a function defined in an event can be used in all the events that happen after it.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             function narrator(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
In the example above, the redundant structure could be hidden behind macros. But it may be better to simply define a new WML tag.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             -- The function is now local, since its name does not have to be&lt;br /&gt;
             -- visible outside this Lua scripts.&lt;br /&gt;
             local function handler(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
             -- Create a new tag named [narrator].&lt;br /&gt;
             wesnoth.register_wml_action(&amp;quot;narrator&amp;quot;, handler)&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
The global environment is not preserved over save/load cycles. Therefore, storing values in the global environment is generally a bad idea (unless it has been redirected to WML variables, see [[LuaWML:Variables#set_wml_var_metatable|helper.set_wml_var_metatable]]). The only time assigning global variables (including function definitions) makes sense is during a [[EventWML#Predefined 'name' Key Values|preload]] event, as this event is always run. Therefore, helper functions defined at that time will be available to all the later scripts.&lt;br /&gt;
&lt;br /&gt;
The global environment initially contains the following modules: [http://www.lua.org/manual/5.1/manual.html#5.1 basic] (no name), [http://www.lua.org/manual/5.1/manual.html#5.4 string], [http://www.lua.org/manual/5.1/manual.html#5.5 table], and [http://www.lua.org/manual/5.1/manual.html#5.6 math]. A '''wesnoth''' module is also available, it provides access to the [[#Interface to the C++ engine|C++ engine]]. Besides, the functions clock, date, time and difftime from the [http://www.lua.org/manual/5.1/manual.html#5.8 os] library (Keep in mind that they aren't multiplayer- and replay-save.) and traceback from the [http://www.lua.org/manual/5.1/manual.html#5.9 debug] library are also available.&lt;br /&gt;
&lt;br /&gt;
At the start of a script, the variadic local variable '''...''' (three dots) is a proxy table representing [[#Encoding WML objects into Lua tables|WML data]]. This table is the content of the '''[args]''' sub-tag of the '''[lua]''' tag, if any.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following WML event is taken from Wesnoth' tutorial. It will serve as an example to present how Lua scripts are embedded into Wesnoth. The event is fired whenever a unit from side 1 (that is, the hero controlled by the user) moves to a tile that is not the one set in the WML variable ''target_hex''.&lt;br /&gt;
&lt;br /&gt;
 # General catch for them moving to the wrong place.&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [if]&lt;br /&gt;
         [variable]&lt;br /&gt;
             name=target_hex.is_set&lt;br /&gt;
             equals=yes&lt;br /&gt;
         [/variable]&lt;br /&gt;
         [then]&lt;br /&gt;
             [if]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=x1&lt;br /&gt;
                     equals=$target_hex.x&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=y1&lt;br /&gt;
                     equals=$target_hex.y&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [then]&lt;br /&gt;
                 [/then]&lt;br /&gt;
                 [else]&lt;br /&gt;
                     [redraw][/redraw]&lt;br /&gt;
                     [message]&lt;br /&gt;
                         speaker=narrator&lt;br /&gt;
                         message=_ &amp;quot;*Oops!&lt;br /&gt;
 You moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot; +&lt;br /&gt;
                         _ &amp;quot;&lt;br /&gt;
 *Left click or press spacebar to continue...&amp;quot;&lt;br /&gt;
                     [/message]&lt;br /&gt;
                 [/else]&lt;br /&gt;
             [/if]&lt;br /&gt;
         [/then]&lt;br /&gt;
     [/if]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
A Lua script that performs the same action is presented below.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             local event_data = wesnoth.current.event_context&lt;br /&gt;
             if target_hex.is_set and&lt;br /&gt;
                (event_data.x1 ~= target_hex.x or event_data.y1 ~= target_hex.y)&lt;br /&gt;
             then&lt;br /&gt;
                 W.redraw()&lt;br /&gt;
                 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Here is a more detailed explanation of the Lua code. Its first line&lt;br /&gt;
&lt;br /&gt;
 local event_data = wesnoth.current.event_context&lt;br /&gt;
&lt;br /&gt;
puts the event data into the ''event_data'' local variable. Since it is a ''moveto'' event, the ''event_data'' table contains the destination of the unit in the ''x1'' and ''y1'' fields.&lt;br /&gt;
&lt;br /&gt;
The next two lines then test&lt;br /&gt;
&lt;br /&gt;
 if target_hex.is_set and&lt;br /&gt;
    (event_data.x1 ~= target_hex.x or event_data.y1 ~= target_hex.y)&lt;br /&gt;
&lt;br /&gt;
whether the variable ''target_hex'' matches the event parameters. Since ''target_hex'' is not a local variable, it is taken from the global environment (a table implicitly named ''_G'', so it is actually ''_G.target_hex''). The global environment is not persistent, so it cannot be used to store data. In order to make it useful, it was mapped to the storage of WML variables by the following ''preload'' event.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             -- skipping some other initializations&lt;br /&gt;
             -- ...&lt;br /&gt;
             H.set_wml_var_metatable(_G)&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Without a prelude redirecting ''_G'', the conditional would have been written&lt;br /&gt;
&lt;br /&gt;
 if wesnoth.get_variable(&amp;quot;target_hex.is_set&amp;quot;) and&lt;br /&gt;
    (event_data.x1 ~= wesnoth.get_variable(&amp;quot;target_hex.x&amp;quot;) or event_data.y1 ~= wesnoth.get_variable(&amp;quot;target_hex.y&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The body of the conditional then performs the [[InterfaceActionsWML#Other interface tags|[redraw]]] action.&lt;br /&gt;
&lt;br /&gt;
 W.redraw()&lt;br /&gt;
&lt;br /&gt;
Again, this short syntax is made possible by a line of the prelude that makes ''W'' a proxy for performing WML actions.&lt;br /&gt;
&lt;br /&gt;
 W = H.set_wml_action_metatable {}&lt;br /&gt;
&lt;br /&gt;
Without this shortcut, the first statement would have been written&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;redraw&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Finally the script displays a message by&lt;br /&gt;
&lt;br /&gt;
 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The ''narrator_says'' function is defined in the prelude too, since the construct behind it occurs several times in the tutorial. In plain WML, macros would have been used instead. The definition of the function is&lt;br /&gt;
&lt;br /&gt;
 function narrator_says(m)&lt;br /&gt;
     W.message { speaker=&amp;quot;narrator&amp;quot;,&lt;br /&gt;
                 message = m .. _ &amp;quot;\n*Left click or press spacebar to continue...&amp;quot; }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The function fires a [[InterfaceActionsWML#.5Bmessage.5D|[message]]] action and passes a WML object containing the usual two fields to it. The second field is initialized by concatenating the function argument with another string. Both strings are prefixed by the ''_'' symbol to mark them as translatable. (Note that ''_'' is just a unary function, not a keyword.) Again, this is made possible by a specific line of the prelude:&lt;br /&gt;
&lt;br /&gt;
 _ = wesnoth.textdomain &amp;quot;wesnoth-tutorial&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A longer translation of the tutorial is available at [https://gna.org/patch/download.php?file_id=5483].&lt;br /&gt;
&lt;br /&gt;
== Interface to the engine and helper functions ==&lt;br /&gt;
&lt;br /&gt;
Functionalities of the game engine are available through the functions of the '''wesnoth''' global table. Some of these functions return proxy tables. Writes to fields marked &amp;quot;read-only&amp;quot; are ignored. The '''__cfg''' fields return plain tables; in particular, writes do not modify the original object, and reads return the values from the time the dump was performed.&lt;br /&gt;
&lt;br /&gt;
Some helper functions are provided by the '''lua/helper.lua''' library. They are stored inside a table that is returned when loading the library with [[LuaWML:Files#wesnoth.require|wesnoth.require]].&lt;br /&gt;
&lt;br /&gt;
 helper = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== WML variables ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]]&lt;br /&gt;
* [[LuaWML:Variables#helper.set_wml_var_metatable|helper.set_wml_var_metatable]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_child|helper.get_child]]&lt;br /&gt;
* [[LuaWML:Variables#helper.child_range|helper.child_range]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_array|helper.get_variable_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_proxy_array|helper.get_variable_proxy_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.set_variable_array|helper.set_variable_array]]&lt;br /&gt;
&lt;br /&gt;
=== Events and WML actions ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire|wesnoth.fire]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.wml_actions|wesnoth.wml_actions]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.game_events|wesnoth.game_events]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire_event|wesnoth.fire_event]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.eval_conditional|wesnoth.eval_conditional]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.tovconfig|wesnoth.tovconfig]]&lt;br /&gt;
* [[LuaWML:Events#helper.set_wml_action_metatable|helper.set_wml_action_metatable]]&lt;br /&gt;
* [[LuaWML:Events#helper.wml_error|helper.wml_error]]&lt;br /&gt;
* [[LuaWML:Events#helper.literal|helper.literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.parsed|helper.parsed]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_literal|helper.shallow_literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_parsed|helper.shallow_parsed]]&lt;br /&gt;
&lt;br /&gt;
=== User interface ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Display#wesnoth.message|wesnoth.message]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.clear_messages|wesnoth.clear_messages]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.textdomain|wesnoth.textdomain]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.delay|wesnoth.delay]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.float_label|wesnoth.float_label]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_hex|wesnoth.select_hex]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.scroll_to_tile|wesnoth.scroll_to_tile]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.lock_view|wesnoth.lock_view]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.view_locked|wesnoth.view_locked]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.play_sound|wesnoth.play_sound]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_music|wesnoth.set_music]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_dialog|wesnoth.show_dialog]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_value|wesnoth.set_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_dialog_value|wesnoth.get_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_active|wesnoth.set_dialog_active]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_callback|wesnoth.set_dialog_callback]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_canvas|wesnoth.set_dialog_canvas]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_displayed_unit|wesnoth.get_displayed_unit]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.theme_items|wesnoth.theme_items]]&lt;br /&gt;
* [[LuaWML:Display#helper.get_user_choice|helper.get_user_choice]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_time_of_day|wesnoth.get_time_of_day]]&lt;br /&gt;
&lt;br /&gt;
=== Map and terrains ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_map_size|wesnoth.get_map_size]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain|wesnoth.get_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.set_terrain|wesnoth.set_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain_info|wesnoth.get_terrain_info]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_selected_tile|wesnoth.get_selected_tile]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_locations|wesnoth.get_locations]]&lt;br /&gt;
* {{DevFeature1.11}}[[LuaWML:Tiles#wesnoth.get_villages|wesnoth.get_villages]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.match_location|wesnoth.match_location]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_tile_overlay|wesnoth.add_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_tile_overlay|wesnoth.remove_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_image|items.place_image]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_halo|items.place_halo]]&lt;br /&gt;
* [[LuaWML:Tiles#items.remove|items.remove]]&lt;br /&gt;
&lt;br /&gt;
=== Units ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_units|wesnoth.get_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit|wesnoth.get_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.match_unit|wesnoth.match_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_unit|wesnoth.put_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_recall_units|wesnoth.get_recall_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_recall_unit|wesnoth.put_recall_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.create_unit|wesnoth.create_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.copy_unit|wesnoth.copy_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.extract_unit|wesnoth.extract_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_modification|wesnoth.add_modification]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_resistance|wesnoth.unit_resistance]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_defense|wesnoth.unit_defense]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_movement_cost|wesnoth.unit_movement_cost]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_ability|wesnoth.unit_ability]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type_ids|wesnoth.get_unit_type_ids]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type|wesnoth.get_unit_type]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_types|wesnoth.unit_types]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.races|wesnoth.races]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_traits|wesnoth.get_traits]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.simulate_combat|wesnoth.simulate_combat]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.transform_unit|wesnoth.transform_unit]]&lt;br /&gt;
&lt;br /&gt;
=== Sides ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_side|wesnoth.get_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.sides|wesnoth.sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_sides|wesnoth.get_sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_village_owner|wesnoth.get_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.set_village_owner|wesnoth.set_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.is_enemy|wesnoth.is_enemy]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.match_side|wesnoth.match_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_starting_location|wesnoth.get_starting_location]]&lt;br /&gt;
* [[LuaWML:Sides#helper.all_teams|helper.all_teams]]&lt;br /&gt;
&lt;br /&gt;
=== Pathfinder ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_path|wesnoth.find_path]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_vacant_tile|wesnoth.find_vacant_tile]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_reach|wesnoth.find_reach]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.distance_between|helper.distance_between]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.adjacent_tiles|helper.adjacent_tiles]]&lt;br /&gt;
&lt;br /&gt;
=== Lua files ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Files#wesnoth.dofile|wesnoth.dofile]]&lt;br /&gt;
* [[LuaWML:Files#wesnoth.require|wesnoth.require]]&lt;br /&gt;
&lt;br /&gt;
=== Location sets ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Location_set#location_set.create|location_set.create]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_pairs|location_set.of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_wml_var|location_set.of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:empty|location_set:empty]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:size|location_set:size]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:clear|location_set:clear]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:get|location_set:get]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:insert|location_set:insert]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:remove|location_set:remove]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_pairs|location_set:of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_wml_var|location_set:of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_pairs|location_set:to_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_stable_pairs|location_set:to_stable_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_wml_var|location_set:to_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union|location_set:union]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter|location_set:inter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:iter|location_set:iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:stable_iter|location_set:stable_iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:filter|location_set:filter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union_merge|location_set:union_merge]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter_merge|location_set:inter_merge]]&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.game_config|wesnoth.game_config]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.current|wesnoth.current]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.synchronize_choice|wesnoth.synchronize_choice]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_image_size|wesnoth.get_image_size]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compare_versions|wesnoth.compare_versions]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.have_file|wesnoth.have_file]] {{DevFeature1.11}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.debug|wesnoth.debug]]&lt;br /&gt;
* [[LuaWML:Misc#helper.set_wml_tag_metatable|helper.set_wml_tag_metatable]]&lt;br /&gt;
* [[LuaWML:Misc#helper.modify_unit|helper.modify_unit]]&lt;br /&gt;
* [[LuaWML:Misc#helper.move_unit_fake|helper.move_unit_fake]]&lt;br /&gt;
* [[LuaWML:Misc#helper.rand|helper.rand]]&lt;br /&gt;
* [[LuaWML:Misc#helper.round|helper.round]] {{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
== Encoding WML objects into Lua tables ==&lt;br /&gt;
&lt;br /&gt;
Function [[LuaWML:Events#wesnoth.fire|wesnoth.fire]] expects a table representing a WML object as its second argument (if needed). Function [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]] allows to modify whole WML objects, again by passing it a table. Function [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]] transforms a WML object into a table, if its second argument is not set to ''true''. All these tables have the same format.&lt;br /&gt;
&lt;br /&gt;
Scalar fields are transformed into WML attributes. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     a_bool = true,&lt;br /&gt;
     an_int = 42,&lt;br /&gt;
     a_float = 1.25,&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;,&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     a_bool = &amp;quot;yes&amp;quot;&lt;br /&gt;
     an_int = &amp;quot;42&amp;quot;&lt;br /&gt;
     a_float = &amp;quot;1.25&amp;quot;&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
WML child objects are not stored as Lua named fields, since several of them can have the same tag. Moreover, their tags can conflict with the attribute keys. So child objects are stored as pairs string + table in the unnamed fields in definition order. This means that for every subtag appearing in the wml code there is an additional table &amp;quot;layer&amp;quot; in the corresponding WML table of the form {[1] = &amp;quot;tag_name&amp;quot;, [2] = {}} which is equivalent to {&amp;quot;tag_name&amp;quot;, {}}. [1] etc are the unnamed fields (as opposed to wml attributes). The table under [2] in this subtable then holds the wml attributes from inside the wml subtag. So every subtag other than the toplevel tag corresponds to two nested tables each. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { v = 1, w = 2 } },&lt;br /&gt;
     { &amp;quot;foo&amp;quot;, { x = false } },&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     { &amp;quot;foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     foo = 42&lt;br /&gt;
     [bar]&lt;br /&gt;
         v = 1&lt;br /&gt;
         w = 2&lt;br /&gt;
     [/bar]&lt;br /&gt;
     [foo]&lt;br /&gt;
         x = no&lt;br /&gt;
     [/foo]&lt;br /&gt;
     [bar]&lt;br /&gt;
         y = foo&lt;br /&gt;
     [bar]&lt;br /&gt;
     [foobar]&lt;br /&gt;
         z = 5&lt;br /&gt;
         [barfoo]&lt;br /&gt;
         [/barfoo]&lt;br /&gt;
     [/foobar]&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
Both tables above are also equivalent to this WML table, where all unnamed fields are displayed:&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     [1] = { [1] = &amp;quot;bar&amp;quot;, [2] = { v = 1, w = 2 } },&lt;br /&gt;
     [2] = { [1] = &amp;quot;foo&amp;quot;, [2] = { x = false } },&lt;br /&gt;
     [3] = { [1] = &amp;quot;bar&amp;quot;, [2] = { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     [4] = { [1] = &amp;quot;foobar&amp;quot;, [2] = { z = 5, [1] = { [1] = &amp;quot;barfoo&amp;quot;, [2] = {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
So assuming ''cfg'' contains the above WML object, the following accesses are possible:&lt;br /&gt;
&lt;br /&gt;
 a_int = cfg.foo        -- &amp;quot;dummy.foo&amp;quot;, 42&lt;br /&gt;
 a_string = cfg[3][2].y -- &amp;quot;dummy.bar[1].y&amp;quot;, &amp;quot;foo&amp;quot;&lt;br /&gt;
 a_table = cfg[4][2]    -- &amp;quot;dummy.foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } }&lt;br /&gt;
&lt;br /&gt;
Consider using the [[LuaWML:Variables#helper.get_child|helper.get_child]] and [[LuaWML:Variables#helper.child_range|helper.child_range]] to ease the access to subtags.&lt;br /&gt;
&lt;br /&gt;
Functions registered by [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]] receive their data in a userdata object which has the exact same structure as above. It is read-only however. Accessing fields or children performs variable substitution on the fly. Its '''__parsed''' and '''__literal''' fields provide translations to plain tables (therefore writable). '''__literal''' returns the original text of the data (including dollar symbols in attributes and [insert_tag] children), while '''__parsed''' performs a variable substitution.&lt;br /&gt;
&lt;br /&gt;
For instance, if you cannot stand any longer the fact that '''first_time_only''' is set to yes by default for the '''[event]''' tag, you can redefine it. But we have to be careful not to cause variable substitution, since the engine would perform a second variable substitution afterwards.&lt;br /&gt;
&lt;br /&gt;
 local old_event_handler&lt;br /&gt;
 old_event_handler = register_wml_action(&amp;quot;event&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         -- Get the plain text from the user.&lt;br /&gt;
         local new_cfg = cfg.__literal&lt;br /&gt;
         -- The expression below is equivalent to cfg.__parsed.first_time_only,&lt;br /&gt;
         -- only faster. It is needed, since the first_time_only attribute may&lt;br /&gt;
         -- reference variables.&lt;br /&gt;
         local first = cfg.first_time_only&lt;br /&gt;
         -- Modify the default behavior of first_time_only.&lt;br /&gt;
         if first == nil then first = false end&lt;br /&gt;
         new_cfg.first_time_only = first&lt;br /&gt;
         -- Call the engine handler.&lt;br /&gt;
         old_event_handler(new_cfg)&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Note that, since the object is a userdata and not a table, '''pairs''' and '''ipairs''' are unfortunately not usable on it. So scripts have to work at a lower level. For instance, the following function returns the first sub-tag with a given name and it works both on WML tables and WML userdata:&lt;br /&gt;
&lt;br /&gt;
 function get_child(cfg, name)&lt;br /&gt;
     for i = 1, #cfg do&lt;br /&gt;
         local v = cfg[i]&lt;br /&gt;
         if v[1] == name then return v[2] end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Another approach for handling userdata and tables in the same way, would be to convert the former into the latter beforehand:&lt;br /&gt;
&lt;br /&gt;
 if getmetatable(cfg) == &amp;quot;wml object&amp;quot; then cfg = cfg.__parsed end&lt;br /&gt;
&lt;br /&gt;
The WML userdata provides two other special fields: '''__shallow_parsed''' and '''__shallow_literal'''. They return a table corresponding to the WML userdata with variable substitution performed on the attributes (or not). [insert_tag] tags have also been parsed, so the number of children is faithful. But contrarily to '''__parsed''' and '''__literal''', the process is not recursive: all the children are still WML userdata and variable substitution can still happen for them. These shallow translators are meant as optimized versions of the deep ones, when only the toplevel attributes need to be writable.&lt;br /&gt;
&lt;br /&gt;
== Skeleton of a preload event ==&lt;br /&gt;
&lt;br /&gt;
The following event is a skeleton for a prelude enabling Lua in your WML events. It creates a table ''H'' containing the functions from helper.lua and a table ''W'' that serves as a proxy for firing WML actions. It also sets up the global environment so that any access to an undefined global variable is redirected to the persistent WML storage.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             W = H.set_wml_action_metatable {}&lt;br /&gt;
             _ = wesnoth.textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
             -- Define your global constants here.&lt;br /&gt;
             -- ...&lt;br /&gt;
 &lt;br /&gt;
             H.set_wml_var_metatable(_G)&lt;br /&gt;
 &lt;br /&gt;
             -- Define your global functions here.&lt;br /&gt;
             -- ...&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
It may be worth putting the whole Lua script above inside a separate file and having the ''preload'' event load it:&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; wesnoth.dofile &amp;quot;~add-ons/Whatever/file.lua&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
== Remarks ==&lt;br /&gt;
&lt;br /&gt;
The math.random function is not safe for replays and multiplayer games, since the random values will be different each time and on all the clients. Instead, the Lua code should rely on the [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] tag to synchronize random values.&lt;br /&gt;
&lt;br /&gt;
 function random(min, max)&lt;br /&gt;
   if not max then min, max = 1, min end&lt;br /&gt;
   wesnoth.fire(&amp;quot;set_variable&amp;quot;, { name = &amp;quot;LUA_random&amp;quot;, rand = string.format(&amp;quot;%d..%d&amp;quot;, min, max) })&lt;br /&gt;
   local res = wesnoth.get_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   wesnoth.set_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   return res&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference|*]]&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Misc&amp;diff=47551</id>
		<title>LuaWML/Misc</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Misc&amp;diff=47551"/>
		<updated>2012-10-08T18:32:33Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added wesnoth.have_file()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes miscellaneous [[LuaWML]] objects and helpers.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.game_config ====&lt;br /&gt;
&lt;br /&gt;
Contrarily to the other values of the ''wesnoth'' table, ''game_config'' is simply a proxy table. Its fields offer an interface to the global settings of Wesnoth:&lt;br /&gt;
&lt;br /&gt;
* '''version''': string (read only)&lt;br /&gt;
* '''base_income''': integer (read/write)&lt;br /&gt;
* '''village_income''': integer (read/write)&lt;br /&gt;
* '''poison_amount''': integer (read/write)&lt;br /&gt;
* '''rest_heal_amount''': integer (read/write)&lt;br /&gt;
* '''recall_cost''': integer (read/write)&lt;br /&gt;
* '''kill_experience''': integer (read/write)&lt;br /&gt;
* '''last_turn''': integer (read/write) turn limit, maximum number of turns&lt;br /&gt;
* '''debug''': boolean (read only)&lt;br /&gt;
* '''mp_debug''': boolean (read only) {{DevFeature1.11}}&lt;br /&gt;
&lt;br /&gt;
 -- Poison a bit weak? Let's boost it!&lt;br /&gt;
 wesnoth.game_config.poison_amount = 15&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.current ====&lt;br /&gt;
&lt;br /&gt;
As with ''game_config'', ''current'' is a proxy table. Its fields are getter for game-related properties:&lt;br /&gt;
&lt;br /&gt;
* '''side''': integer (read only)&lt;br /&gt;
* '''turn''': integer (read only)&lt;br /&gt;
* '''event_context''': WML table with attributes ''name'', ''x1'', ''y1'', ''x2'', ''y2'', and children ''weapon'', ''second_weapon'', describing the trigger for the current event.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Turn %d, side %d is playing.&amp;quot;, wesnoth.current.turn, wesnoth.current.side))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.synchronize_choice ====&lt;br /&gt;
&lt;br /&gt;
Recovers a WML table that was computed on one client only or was stored in a replay. The actual computation is performed by the function passed as the first argument, assuming that the client is the side currently playing. For all the other clients, the function will not be called. An optional second function can be passed; if present, it will be used instead of the first one when the client happens to be an AI (hence not enable to interact with a user interface).&lt;br /&gt;
&lt;br /&gt;
 local result = wesnoth.synchronize_choice(&lt;br /&gt;
   function()&lt;br /&gt;
     -- Called only on the client handling the current side, if it is a human.&lt;br /&gt;
     local choice = 0&lt;br /&gt;
     wesnoth.show_dialog(&lt;br /&gt;
       some_dialog_cfg, nil,&lt;br /&gt;
       function()&lt;br /&gt;
         choice = wesnoth.get_dialog_value &amp;quot;some_list&amp;quot;&lt;br /&gt;
       end)&lt;br /&gt;
     return { value = choice }&lt;br /&gt;
   end,&lt;br /&gt;
   function()&lt;br /&gt;
     -- Called only on the client handling the current side, if it is an AI.&lt;br /&gt;
     return { value = math.random(some_list_size) }&lt;br /&gt;
   end)&lt;br /&gt;
 wesnoth.message(string.format(&amp;quot;Selected item: %d&amp;quot;, result.value))&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_image_size ====&lt;br /&gt;
&lt;br /&gt;
Returns the width and height of an image.&lt;br /&gt;
&lt;br /&gt;
 local w, h = wesnoth.get_image_size &amp;quot;units/transport/galleon.png&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.compare_versions ====&lt;br /&gt;
&lt;br /&gt;
Takes two versions strings and an operator, returns whether the comparison yields true.&lt;br /&gt;
Follows the same rules like the #ifver preprocessor statement.&lt;br /&gt;
&lt;br /&gt;
 local function version_is_sufficient(required)&lt;br /&gt;
  if not wesnoth.compare_versions then return false end&lt;br /&gt;
  return wesnoth.compare_versions(wesnoth.game_config.version, &amp;quot;&amp;gt;=&amp;quot;, required)&lt;br /&gt;
 end&lt;br /&gt;
 local required = &amp;quot;1.9.6+svn&amp;quot;&lt;br /&gt;
 if not version_is_sufficient(required) then wesnoth.message(string.format(&lt;br /&gt;
  &amp;quot;Your BfW version is insufficient, please get BfW %s or greater!&amp;quot;, required)) end&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.have_file ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}}Checks if the file (not necessarily a Lua file) or the directory passed as argument exists. Returns true if the file exists, false otherwise. Follows the same rules like the #ifhave preprocessor statement.&lt;br /&gt;
&lt;br /&gt;
 -- Does the user have installed the UMC Music Book 1?&lt;br /&gt;
 local umc_music = wesnoth.have_file( &amp;quot;~add-ons/UMC_Music_Book_1/_main.cfg&amp;quot; )&lt;br /&gt;
 -- and if we want to check for the folder?&lt;br /&gt;
 local music_folder = wesnoth.have_file( &amp;quot;~add-ons/UMC_Music_Book_1/&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.debug ====&lt;br /&gt;
&lt;br /&gt;
Takes a userdata with metatable wml object or a wml table and dumps its content into a pretty string.&lt;br /&gt;
 wesnoth.set_variable(&amp;quot;number&amp;quot;, 100)&lt;br /&gt;
 local vconfig = wesnoth.tovconfig({ key = &amp;quot;$number&amp;quot;, another_key = true,&lt;br /&gt;
     {&amp;quot;a_subtag&amp;quot;, { a_key_in_the_subtag = &amp;quot;foo&amp;quot; }}&lt;br /&gt;
 })&lt;br /&gt;
 wesnoth.message(wesnoth.debug(vconfig))&lt;br /&gt;
 wesnoth.message(wesnoth.debug(vconfig.__literal))&lt;br /&gt;
&lt;br /&gt;
==== helper.set_wml_tag_metatable ====&lt;br /&gt;
&lt;br /&gt;
Sets the metable of a table so that it can be used to create subtags with less brackets. Returns the table. The fields of the table are simple wrappers around table constructors.&lt;br /&gt;
&lt;br /&gt;
 T = helper.set_wml_tag_metatable {}&lt;br /&gt;
 W.event { name = &amp;quot;new turn&amp;quot;, T.message { speaker = &amp;quot;narrator&amp;quot;, message = &amp;quot;?&amp;quot; } }&lt;br /&gt;
&lt;br /&gt;
==== helper.modify_unit ====&lt;br /&gt;
&lt;br /&gt;
Modifies all the units satisfying the given filter (argument 1) with some WML attributes/objects (argument 2). This is a Lua implementation of the [http://www.wesnoth.org/macro-reference.xhtml MODIFY_UNIT] macro.&lt;br /&gt;
&lt;br /&gt;
 helper.modify_unit({ id=&amp;quot;Delfador&amp;quot; }, { moves=0 })&lt;br /&gt;
&lt;br /&gt;
==== helper.move_unit_fake ====&lt;br /&gt;
&lt;br /&gt;
Fakes the move of a unit satisfying the given filter (argument 1) to the given position (argument 2). This is a Lua implementation of the [http://www.wesnoth.org/macro-reference.xhtml MOVE_UNIT] macro.&lt;br /&gt;
&lt;br /&gt;
 helper.move_unit_fake({ id=&amp;quot;Delfador&amp;quot; }, 14, 8)&lt;br /&gt;
&lt;br /&gt;
==== helper.rand ====&lt;br /&gt;
&lt;br /&gt;
(A shortcut to set_variable's rand= since math.rand is an OOS magnet and therefore disabled.) Pass a string like you would to set_variable's rand=.&lt;br /&gt;
&lt;br /&gt;
create a random unit at (1, 1) on side=1 :&lt;br /&gt;
 wesnoth.put_unit(1, 1, { type = helper.rand(&amp;quot;Dwarvish Fighter,Dwarvish Thunderer,Dwarvish Scout&amp;quot;) })&lt;br /&gt;
&lt;br /&gt;
==== helper.round ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}}Unlike other languages (Python, Perl, Javascript, ...), Lua does not include a round function. This helper function allows rounding numbers, following the &amp;quot;round half away from zero method&amp;quot;, see Wikipedia [[http://en.wikipedia.org/wiki/Rounding_numbers#Round_half_away_from_zero]]. Returns the number rounded to the nearest integer.&lt;br /&gt;
&lt;br /&gt;
 -- this number will be rounded up&lt;br /&gt;
 helper.round(345.67) -- returns 346&lt;br /&gt;
 -- this one will be rounded down&lt;br /&gt;
 helper.round(543.21) -- returns 543&lt;br /&gt;
 -- an integer stays integer&lt;br /&gt;
 helper.round(123) -- returns 123&lt;br /&gt;
 -- works also for negative numbers&lt;br /&gt;
 helper.round(-369.84) -- returns -370&lt;br /&gt;
 helper.round(-246.42) -- returns -246&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=EffectWML&amp;diff=47226</id>
		<title>EffectWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=EffectWML&amp;diff=47226"/>
		<updated>2012-09-14T20:33:24Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added [effect] apply_to=overlay&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
The tag [effect] is used to describe one modification to a unit. Any number of [effect] tags can be used to describe a complete modification. Modifications are permanent changes to a unit; currently there is no way of removing a modification.&lt;br /&gt;
&lt;br /&gt;
The following keys and subtags are always recognized:&lt;br /&gt;
* '''[filter]''': only apply this effect if the affected unit matches. See [[StandardUnitFilter]] for details.&lt;br /&gt;
* '''unit_type''': only apply this effect if the affected unit's type name matches the value. (can be a list)&lt;br /&gt;
* '''unit_gender''': only apply this effect if the affected unit's gender name matches the value. (can be a list)&lt;br /&gt;
* '''times''': describes how many times the effect is applied. The default is to apply the effect once. Other possible value : &amp;quot;per level&amp;quot; which means that the effect is applied level times, where level is the unit level.&lt;br /&gt;
* '''apply_to''': describes what the effect actually affects.&lt;br /&gt;
[effect] uses different keys depending on the value of '''apply_to'''.  '''apply_to''' can take the following values:&lt;br /&gt;
* '''new_attack''': will use all other keys and tags as the description of an attack that will be added to the unit. See [attack] in [[UnitTypeWML#Attacks|UnitTypeWML]].&lt;br /&gt;
* '''remove_attacks''': remove the matching attacks. All tags from the attack filter construct will be used to match the attack; see [[FilterWML#Filtering Weapons|FilterWML]]. Do not use a [filter] tag otherwise it will not work properly.&lt;br /&gt;
* '''attack''': find an attack and modify it.  All tags from the attack filter construct will be used to match the attack; see [[FilterWML#Filtering Weapons|FilterWML]].  After that, the following keys and tags can be used to modify the attack.  Note: do not use a [filter] tag.  Just put the keys you want to filter on inside the [effect] tag.&lt;br /&gt;
** '''set_name''': change the attack's name (ie identifier).&lt;br /&gt;
** '''set_description''': change the attack's description (ie displayed name). &lt;br /&gt;
** '''set_type''': change the attack type. The standard values are '''blade''', '''pierce''', '''impact''', '''fire''', '''cold''', and '''arcane'''.&lt;br /&gt;
** '''[set_specials]''': change the attack's specials. The specials to add are given exactly as in the [specials] tag.&lt;br /&gt;
*** '''mode''': if '''append''', adds the given specials to the attack. If '''replace''', replaces the existing specials with the given ones. Default '''replace'''.&lt;br /&gt;
** '''remove_specials''': remove the listed specials. The value of this key is the coma-separated list of the id of the specials to remove. This key is always evaluated before a [set_specials] tags in the same [effect]&lt;br /&gt;
** '''increase_damage''': increases the attack's damage.  This can be positive or negative, so you can use it to decrease damage as well.  If it ends in a percent(''''%''''), the change in damage will be a percentage ratio of the attack's original damage.&lt;br /&gt;
** '''increase_attacks''': increases the number of attack strikes. Like '''increase_damage''', it can be positive or negative, or a percentage.&lt;br /&gt;
** '''attack_weight''': change the attack's attack_weight. See [attack] in [[UnitTypeWML#Attacks|UnitTypeWML]] for explanations about attack_weight.&lt;br /&gt;
** '''defense_weight''': change the attack's defense_weight. See [attack] in [[UnitTypeWML#Attacks|UnitTypeWML]] for explanations about defense_weight.&lt;br /&gt;
* '''hitpoints''': modifies the unit's HP and/or max HP.&lt;br /&gt;
** '''increase''': the amount to increase the unit's HP.&lt;br /&gt;
** '''heal_full''': if present  and not set to &amp;quot;no&amp;quot; the unit will be put back to full HP.&lt;br /&gt;
** '''increase_total''': will increase the total HP of the unit.  Can be specified either as a negative or a positive value.  It can also be specified as a percentage of the current total; i.e. &amp;quot;-50%&amp;quot; will cut max HP in half.&lt;br /&gt;
** '''violate_maximum''': it the unit ends up with more than its max HP after these modifications, and this key is present (set to any non-null value, ex. '''yes'''), the unit's HP won't be lowered to its max HP.&lt;br /&gt;
* '''movement''': modifies the unit's movement points.&lt;br /&gt;
** '''increase''': maximum movement is increased by this amount. It can be positive, negative, or specified as a percentage.&lt;br /&gt;
** '''set''': maximum movement is set to a specific value.&lt;br /&gt;
* '''max_experience''': affects the amount of XP the unit needs for the next level.&lt;br /&gt;
** '''increase''': how to change the xp; again it can be negative, positive or a percentage.&lt;br /&gt;
* '''loyal''': no keys associated. The affected unit will be loyal i.e have an upkeep of 0.&lt;br /&gt;
* '''movement_costs''': speed through specific terrain is modified&lt;br /&gt;
** '''replace''': If set to &amp;quot;true&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values (negative values allowed).&lt;br /&gt;
** '''[movement_costs]''': a subtag that describes the new movement costs just like in [[UnitsWML#.5Bmovetype.5D|UnitsWML]]&lt;br /&gt;
* '''defense''': Sets unit chance to be hit in specific terrain (100 - defense value)&lt;br /&gt;
** '''replace''': If set to &amp;quot;true&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values (negative values allowed).&lt;br /&gt;
** '''[defense]''': a subtag that describes the new defense just like in [[UnitsWML#.5Bmovetype.5D|UnitsWML]]&lt;br /&gt;
* '''resistance''': Sets percent damage taken from combat&lt;br /&gt;
** '''replace''': If set to &amp;quot;true&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values (negative values allowed).&lt;br /&gt;
** '''[resistance]''': a subtag that describes the new resistance just like in [[UnitsWML#.5Bmovetype.5D|UnitsWML]]&lt;br /&gt;
* '''variation''': switches the unit into one of its variations.&lt;br /&gt;
** '''name''': the id of the variation to invoke.&lt;br /&gt;
* '''type''': transforms the unit into a new unit_type.&lt;br /&gt;
** '''name''': the id of the unit_type to invoke.&lt;br /&gt;
* '''status''': modifies the status affecting the unit.&lt;br /&gt;
** '''add''': a list of status modifications to add. Beware, these may be reapplied later, such as when the unit is recalled or levels up; if in an event, you can use [[InternalActionsWML|[store_unit]]] and [[DirectActionsWML|[unstore_unit]]], modifying unit.status.name directly, to avoid this, or if you are creating the unit, you can just add it to the unit's [status] tag in the [unit] tag.  These are listed in [status], [[SingleUnitWML]].&lt;br /&gt;
** '''remove''': a list of status modifications to remove.&lt;br /&gt;
* '''zoc''': toggle the zone of control.&lt;br /&gt;
** '''value''': new value for zoc (0=disable, other=enable).&lt;br /&gt;
* '''profile''': customize the profile of the unit. See [[UnitTypeWML]].&lt;br /&gt;
** '''portrait''': new image to display when the unit speaks.&lt;br /&gt;
** '''small_portrait''': new image to display in unit reports.&lt;br /&gt;
** '''description''': sets the text to display when hovering over the unit's type in the righthand pane.&lt;br /&gt;
* '''new_ability''': Adds one or more abilities to a unit.&lt;br /&gt;
** '''[abilities]''': A subtag that contains the ability definitions.&lt;br /&gt;
* '''remove_ability''': Removes one or more abilities from a unit. Abilities are not reference counted: added, added, removed = gone.&lt;br /&gt;
** '''[abilities]''': A subtag that contains the ability definitions. Strictly speaking, all that is needed is the id= inside some tag.&lt;br /&gt;
* '''new_animation''': contain animations that will be added to the unit, it can contain multiple animation blocks, and a single &amp;quot;id=&amp;quot; line. That Id should be unique for each effect block and is used by the engine to reuse WML parsing, making the loading faster.&lt;br /&gt;
* '''image_mod''': modify the image path function ([[ImagePathFunctionWML]]) of all the unit's frames.&lt;br /&gt;
** '''replace''': replaces the image path function(s) to be used, e.g. &amp;quot;RC(magenta&amp;gt;red)&amp;quot;&lt;br /&gt;
** '''add''': adds an image path function without removing any existing ones.&lt;br /&gt;
* '''ellipse''': Change the image used for the unit's ellipse.&lt;br /&gt;
**'''ellipse''' : the new image to use.&lt;br /&gt;
* {{DevFeature1.11}} '''halo''': Change the image used for the unit's halo.&lt;br /&gt;
**'''halo''': the new image to use.&lt;br /&gt;
* {{DevFeature1.11}} '''overlay''': Change the unit's overlays.&lt;br /&gt;
**'''add''': the specified overlay will be added to the unit's overlays. It can be a comma separated list with multiple overlays. ''Note: overlays added in this way cannot be removed by [remove_unit_overlay] until the effect's duration is over.''&lt;br /&gt;
**'''replace''': all the unit's overlays will be removed and replaced with the specified one. Again, it can be a comma separated list. ''Note: overlays replaced in this way cannot be modified by [unit_overlay] or [remove_unit_overlay] until the effect's duration is over.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[UnitTypeWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
* [[AnimationWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=46819</id>
		<title>LuaWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=46819"/>
		<updated>2012-07-21T10:13:24Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* Map and terrains */ Added wesnoth.get_villages()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
== The '''[lua]''' tag ==&lt;br /&gt;
&lt;br /&gt;
This tag is a part of [[ActionWML]], thus can be used inside [event] and at other places where [[ActionWML]] can be used. It makes it possible to write actions with the [http://www.lua.org Lua 5.1] language.&lt;br /&gt;
&lt;br /&gt;
The tag supports only the '''code''' key, which is a string containing the Lua scripts. Since Lua makes usage of the quotes and the { and } symbols, it is certainly wise to enclose the script between stronger quotes, as they prevent the preprocessor from performing macro expansion and tokenization.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; wesnoth.message &amp;quot;Hello World!&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
The Lua kernel can also be accessed from the [[CommandMode|command mode]]:&lt;br /&gt;
&lt;br /&gt;
 :lua local u = wesnoth.get_units({ id = &amp;quot;Konrad&amp;quot; })[1]; u.moves = 5&lt;br /&gt;
&lt;br /&gt;
The '''[args]''' sub-tag can be used to pass a WML object to the script via its variadic local variable &amp;quot;'''...'''&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 [lua]&lt;br /&gt;
     code = &amp;lt;&amp;lt; local t = ...; wesnoth.message(tostring(t.text)) &amp;gt;&amp;gt;&lt;br /&gt;
     [args]&lt;br /&gt;
         text = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/args]&lt;br /&gt;
 [/lua]&lt;br /&gt;
&lt;br /&gt;
== Global environment ==&lt;br /&gt;
&lt;br /&gt;
All the Lua scripts of a scenario share the same global environment (aka Lua state). For instance, a function defined in an event can be used in all the events that happen after it.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             function narrator(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; narrator(...) &amp;gt;&amp;gt;&lt;br /&gt;
         [args]&lt;br /&gt;
             sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
         [/args]&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
In the example above, the redundant structure could be hidden behind macros. But it may be better to simply define a new WML tag.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name = preload&lt;br /&gt;
     first_time_only = no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             -- The function is now local, since its name does not have to be&lt;br /&gt;
             -- visible outside this Lua scripts.&lt;br /&gt;
             local function handler(t)&lt;br /&gt;
                 -- Behave like the [message] tag.&lt;br /&gt;
                 wesnoth.fire(&amp;quot;message&amp;quot;,&lt;br /&gt;
                   { speaker = &amp;quot;narrator&amp;quot;, message = t.sentence })&lt;br /&gt;
             end&lt;br /&gt;
             -- Create a new tag named [narrator].&lt;br /&gt;
             wesnoth.register_wml_action(&amp;quot;narrator&amp;quot;, handler)&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
 &lt;br /&gt;
 [event]&lt;br /&gt;
     name = turn 1&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
     [narrator]&lt;br /&gt;
         sentence = _ &amp;quot;How are you today?&amp;quot;&lt;br /&gt;
     [/narrator]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
The global environment is not preserved over save/load cycles. Therefore, storing values in the global environment is generally a bad idea (unless it has been redirected to WML variables, see [[LuaWML:Variables#set_wml_var_metatable|helper.set_wml_var_metatable]]). The only time assigning global variables (including function definitions) makes sense is during a [[EventWML#Predefined 'name' Key Values|preload]] event, as this event is always run. Therefore, helper functions defined at that time will be available to all the later scripts.&lt;br /&gt;
&lt;br /&gt;
The global environment initially contains the following modules: [http://www.lua.org/manual/5.1/manual.html#5.1 basic] (no name), [http://www.lua.org/manual/5.1/manual.html#5.4 string], [http://www.lua.org/manual/5.1/manual.html#5.5 table], and [http://www.lua.org/manual/5.1/manual.html#5.6 math]. A '''wesnoth''' module is also available, it provides access to the [[#Interface to the C++ engine|C++ engine]]. Besides, the functions clock, date, time and difftime from the [http://www.lua.org/manual/5.1/manual.html#5.8 os] library (Keep in mind that they aren't multiplayer- and replay-save.) and traceback from the [http://www.lua.org/manual/5.1/manual.html#5.9 debug] library are also available.&lt;br /&gt;
&lt;br /&gt;
At the start of a script, the variadic local variable '''...''' (three dots) is a proxy table representing [[#Encoding WML objects into Lua tables|WML data]]. This table is the content of the '''[args]''' sub-tag of the '''[lua]''' tag, if any.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following WML event is taken from Wesnoth' tutorial. It will serve as an example to present how Lua scripts are embedded into Wesnoth. The event is fired whenever a unit from side 1 (that is, the hero controlled by the user) moves to a tile that is not the one set in the WML variable ''target_hex''.&lt;br /&gt;
&lt;br /&gt;
 # General catch for them moving to the wrong place.&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [if]&lt;br /&gt;
         [variable]&lt;br /&gt;
             name=target_hex.is_set&lt;br /&gt;
             equals=yes&lt;br /&gt;
         [/variable]&lt;br /&gt;
         [then]&lt;br /&gt;
             [if]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=x1&lt;br /&gt;
                     equals=$target_hex.x&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [variable]&lt;br /&gt;
                     name=y1&lt;br /&gt;
                     equals=$target_hex.y&lt;br /&gt;
                 [/variable]&lt;br /&gt;
                 [then]&lt;br /&gt;
                 [/then]&lt;br /&gt;
                 [else]&lt;br /&gt;
                     [redraw][/redraw]&lt;br /&gt;
                     [message]&lt;br /&gt;
                         speaker=narrator&lt;br /&gt;
                         message=_ &amp;quot;*Oops!&lt;br /&gt;
 You moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot; +&lt;br /&gt;
                         _ &amp;quot;&lt;br /&gt;
 *Left click or press spacebar to continue...&amp;quot;&lt;br /&gt;
                     [/message]&lt;br /&gt;
                 [/else]&lt;br /&gt;
             [/if]&lt;br /&gt;
         [/then]&lt;br /&gt;
     [/if]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
A Lua script that performs the same action is presented below.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=moveto&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [allow_undo][/allow_undo]&lt;br /&gt;
     [filter]&lt;br /&gt;
         side=1&lt;br /&gt;
     [/filter]&lt;br /&gt;
 &lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             local event_data = wesnoth.current.event_context&lt;br /&gt;
             if target_hex.is_set and&lt;br /&gt;
                (event_data.x1 ~= target_hex.x or event_data.y1 ~= target_hex.y)&lt;br /&gt;
             then&lt;br /&gt;
                 W.redraw()&lt;br /&gt;
                 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
             end&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Here is a more detailed explanation of the Lua code. Its first line&lt;br /&gt;
&lt;br /&gt;
 local event_data = wesnoth.current.event_context&lt;br /&gt;
&lt;br /&gt;
puts the event data into the ''event_data'' local variable. Since it is a ''moveto'' event, the ''event_data'' table contains the destination of the unit in the ''x1'' and ''y1'' fields.&lt;br /&gt;
&lt;br /&gt;
The next two lines then test&lt;br /&gt;
&lt;br /&gt;
 if target_hex.is_set and&lt;br /&gt;
    (event_data.x1 ~= target_hex.x or event_data.y1 ~= target_hex.y)&lt;br /&gt;
&lt;br /&gt;
whether the variable ''target_hex'' matches the event parameters. Since ''target_hex'' is not a local variable, it is taken from the global environment (a table implicitly named ''_G'', so it is actually ''_G.target_hex''). The global environment is not persistent, so it cannot be used to store data. In order to make it useful, it was mapped to the storage of WML variables by the following ''preload'' event.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             -- skipping some other initializations&lt;br /&gt;
             -- ...&lt;br /&gt;
             H.set_wml_var_metatable(_G)&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
Without a prelude redirecting ''_G'', the conditional would have been written&lt;br /&gt;
&lt;br /&gt;
 if wesnoth.get_variable(&amp;quot;target_hex.is_set&amp;quot;) and&lt;br /&gt;
    (event_data.x1 ~= wesnoth.get_variable(&amp;quot;target_hex.x&amp;quot;) or event_data.y1 ~= wesnoth.get_variable(&amp;quot;target_hex.y&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The body of the conditional then performs the [[InterfaceActionsWML#Other interface tags|[redraw]]] action.&lt;br /&gt;
&lt;br /&gt;
 W.redraw()&lt;br /&gt;
&lt;br /&gt;
Again, this short syntax is made possible by a line of the prelude that makes ''W'' a proxy for performing WML actions.&lt;br /&gt;
&lt;br /&gt;
 W = H.set_wml_action_metatable {}&lt;br /&gt;
&lt;br /&gt;
Without this shortcut, the first statement would have been written&lt;br /&gt;
&lt;br /&gt;
 wesnoth.fire(&amp;quot;redraw&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Finally the script displays a message by&lt;br /&gt;
&lt;br /&gt;
 narrator_says(_ &amp;quot;*Oops!\nYou moved to the wrong place! After this message, you can press 'u' to undo, then try again.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The ''narrator_says'' function is defined in the prelude too, since the construct behind it occurs several times in the tutorial. In plain WML, macros would have been used instead. The definition of the function is&lt;br /&gt;
&lt;br /&gt;
 function narrator_says(m)&lt;br /&gt;
     W.message { speaker=&amp;quot;narrator&amp;quot;,&lt;br /&gt;
                 message = m .. _ &amp;quot;\n*Left click or press spacebar to continue...&amp;quot; }&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The function fires a [[InterfaceActionsWML#.5Bmessage.5D|[message]]] action and passes a WML object containing the usual two fields to it. The second field is initialized by concatenating the function argument with another string. Both strings are prefixed by the ''_'' symbol to mark them as translatable. (Note that ''_'' is just a unary function, not a keyword.) Again, this is made possible by a specific line of the prelude:&lt;br /&gt;
&lt;br /&gt;
 _ = wesnoth.textdomain &amp;quot;wesnoth-tutorial&amp;quot;&lt;br /&gt;
&lt;br /&gt;
A longer translation of the tutorial is available at [https://gna.org/patch/download.php?file_id=5483].&lt;br /&gt;
&lt;br /&gt;
== Interface to the engine and helper functions ==&lt;br /&gt;
&lt;br /&gt;
Functionalities of the game engine are available through the functions of the '''wesnoth''' global table. Some of these functions return proxy tables. Writes to fields marked &amp;quot;read-only&amp;quot; are ignored. The '''__cfg''' fields return plain tables; in particular, writes do not modify the original object, and reads return the values from the time the dump was performed.&lt;br /&gt;
&lt;br /&gt;
Some helper functions are provided by the '''lua/helper.lua''' library. They are stored inside a table that is returned when loading the library with [[LuaWML:Files#wesnoth.require|wesnoth.require]].&lt;br /&gt;
&lt;br /&gt;
 helper = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== WML variables ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]]&lt;br /&gt;
* [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]]&lt;br /&gt;
* [[LuaWML:Variables#helper.set_wml_var_metatable|helper.set_wml_var_metatable]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_child|helper.get_child]]&lt;br /&gt;
* [[LuaWML:Variables#helper.child_range|helper.child_range]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_array|helper.get_variable_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.get_variable_proxy_array|helper.get_variable_proxy_array]]&lt;br /&gt;
* [[LuaWML:Variables#helper.set_variable_array|helper.set_variable_array]]&lt;br /&gt;
&lt;br /&gt;
=== Events and WML actions ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire|wesnoth.fire]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.wml_actions|wesnoth.wml_actions]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.game_events|wesnoth.game_events]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.fire_event|wesnoth.fire_event]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.eval_conditional|wesnoth.eval_conditional]]&lt;br /&gt;
* [[LuaWML:Events#wesnoth.tovconfig|wesnoth.tovconfig]]&lt;br /&gt;
* [[LuaWML:Events#helper.set_wml_action_metatable|helper.set_wml_action_metatable]]&lt;br /&gt;
* [[LuaWML:Events#helper.wml_error|helper.wml_error]]&lt;br /&gt;
* [[LuaWML:Events#helper.literal|helper.literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.parsed|helper.parsed]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_literal|helper.shallow_literal]]&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_parsed|helper.shallow_parsed]]&lt;br /&gt;
&lt;br /&gt;
=== User interface ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Display#wesnoth.message|wesnoth.message]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.clear_messages|wesnoth.clear_messages]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.textdomain|wesnoth.textdomain]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.delay|wesnoth.delay]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.float_label|wesnoth.float_label]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_hex|wesnoth.select_hex]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.scroll_to_tile|wesnoth.scroll_to_tile]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.lock_view|wesnoth.lock_view]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.view_locked|wesnoth.view_locked]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.play_sound|wesnoth.play_sound]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_music|wesnoth.set_music]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_dialog|wesnoth.show_dialog]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_value|wesnoth.set_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_dialog_value|wesnoth.get_dialog_value]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_active|wesnoth.set_dialog_active]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_callback|wesnoth.set_dialog_callback]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_canvas|wesnoth.set_dialog_canvas]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_displayed_unit|wesnoth.get_displayed_unit]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.theme_items|wesnoth.theme_items]]&lt;br /&gt;
* [[LuaWML:Display#helper.get_user_choice|helper.get_user_choice]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_time_of_day|wesnoth.get_time_of_day]]&lt;br /&gt;
&lt;br /&gt;
=== Map and terrains ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_map_size|wesnoth.get_map_size]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain|wesnoth.get_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.set_terrain|wesnoth.set_terrain]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_terrain_info|wesnoth.get_terrain_info]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_selected_tile|wesnoth.get_selected_tile]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.get_locations|wesnoth.get_locations]]&lt;br /&gt;
* {{DevFeature1.11}}[[LuaWML:Tiles#wesnoth.get_villages|wesnoth.get_villages]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.match_location|wesnoth.match_location]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_tile_overlay|wesnoth.add_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_tile_overlay|wesnoth.remove_tile_overlay]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_image|items.place_image]]&lt;br /&gt;
* [[LuaWML:Tiles#items.place_halo|items.place_halo]]&lt;br /&gt;
* [[LuaWML:Tiles#items.remove|items.remove]]&lt;br /&gt;
&lt;br /&gt;
=== Units ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_units|wesnoth.get_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit|wesnoth.get_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.match_unit|wesnoth.match_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_unit|wesnoth.put_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_recall_units|wesnoth.get_recall_units]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_recall_unit|wesnoth.put_recall_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.create_unit|wesnoth.create_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.copy_unit|wesnoth.copy_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.extract_unit|wesnoth.extract_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_modification|wesnoth.add_modification]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_resistance|wesnoth.unit_resistance]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_defense|wesnoth.unit_defense]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_movement_cost|wesnoth.unit_movement_cost]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_ability|wesnoth.unit_ability]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type_ids|wesnoth.get_unit_type_ids]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_unit_type|wesnoth.get_unit_type]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.unit_types|wesnoth.unit_types]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.races|wesnoth.races]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_traits|wesnoth.get_traits]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.simulate_combat|wesnoth.simulate_combat]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.transform_unit|wesnoth.transform_unit]]&lt;br /&gt;
&lt;br /&gt;
=== Sides ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_side|wesnoth.get_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.sides|wesnoth.sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_sides|wesnoth.get_sides]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_village_owner|wesnoth.get_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.set_village_owner|wesnoth.set_village_owner]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.is_enemy|wesnoth.is_enemy]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.match_side|wesnoth.match_side]]&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_starting_location|wesnoth.get_starting_location]]&lt;br /&gt;
* [[LuaWML:Sides#helper.all_teams|helper.all_teams]]&lt;br /&gt;
&lt;br /&gt;
=== Pathfinder ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_path|wesnoth.find_path]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_vacant_tile|wesnoth.find_vacant_tile]]&lt;br /&gt;
* [[LuaWML:Pathfinder#wesnoth.find_reach|wesnoth.find_reach]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.distance_between|helper.distance_between]]&lt;br /&gt;
* [[LuaWML:Pathfinder#helper.adjacent_tiles|helper.adjacent_tiles]]&lt;br /&gt;
&lt;br /&gt;
=== Lua files ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Files#wesnoth.dofile|wesnoth.dofile]]&lt;br /&gt;
* [[LuaWML:Files#wesnoth.require|wesnoth.require]]&lt;br /&gt;
&lt;br /&gt;
=== Location sets ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Location_set#location_set.create|location_set.create]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_pairs|location_set.of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_wml_var|location_set.of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:empty|location_set:empty]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:size|location_set:size]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:clear|location_set:clear]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:get|location_set:get]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:insert|location_set:insert]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:remove|location_set:remove]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_pairs|location_set:of_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_wml_var|location_set:of_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_pairs|location_set:to_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_stable_pairs|location_set:to_stable_pairs]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_wml_var|location_set:to_wml_var]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union|location_set:union]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter|location_set:inter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:iter|location_set:iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:stable_iter|location_set:stable_iter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:filter|location_set:filter]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union_merge|location_set:union_merge]]&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter_merge|location_set:inter_merge]]&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous ===&lt;br /&gt;
&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.game_config|wesnoth.game_config]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.current|wesnoth.current]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.synchronize_choice|wesnoth.synchronize_choice]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_image_size|wesnoth.get_image_size]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compare_versions|wesnoth.compare_versions]]&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.debug|wesnoth.debug]]&lt;br /&gt;
* [[LuaWML:Misc#helper.set_wml_tag_metatable|helper.set_wml_tag_metatable]]&lt;br /&gt;
* [[LuaWML:Misc#helper.modify_unit|helper.modify_unit]]&lt;br /&gt;
* [[LuaWML:Misc#helper.move_unit_fake|helper.move_unit_fake]]&lt;br /&gt;
* [[LuaWML:Misc#helper.rand|helper.rand]]&lt;br /&gt;
* [[LuaWML:Misc#helper.round|helper.round]]&lt;br /&gt;
&lt;br /&gt;
== Encoding WML objects into Lua tables ==&lt;br /&gt;
&lt;br /&gt;
Function [[LuaWML:Events#wesnoth.fire|wesnoth.fire]] expects a table representing a WML object as its second argument (if needed). Function [[LuaWML:Variables#wesnoth.set_variable|wesnoth.set_variable]] allows to modify whole WML objects, again by passing it a table. Function [[LuaWML:Variables#wesnoth.get_variable|wesnoth.get_variable]] transforms a WML object into a table, if its second argument is not set to ''true''. All these tables have the same format.&lt;br /&gt;
&lt;br /&gt;
Scalar fields are transformed into WML attributes. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     a_bool = true,&lt;br /&gt;
     an_int = 42,&lt;br /&gt;
     a_float = 1.25,&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;,&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     a_bool = &amp;quot;yes&amp;quot;&lt;br /&gt;
     an_int = &amp;quot;42&amp;quot;&lt;br /&gt;
     a_float = &amp;quot;1.25&amp;quot;&lt;br /&gt;
     a_string = &amp;quot;scout&amp;quot;&lt;br /&gt;
     a_translation = _ &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
WML child objects are not stored as Lua named fields, since several of them can have the same tag. Moreover, their tags can conflict with the attribute keys. So child objects are stored as pairs string + table in the unnamed fields in definition order. This means that for every subtag appearing in the wml code there is an additional table &amp;quot;layer&amp;quot; in the corresponding WML table of the form {[1] = &amp;quot;tag_name&amp;quot;, [2] = {}} which is equivalent to {&amp;quot;tag_name&amp;quot;, {}}. [1] etc are the unnamed fields (as opposed to wml attributes). The table under [2] in this subtable then holds the wml attributes from inside the wml subtag. So every subtag other than the toplevel tag corresponds to two nested tables each. For instance, the following Lua table&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { v = 1, w = 2 } },&lt;br /&gt;
     { &amp;quot;foo&amp;quot;, { x = false } },&lt;br /&gt;
     { &amp;quot;bar&amp;quot;, { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     { &amp;quot;foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
is equivalent to the content of the following WML object&lt;br /&gt;
&lt;br /&gt;
 [dummy]&lt;br /&gt;
     foo = 42&lt;br /&gt;
     [bar]&lt;br /&gt;
         v = 1&lt;br /&gt;
         w = 2&lt;br /&gt;
     [/bar]&lt;br /&gt;
     [foo]&lt;br /&gt;
         x = no&lt;br /&gt;
     [/foo]&lt;br /&gt;
     [bar]&lt;br /&gt;
         y = foo&lt;br /&gt;
     [bar]&lt;br /&gt;
     [foobar]&lt;br /&gt;
         z = 5&lt;br /&gt;
         [barfoo]&lt;br /&gt;
         [/barfoo]&lt;br /&gt;
     [/foobar]&lt;br /&gt;
 [/dummy]&lt;br /&gt;
&lt;br /&gt;
Both tables above are also equivalent to this WML table, where all unnamed fields are displayed:&lt;br /&gt;
 {&lt;br /&gt;
     foo = 42,&lt;br /&gt;
     [1] = { [1] = &amp;quot;bar&amp;quot;, [2] = { v = 1, w = 2 } },&lt;br /&gt;
     [2] = { [1] = &amp;quot;foo&amp;quot;, [2] = { x = false } },&lt;br /&gt;
     [3] = { [1] = &amp;quot;bar&amp;quot;, [2] = { y = &amp;quot;foo&amp;quot; } },&lt;br /&gt;
     [4] = { [1] = &amp;quot;foobar&amp;quot;, [2] = { z = 5, [1] = { [1] = &amp;quot;barfoo&amp;quot;, [2] = {} } } }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
So assuming ''cfg'' contains the above WML object, the following accesses are possible:&lt;br /&gt;
&lt;br /&gt;
 a_int = cfg.foo        -- &amp;quot;dummy.foo&amp;quot;, 42&lt;br /&gt;
 a_string = cfg[3][2].y -- &amp;quot;dummy.bar[1].y&amp;quot;, &amp;quot;foo&amp;quot;&lt;br /&gt;
 a_table = cfg[4][2]    -- &amp;quot;dummy.foobar&amp;quot;, { z = 5, { &amp;quot;barfoo&amp;quot;, {} } }&lt;br /&gt;
&lt;br /&gt;
Consider using the [[LuaWML:Variables#helper.get_child|helper.get_child]] and [[LuaWML:Variables#helper.child_range|helper.child_range]] to ease the access to subtags.&lt;br /&gt;
&lt;br /&gt;
Functions registered by [[LuaWML:Events#wesnoth.register_wml_action|wesnoth.register_wml_action]] receive their data in a userdata object which has the exact same structure as above. It is read-only however. Accessing fields or children performs variable substitution on the fly. Its '''__parsed''' and '''__literal''' fields provide translations to plain tables (therefore writable). '''__literal''' returns the original text of the data (including dollar symbols in attributes and [insert_tag] children), while '''__parsed''' performs a variable substitution.&lt;br /&gt;
&lt;br /&gt;
For instance, if you cannot stand any longer the fact that '''first_time_only''' is set to yes by default for the '''[event]''' tag, you can redefine it. But we have to be careful not to cause variable substitution, since the engine would perform a second variable substitution afterwards.&lt;br /&gt;
&lt;br /&gt;
 local old_event_handler&lt;br /&gt;
 old_event_handler = register_wml_action(&amp;quot;event&amp;quot;,&lt;br /&gt;
     function(cfg)&lt;br /&gt;
         -- Get the plain text from the user.&lt;br /&gt;
         local new_cfg = cfg.__literal&lt;br /&gt;
         -- The expression below is equivalent to cfg.__parsed.first_time_only,&lt;br /&gt;
         -- only faster. It is needed, since the first_time_only attribute may&lt;br /&gt;
         -- reference variables.&lt;br /&gt;
         local first = cfg.first_time_only&lt;br /&gt;
         -- Modify the default behavior of first_time_only.&lt;br /&gt;
         if first == nil then first = false end&lt;br /&gt;
         new_cfg.first_time_only = first&lt;br /&gt;
         -- Call the engine handler.&lt;br /&gt;
         old_event_handler(new_cfg)&lt;br /&gt;
     end&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Note that, since the object is a userdata and not a table, '''pairs''' and '''ipairs''' are unfortunately not usable on it. So scripts have to work at a lower level. For instance, the following function returns the first sub-tag with a given name and it works both on WML tables and WML userdata:&lt;br /&gt;
&lt;br /&gt;
 function get_child(cfg, name)&lt;br /&gt;
     for i = 1, #cfg do&lt;br /&gt;
         local v = cfg[i]&lt;br /&gt;
         if v[1] == name then return v[2] end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Another approach for handling userdata and tables in the same way, would be to convert the former into the latter beforehand:&lt;br /&gt;
&lt;br /&gt;
 if getmetatable(cfg) == &amp;quot;wml object&amp;quot; then cfg = cfg.__parsed end&lt;br /&gt;
&lt;br /&gt;
The WML userdata provides two other special fields: '''__shallow_parsed''' and '''__shallow_literal'''. They return a table corresponding to the WML userdata with variable substitution performed on the attributes (or not). [insert_tag] tags have also been parsed, so the number of children is faithful. But contrarily to '''__parsed''' and '''__literal''', the process is not recursive: all the children are still WML userdata and variable substitution can still happen for them. These shallow translators are meant as optimized versions of the deep ones, when only the toplevel attributes need to be writable.&lt;br /&gt;
&lt;br /&gt;
== Skeleton of a preload event ==&lt;br /&gt;
&lt;br /&gt;
The following event is a skeleton for a prelude enabling Lua in your WML events. It creates a table ''H'' containing the functions from helper.lua and a table ''W'' that serves as a proxy for firing WML actions. It also sets up the global environment so that any access to an undefined global variable is redirected to the persistent WML storage.&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt;&lt;br /&gt;
             H = wesnoth.require &amp;quot;lua/helper.lua&amp;quot;&lt;br /&gt;
             W = H.set_wml_action_metatable {}&lt;br /&gt;
             _ = wesnoth.textdomain &amp;quot;my-campaign&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
             -- Define your global constants here.&lt;br /&gt;
             -- ...&lt;br /&gt;
 &lt;br /&gt;
             H.set_wml_var_metatable(_G)&lt;br /&gt;
 &lt;br /&gt;
             -- Define your global functions here.&lt;br /&gt;
             -- ...&lt;br /&gt;
         &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
It may be worth putting the whole Lua script above inside a separate file and having the ''preload'' event load it:&lt;br /&gt;
&lt;br /&gt;
 [event]&lt;br /&gt;
     name=preload&lt;br /&gt;
     first_time_only=no&lt;br /&gt;
     [lua]&lt;br /&gt;
         code = &amp;lt;&amp;lt; wesnoth.dofile &amp;quot;~add-ons/Whatever/file.lua&amp;quot; &amp;gt;&amp;gt;&lt;br /&gt;
     [/lua]&lt;br /&gt;
 [/event]&lt;br /&gt;
&lt;br /&gt;
== Remarks ==&lt;br /&gt;
&lt;br /&gt;
The math.random function is not safe for replays and multiplayer games, since the random values will be different each time and on all the clients. Instead, the Lua code should rely on the [[InternalActionsWML#.5Bset_variable.5D|[set_variable]]] tag to synchronize random values.&lt;br /&gt;
&lt;br /&gt;
 function random(min, max)&lt;br /&gt;
   if not max then min, max = 1, min end&lt;br /&gt;
   wesnoth.fire(&amp;quot;set_variable&amp;quot;, { name = &amp;quot;LUA_random&amp;quot;, rand = string.format(&amp;quot;%d..%d&amp;quot;, min, max) })&lt;br /&gt;
   local res = wesnoth.get_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   wesnoth.set_variable &amp;quot;LUA_random&amp;quot;&lt;br /&gt;
   return res&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference|*]]&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Tiles&amp;diff=46818</id>
		<title>LuaWML/Tiles</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Tiles&amp;diff=46818"/>
		<updated>2012-07-21T10:09:58Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: Added wesnoth.get_villages()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions for handling terrains and tiles. The ''items'' library can be loaded by&lt;br /&gt;
&lt;br /&gt;
 items = wesnoth.require &amp;quot;lua/wml/items.lua&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_map_size ====&lt;br /&gt;
&lt;br /&gt;
Returns the width, the height, and the border size of the map.&lt;br /&gt;
&lt;br /&gt;
 local w,h,b = wesnoth.get_map_size()&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_terrain ====&lt;br /&gt;
&lt;br /&gt;
Returns the terrain code for the given location.&lt;br /&gt;
&lt;br /&gt;
 local is_grassland = wesnoth.get_terrain(12, 15) == &amp;quot;Gg&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_terrain ====&lt;br /&gt;
&lt;br /&gt;
Modifies the terrain at the given location.&lt;br /&gt;
&lt;br /&gt;
 function create_village(x, y)&lt;br /&gt;
     wesnoth.set_terrain(x, y, &amp;quot;Gg^Vh&amp;quot;)&lt;br /&gt;
 end&lt;br /&gt;
An optional 4th parameter can be passed (layer): overlay, base or both, default both: Change the specified layer only.&lt;br /&gt;
An optional 5th boolean parameter (replace_if_failed) can be passed, see the documentation of the [terrain] tag. To pass the 5th parameter but not the 4th, pass nil for the 4th.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_terrain_info ====&lt;br /&gt;
&lt;br /&gt;
Returns the terrain details for the given terrain code.&lt;br /&gt;
&lt;br /&gt;
 local is_keep = wesnoth.get_terrain_info(wesnoth.get_terrain(12, 15)).keep&lt;br /&gt;
&lt;br /&gt;
Terrain info is a plain table with the following fields:&lt;br /&gt;
* '''id''': string&lt;br /&gt;
* '''name''', '''description''', '''editor_name''': translatable strings&lt;br /&gt;
* '''castle''', '''keep''', '''village''': booleans&lt;br /&gt;
* '''healing''': integer&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_selected_tile ====&lt;br /&gt;
&lt;br /&gt;
Returns the two coordinates of the currently selected tile. This is mostly useful for defining command-mode helpers.&lt;br /&gt;
&lt;br /&gt;
 function chg_unit(attr, val)&lt;br /&gt;
    local x, y = wesnoth.get_selected_tile()&lt;br /&gt;
    if not x then wesnoth.message(&amp;quot;Error&amp;quot;, &amp;quot;No unit selected.&amp;quot;); return end&lt;br /&gt;
    helper.modify_unit({ x = x, y = y }, { [attr] = val })&lt;br /&gt;
 end&lt;br /&gt;
 -- Function chg_unit can be used in command mode to modify unit attributes on the fly:&lt;br /&gt;
 --   :lua chg_unit(&amp;quot;status.poisoned&amp;quot;, true)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_locations ====&lt;br /&gt;
&lt;br /&gt;
Returns a table containing all the locations matching the given filter. Locations are stored as pairs: tables of two elements. See [[StandardLocationFilter]] for details about location filters.&lt;br /&gt;
&lt;br /&gt;
 -- replace all grass terrains by roads&lt;br /&gt;
 for i,loc in ipairs(wesnoth.get_locations { terrain = &amp;quot;Gg&amp;quot; }) do&lt;br /&gt;
     wesnoth.set_terrain(loc[1], loc[2], &amp;quot;Rr&amp;quot;)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_villages ====&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.11}}This function, when called without arguments, returns a table containing all the villages present on the map (as tables of two elements). If it's called with a WML table as argument, a table containing only the villages matching the supplied [[StandardLocationFilter]] is returned.&lt;br /&gt;
&lt;br /&gt;
 -- How many villages do we have on our map?&lt;br /&gt;
 v = #wesnoth.get_villages()&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.match_location ====&lt;br /&gt;
&lt;br /&gt;
Returns true if the given location passes the filter.&lt;br /&gt;
&lt;br /&gt;
 bool b = wesnoth.match_location(x, y, { terrain = &amp;quot;Ww&amp;quot;, { &amp;quot;filter_adjacent_location&amp;quot;, terrain = &amp;quot;Ds,*^Bw*&amp;quot; } })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.add_tile_overlay ====&lt;br /&gt;
&lt;br /&gt;
Places a tile overlay (either an image or a halo) at a given location. The overlay is described by a table supporting the same fields as [[InterfaceActionsWML|[item]]]. Note that the overlay is not kept over save/load cycles.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.add_tile_overlay(17, 42, { image = &amp;quot;items/orcish-flag.png&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.remove_tile_overlay ====&lt;br /&gt;
&lt;br /&gt;
Removes all the overlays at the given location. If a filename is passed as a third argument, only this overlay (either image or halo) is removed.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.remove_tile_overlay(17, 42, &amp;quot;items/orcish-flag.png&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== items.place_image ====&lt;br /&gt;
&lt;br /&gt;
Places an image at a given location and registers it as a WML ''[item]'' would do, so that it can be restored after save/load.&lt;br /&gt;
&lt;br /&gt;
 local items = wesnoth.require &amp;quot;lua/wml/items.lua&amp;quot;&lt;br /&gt;
 items.place_image(17, 42, &amp;quot;items/orcish-flag.png&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== items.place_halo ====&lt;br /&gt;
&lt;br /&gt;
Behaves the same as [[#items.place_image]] but for halos.&lt;br /&gt;
&lt;br /&gt;
==== items.remove ====&lt;br /&gt;
&lt;br /&gt;
Removes an overlay set by [[#items.place_image]] or [[#items.place_halo]]. If no filename is provided, all the overlays on a given tile are removed.&lt;br /&gt;
&lt;br /&gt;
 items.remove(17, 42, &amp;quot;items/orcish-flag.png&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=EffectWML&amp;diff=46711</id>
		<title>EffectWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=EffectWML&amp;diff=46711"/>
		<updated>2012-06-23T08:20:11Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* the [effect] tag */ Documented apply_to=halo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== the [effect] tag ==&lt;br /&gt;
&lt;br /&gt;
The tag [effect] is used to describe one modification to a unit. Any number of [effect] tags can be used to describe a complete modification. Modifications are permanent changes to a unit; currently there is no way of removing a modification.&lt;br /&gt;
&lt;br /&gt;
The following keys and subtags are always recognized:&lt;br /&gt;
* '''[filter]''': only apply this effect if the affected unit matches. See [[StandardUnitFilter]] for details.&lt;br /&gt;
* '''unit_type''': only apply this effect if the affected unit's type name matches the value. (can be a list)&lt;br /&gt;
* '''unit_gender''': only apply this effect if the affected unit's gender name matches the value. (can be a list)&lt;br /&gt;
* '''times''': describes how many times the effect is applied. The default is to apply the effect once. Other possible value : &amp;quot;per level&amp;quot; which means that the effect is applied level times, where level is the unit level.&lt;br /&gt;
* '''apply_to''': describes what the effect actually affects.&lt;br /&gt;
[effect] uses different keys depending on the value of '''apply_to'''.  '''apply_to''' can take the following values:&lt;br /&gt;
* '''new_attack''': will use all other keys and tags as the description of an attack that will be added to the unit. See [attack] in [[UnitTypeWML]].&lt;br /&gt;
* '''remove_attacks''': remove the matching attacks. All tags from the attack filter construct will be used to match the attack; see [[FilterWML]]. Do not use a [filter] tag otherwise it will not work properly.&lt;br /&gt;
* '''attack''': find an attack and modify it.  All tags from the attack filter construct will be used to match the attack; see [[FilterWML]].  After that, the following keys and tags can be used to modify the attack.  Note: do not use a [filter] tag.  Just put the keys you want to filter on inside the [effect] tag.&lt;br /&gt;
** '''set_name''': change the attack's name (ie identifier).&lt;br /&gt;
** '''set_description''': change the attack's description (ie displayed name). &lt;br /&gt;
** '''set_type''': change the attack type. The standard values are '''blade''', '''pierce''', '''impact''', '''fire''', '''cold''', and '''arcane'''.&lt;br /&gt;
** '''[set_specials]''': change the attack's specials. The specials to add are given exactly as in the [specials] tag.&lt;br /&gt;
*** '''mode''': if '''append''', adds the given specials to the attack. If '''replace''', replaces the existing specials with the given ones. Default '''replace'''.&lt;br /&gt;
** '''remove_specials''': remove the listed specials. The value of this key is the coma-separated list of the id of the specials to remove. This key is always evaluated before a [set_specials] tags in the same [effect]&lt;br /&gt;
** '''increase_damage''': increases the attack's damage.  This can be positive or negative, so you can use it to decrease damage as well.  If it ends in a percent(''''%''''), the change in damage will be a percentage ratio of the attack's original damage.&lt;br /&gt;
** '''increase_attacks''': increases the number of attack strikes. Like '''increase_damage''', it can be positive or negative, or a percentage.&lt;br /&gt;
** '''attack_weight''': change the attack's attack_weight. See [attack] in [[UnitTypeWML]] for explanations about attack_weight.&lt;br /&gt;
** '''defense_weight''': change the attack's defense_weight. See [attack] in [[UnitTypeWML]] for explanations about defense_weight.&lt;br /&gt;
* '''hitpoints''': modifies the unit's HP and/or max HP.&lt;br /&gt;
** '''increase''': the amount to increase the unit's HP.&lt;br /&gt;
** '''heal_full''': if present  and not set to &amp;quot;no&amp;quot; the unit will be put back to full HP.&lt;br /&gt;
** '''increase_total''': will increase the total HP of the unit.  Can be specified either as a negative or a positive value.  It can also be specified as a percentage of the current total; i.e. &amp;quot;-50%&amp;quot; will cut max HP in half.&lt;br /&gt;
** '''violate_maximum''': it the unit ends up with more than its max HP after these modifications, and this key is present (set to any non-null value, ex. '''yes'''), the unit's HP won't be lowered to its max HP.&lt;br /&gt;
* '''movement''': modifies the unit's movement points.&lt;br /&gt;
** '''increase''': maximum movement is increased by this amount. It can be positive, negative, or specified as a percentage.&lt;br /&gt;
** '''set''': maximum movement is set to a specific value.&lt;br /&gt;
* '''max_experience''': affects the amount of XP the unit needs for the next level.&lt;br /&gt;
** '''increase''': how to change the xp; again it can be negative, positive or a percentage.&lt;br /&gt;
* '''loyal''': no keys associated. The affected unit will be loyal i.e have an upkeep of 0.&lt;br /&gt;
* '''movement_costs''': speed through specific terrain is modified&lt;br /&gt;
** '''replace''': If set to &amp;quot;true&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values (negative values allowed).&lt;br /&gt;
** '''[movement_costs]''': a subtag that describes the new movement costs just like in [[UnitTypeWML]] for describing a unit type&lt;br /&gt;
* '''defense''': Sets unit chance to be hit in specific terrain (100 - defense value)&lt;br /&gt;
** '''replace''': If set to &amp;quot;true&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values (negative values allowed).&lt;br /&gt;
** '''[defense]''': a subtag that describes the new defense just like in [[UnitTypeWML]] for describing a unit type&lt;br /&gt;
* '''resistance''': Sets percent damage taken from combat&lt;br /&gt;
** '''replace''': If set to &amp;quot;true&amp;quot;, any new values replace the old ones. Otherwise, new values are added to old values (negative values allowed).&lt;br /&gt;
** '''[resistance]''': a subtag that describes the new resistance just like in [[UnitTypeWML]] for describing a unit type&lt;br /&gt;
* '''variation''': switches the unit into one of its variations.&lt;br /&gt;
** '''name''': the id of the variation to invoke.&lt;br /&gt;
* '''type''': transforms the unit into a new unit_type.&lt;br /&gt;
** '''name''': the id of the unit_type to invoke.&lt;br /&gt;
* '''status''': modifies the status affecting the unit.&lt;br /&gt;
** '''add''': a list of status modifications to add. Beware, these may be reapplied later, such as when the unit is recalled or levels up; if in an event, you can use [[InternalActionsWML|[store_unit]]] and [[DirectActionsWML|[unstore_unit]]], modifying unit.status.name directly, to avoid this, or if you are creating the unit, you can just add it to the unit's [status] tag in the [unit] tag.  These are listed in [status], [[SingleUnitWML]].&lt;br /&gt;
** '''remove''': a list of status modifications to remove.&lt;br /&gt;
* '''zoc''': toggle the zone of control.&lt;br /&gt;
** '''value''': new value for zoc (0=disable, other=enable).&lt;br /&gt;
* '''profile''': customize the profile of the unit. See [[UnitTypeWML]].&lt;br /&gt;
** '''portrait''': new image to display when the unit speaks.&lt;br /&gt;
** '''small_portrait''': new image to display in unit reports.&lt;br /&gt;
** '''description''': sets the text to display when hovering over the unit's type in the righthand pane.&lt;br /&gt;
* '''new_ability''': Adds one or more abilities to a unit.&lt;br /&gt;
** '''[abilities]''': A subtag that contains the ability definitions.&lt;br /&gt;
* '''remove_ability''': Removes one or more abilities from a unit. Abilities are not reference counted: added, added, removed = gone.&lt;br /&gt;
** '''[abilities]''': A subtag that contains the ability definitions. Strictly speaking, all that is needed is the id= inside some tag.&lt;br /&gt;
* '''new_animation''': contain animations that will be added to the unit, it can contain multiple animation blocks, and a single &amp;quot;id=&amp;quot; line. That Id should be unique for each effect block and is used by the engine to reuse WML parsing, making the loading faster.&lt;br /&gt;
* '''image_mod''': modify the image path function([[ImagePathFunctionWML]]) of all the unit's frames.&lt;br /&gt;
** '''replace''': replaces the image path function(s) to be used, e.g. &amp;quot;RC(magenta&amp;gt;red)&amp;quot;&lt;br /&gt;
** '''add''': adds an image path function without removing any existing ones.&lt;br /&gt;
* '''ellipse''': Change the image used for the unit's ellipse.&lt;br /&gt;
**'''ellipse''' : the new image to use.&lt;br /&gt;
* {{DevFeature1.11}} '''halo''': Change the image used for the unit's halo.&lt;br /&gt;
**'''halo''': the new image to use.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[UnitTypeWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
* [[AnimationWML]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=46680</id>
		<title>ConditionalActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=ConditionalActionsWML&amp;diff=46680"/>
		<updated>2012-06-09T10:34:52Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* [while] */ Corrected number of maximum iterations&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
Part of [[ActionWML]], Conditional Actions WML is used to describe container actions that create branching and flow control for WML. The [[#Conditional Actions|conditional actions]] act as gatekeepers, encapsulating other actions with [[#Condition Tags|conditions]] which must be met before an action can take place. These conditional actions also contain the actions which will take place if those conditions are met and, in some cases, what actions will take place if they are ''not'' met.&lt;br /&gt;
&lt;br /&gt;
== Conditional Actions ==&lt;br /&gt;
&lt;br /&gt;
These actions describe actions that should be executed only if certain conditions are met.&lt;br /&gt;
&lt;br /&gt;
=== [if] ===&lt;br /&gt;
&lt;br /&gt;
Executes actions only if the contained [[#Condition Tags|conditions]] are met.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[then]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[then]''': Contains [[ActionWML|actions]] which should be executed if all conditions evaluate as true ''or'' if any single '''[or]''' tag evaluates as true.&lt;br /&gt;
&lt;br /&gt;
* '''[else]''': Contains [[ActionWML|actions]] which should be executed if any condition evaluates as false ''and'' '''all''' of the '''[or]''' tags evaluate as false.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Attention''': There are tags named [if] and [else] inside [animation] (see [[AnimationWML#.5Bif.5D_and_.5Belse.5D|AnimationWML]]), which have a different syntax.&lt;br /&gt;
&lt;br /&gt;
=== [switch] ===&lt;br /&gt;
&lt;br /&gt;
The '''[switch]''' tag is a special case because it does not use [[#Condition Tags|Condition Tags]] to control whether actions are performed. Instead, it executes different sets of actions based on the value of a variable.&lt;br /&gt;
&lt;br /&gt;
* '''variable''': The name of the variable to check.&lt;br /&gt;
* '''[case]''': Case tag which forms a block containing:&lt;br /&gt;
** '''value''': The value to test the variable's value against. &lt;br /&gt;
This can be a comma separated list of values.&lt;br /&gt;
** [[ActionWML|Action WML]]: Action WML to execute if the variable matches the value. (The rest of the '''[case]''' block after the '''value''' attribute.)&lt;br /&gt;
* '''[else]''': Else tag which forms a block of [[ActionWML|Action WML]] to execute if no '''[case]''' block contains a '''value''' matching the value of the '''variable'''.&lt;br /&gt;
&lt;br /&gt;
Example usage:&lt;br /&gt;
  [switch]&lt;br /&gt;
     variable=foo&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;A&amp;quot;&lt;br /&gt;
        ... WML if foo=A ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [case]&lt;br /&gt;
        value=&amp;quot;B&amp;quot;&lt;br /&gt;
        ... WML if foo=B ...&lt;br /&gt;
     [/case]&lt;br /&gt;
     [else]&lt;br /&gt;
        ... WML if not foo=A nor foo=B ...&lt;br /&gt;
     [/else]&lt;br /&gt;
  [/switch]&lt;br /&gt;
&lt;br /&gt;
=== [while] ===&lt;br /&gt;
&lt;br /&gt;
Like the '''[if]''' tag, executes actions only if conditions described in the contained [[#Condition Tags|conditions]] are met. Additionally, the '''[while]''' tag ''continues'' to execute the actions until the contained [[#Condition Tags|conditions]] are no longer met. Executes a maximum of 65536 iterations per invocation.&lt;br /&gt;
&lt;br /&gt;
* [[#Condition Tags|Condition Tags]]: Conditions which must be met for the actions in the '''[do]''' tag to be executed.&lt;br /&gt;
&lt;br /&gt;
* '''[do]''': contains [[ActionWML|actions]] that should be executed repeatedly until some condition is false.&lt;br /&gt;
&lt;br /&gt;
The '''[while]''' tag is useful for iterating over an array.&lt;br /&gt;
An array is a list of values.&lt;br /&gt;
The ''number''th value in the array '''array''' is stored in the WML variable '''''array''[number]'''.&lt;br /&gt;
Note that if '''number''' is the value of the variable '''variable''',&lt;br /&gt;
the expression '''$''array''[$variable]''' will return the ''number''th value in ''array''.&lt;br /&gt;
&lt;br /&gt;
==== 'FOREACH' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to create a ''for-each'' iteration format. This is useful, for example, when you want to iterate over each row in a table. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#FOREACH FOREACH] and [http://www.wesnoth.org/macro-reference.xhtml#NEXT NEXT] macros.&lt;br /&gt;
&lt;br /&gt;
==== 'REPEAT' Macro ====&lt;br /&gt;
This macro simplifies the use of a '''[while]''' tag to execute the same  [[ActionWML|actions]] repeatedly for a specified number of times. To use it, use the [http://www.wesnoth.org/macro-reference.xhtml#REPEAT REPEAT] macro.&lt;br /&gt;
&lt;br /&gt;
=== [command] ===&lt;br /&gt;
&lt;br /&gt;
This tag is more of an Unconditional Action: when it is encountered, the [[ActionWML|actions]] in its content are simply executed once. In practice, this tag serves little purpose. However, it may be used to arrange actions together in logical groups, for example, with actions that are stored in an array and later inserted.&lt;br /&gt;
(It is also used inside of [set_menu_item] and [option] of [[InterfaceActionsWML]].)&lt;br /&gt;
&lt;br /&gt;
== Condition Tags ==&lt;br /&gt;
&lt;br /&gt;
===True Condition Tags===&lt;br /&gt;
These tags describe conditions which must be met before an action can take place. Some or all of them are used in the various [[#Conditional Actions|Conditional Actions]].&lt;br /&gt;
&lt;br /&gt;
; [have_unit]&lt;br /&gt;
: A unit with greater than zero hit points matching this filter exists.&lt;br /&gt;
:* [[StandardUnitFilter]] '''*''': Selection criteria. Do not use a [filter] tag.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of units equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
:* '''search_recall_list''': ''(Optional)'' If 'yes', search through recall list too. (Default is 'no')&lt;br /&gt;
&lt;br /&gt;
; [have_location]&lt;br /&gt;
: A location matching this filter exists.&lt;br /&gt;
:* [[StandardLocationFilter]]: Selection criteria.&lt;br /&gt;
:* '''count''': ''(Optional)'' If used, a number of locations equal to the value must match the filter. Accepts a number, range, or comma separated range. If not used, the default value is &amp;quot;1-99999&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; [variable]&lt;br /&gt;
: Test the value of a WML [[VariablesWML|variable]] against another value.&lt;br /&gt;
:* '''name''': The name of the variable to test.&lt;br /&gt;
:* ''&amp;lt;comparison&amp;gt;'': '''One''' of the following keys must be used to compare the value of the named variable, represented as ''$name'' below, against another value:&lt;br /&gt;
:** '''contains''': ''$name'' contains this string value.&lt;br /&gt;
:** '''equals''': ''$name'' is equal (string wise) to this value.&lt;br /&gt;
:** '''not_equals''': ''$name'' is not equal (string wise) to this value.&lt;br /&gt;
:** '''numerical_equals''': ''$name'' is equal (numerically) to this value. &lt;br /&gt;
:** '''numerical_not_equals''': ''$name'' is not equal (numerically) to this value. '''*'''&amp;lt;br /&amp;gt;'''*''' Using equals is faster. The point of numerical_equals and boolean_equals is not performance, it's representation. For instance, &amp;quot;1&amp;quot; and &amp;quot;1.0&amp;quot; are not equal as strings but they are equal as numbers; and &amp;quot;yes&amp;quot; and &amp;quot;true&amp;quot; are not equal as strings but they are equal as booleans. (This also explains why equals is faster: it is a straightforward comparison that doesn't try to understand what you have written.)&lt;br /&gt;
:** '''greater_than''': ''$name'' is greater than this value.&lt;br /&gt;
:** '''greater_than_equal_to''': ''$name'' is greater than or equal to this value.&lt;br /&gt;
:** '''less_than''': ''$name'' is less than this value.&lt;br /&gt;
:** '''less_than_equal_to''': ''$name'' is less than or equal to this value.&lt;br /&gt;
:** '''boolean_equals''': ''$name'' has an equivalent boolean value. '''*'''&lt;br /&gt;
:** '''boolean_not_equals''': ''$name'' does not have an equivalent boolean value. '''*'''&lt;br /&gt;
====Boolean Values====&lt;br /&gt;
When values are evaluated as boolean values they are checked to see if they are ''false'' or ''true''.&lt;br /&gt;
&lt;br /&gt;
* These values are evaluated as ''true'': '''&amp;quot;yes&amp;quot;''' and '''&amp;quot;true&amp;quot;'''&lt;br /&gt;
* These values are evaluated as ''false'': '''&amp;quot;no&amp;quot;''', '''&amp;quot;false&amp;quot;''' and '''&amp;quot;&amp;quot;'''(uninitialized)&lt;br /&gt;
** However, in contexts where ''true'' is defined as the default value, an uninitialized value would be considered true. &lt;br /&gt;
&lt;br /&gt;
'''Warning:''' Do not use &amp;quot;off&amp;quot;, &amp;quot;on&amp;quot;, integers, floating-point numbers or anything else than the above as booleans.&lt;br /&gt;
&lt;br /&gt;
=== Meta Condition Tags ===&lt;br /&gt;
&lt;br /&gt;
These tags aren't really conditions, themselves. Instead they are wrapped around condition tags to group them into multiple conditions that must all be met, lists of conditions that only one must be met, or conditions that must not be met. These are handled in order in any combination you can think of. One important thing to remember is if you are using '''[or]''' tags, the first conditional statement should ''not'' have an '''[or]''' tag wrapped around it.&lt;br /&gt;
&lt;br /&gt;
; [and]&lt;br /&gt;
: A condition which must evaluate to true in addition to any others. Useful as a bracket for complex conditions, but not strictly necessary.&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[and]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
; [or]&lt;br /&gt;
: A condition which, if it evaluates to true, is all that is necessary for the conditions to be met. In other words, if all other conditions are false, but one '''[or]''' condition is true, the conditions have been met for an [[:Category:ActionsWML|action]] to take place. (See [[AdvancedConditionalWML|Example]])&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[or]''' tag evaluates to true. &lt;br /&gt;
&lt;br /&gt;
; [not]&lt;br /&gt;
: A condition which reverses the evaluation of the contained condition(s).&lt;br /&gt;
:* [[#Condition Tags|Condition Tags]]: If these evaluate to true, the '''[not]''' tag evaluates to false. If these evaluate to false, the '''[not]''' tag evaluates to true.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[VariablesWML]]&lt;br /&gt;
* [[InternalActionsWML]]&lt;br /&gt;
* [[DirectActionsWML]]&lt;br /&gt;
* [[InterfaceActionsWML]]&lt;br /&gt;
* [[EventWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;br /&gt;
[[Category: ActionsWML]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=SingleUnitWML&amp;diff=46679</id>
		<title>SingleUnitWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=SingleUnitWML&amp;diff=46679"/>
		<updated>2012-06-08T16:23:54Z</updated>

		<summary type="html">&lt;p&gt;Elvish Hunter: /* How to describe a single unit */ Documented unit.attacks_left&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== How to describe a single unit ==&lt;br /&gt;
&lt;br /&gt;
This tag, '''[unit]''', describes a single unit on the map, for example Konrad.&lt;br /&gt;
It is different from the [unit_type] in [units], which describes a class of units. However it takes many of the same keys and thus can generally override the inherited properties from the associated [unit_type].&lt;br /&gt;
&lt;br /&gt;
[unit] can be used inside [side] ([[SideWML]]) for units present at start of the scenario, or as [[DirectActionsWML]] for units created during the game. (It is also used in save-files.)&lt;br /&gt;
&lt;br /&gt;
The following keys are recognized:&lt;br /&gt;
* '''type''': the ID of the unit's unit type. See [[UnitTypeWML]].&lt;br /&gt;
&lt;br /&gt;
* '''side''': the side that the unit is on. It has to be an existing side, even if the unit is created in a variable.&lt;br /&gt;
&lt;br /&gt;
* '''gender''': can be set to male or female to designate the gender of the unit. Default is male, but if the unit has only a female variant it will be female.&lt;br /&gt;
&lt;br /&gt;
* '''x''', '''y''': the location of the unit. By default ( see '''placement''') if a location isn't provided and the side the unit will belong to has a recall list, the unit will be created on the recall list.&lt;br /&gt;
&lt;br /&gt;
* '''placement''': How the unit should be placed: can be one value or a comma-separated list of values. Default value is  'map,leader' for a leader given directly in [side], &amp;quot;&amp;quot; otherwise. By default, 'map,recall' is implicitly appended to the end of the list.&lt;br /&gt;
** '''map''': If x,y are explicitly given and point to a valid on-map location - try to place the unit at the nearest free location to there, never overwriting existing units. Successful if x,y are given and a valid on-map vacant location near it can be found.&lt;br /&gt;
** '''leader''': Try to place unit near the leader, if leader is not present or is in recall list - try to place unit near the start location for this side. Successful if a valid on-map vacant location can be found near leader or near start location.&lt;br /&gt;
** '''recall''': Place unit on recall list. Always successful. &lt;br /&gt;
** '''map_overwrite''': If x,y are explicitly given and point to a valid on-map location - try to place unit at this location, if there was a unit there - overwriting it, without firing events. note: This value does currently (1.9.12) not work since it apparently wasn't implemented; see also http://gna.org/bugs/?15113&lt;br /&gt;
** '''map_passable''': If x,y are explicitly given and point to a valid on-map location - try to place unit at this location; if the hex is of an impassable terrain for the unit being placed, or is already occupied by another unit, the new unit will be placed in the nearest vacant hex.&lt;br /&gt;
&lt;br /&gt;
* '''to_variable''': creates the unit into the given variable instead of placing it on the map.&lt;br /&gt;
&lt;br /&gt;
* '''id''': a unique identifier for the unit. This is (usually) not displayed to the player, but is to be used only for identifying and filtering for units. If not specified or when a unit is normally recruited, a random one will be generated for the unit to ensure that each unit has a unique ''id'' attribute.  In older versions, the '''description''' attribute specified a unique ID. (The one instance when an id is displayed to the player is when the leader's id is used as the default for a [[SideWML|side]]'s '''current_player''' attribute.)&lt;br /&gt;
&lt;br /&gt;
* '''name''': the user-visible name of the unit. Note that the player may use the &amp;quot;rename unit&amp;quot; action to change this.&lt;br /&gt;
&lt;br /&gt;
* '''generate_name''': (default=yes) will generate a new name if there isn't one specifed for the unit, as if the unit were a freshly-recruited one&lt;br /&gt;
&lt;br /&gt;
* '''unrenamable''': if 'yes', the user-visible name of the unit cannot be changed by the player (which is only possible when the unit is on the player's side anyway).&lt;br /&gt;
&lt;br /&gt;
* '''traits_description''': the description of the unit's traits which is displayed. However if it is not specified explicitly, the unit's actual traits' names will be used instead, so it is normally not necessary to set this.&lt;br /&gt;
&lt;br /&gt;
* '''random_traits''': &amp;quot;no&amp;quot; will prevent random trait generation for units. You should only need to set this for placed nonleaders in multiplayer games or if you want to give a unit less traits than it would normally get for its unit type. When generating traits for a unit, first traits the unit has already been given are excluded. Then &amp;quot;musthave&amp;quot; traits (undead, mechanical) for the unit type are given. Then for leaders ('''canrecruit=yes''') traits that are not available to &amp;quot;any&amp;quot; (currently that's all of them to avoid a multiplayer OOS issue, but later will be restricted based on multiplayer play balance issues) are removed from consideration. Then traits are added randomly until the maximum allowed for the unit type is reached or there are no more available traits. Random traits can now be used in MP games but only when spawned in an event, so not for leaders and other units in the [side] definition.&lt;br /&gt;
&lt;br /&gt;
* '''random_gender''': &amp;quot;yes&amp;quot; will cause the gender of the unit with male and female variations to be male 50% of the time, female 50% of the time.  If the unit has only one gender variant it will always be given the correct one.&lt;br /&gt;
&lt;br /&gt;
* '''canrecruit''': a special key for leaders.&lt;br /&gt;
** '''no''': default. Unit cannot recruit.&lt;br /&gt;
** '''yes''': unit can recruit.&lt;br /&gt;
: Normally when a team controls no units with '''canrecruit=yes''', that team loses. However, even if your team has lost you continue to play with whatever units you still have until the scenario is over. Usually scenarios end when only one team is left with a leader that can recruit, but special victory conditions can be set up in campaigns. Normally you want to set the leader of a side with '''canrecruit=yes'''. If you don't want the leader to recruit, it is usually better to just not give him any unit types to recruit, than to make a special victory condition. Units with '''canrecruit=yes''' are exempt from upkeep costs. So that leaders do not need to be given the ''loyal'' trait.&lt;br /&gt;
: More than one unit with '''canrecruit=yes''' for the same side (see [[SideWML]]) are allowed in single player, if the side is human-controlled.&lt;br /&gt;
&lt;br /&gt;
* '''extra_recruit''': a list of unit types which this unit can recruit in addition to the ones given by its [side]recruit=, only working for units with '''canrecruit=yes'''.&lt;br /&gt;
&lt;br /&gt;
* '''variation''': the variation of itself the unit should be created as.&lt;br /&gt;
&lt;br /&gt;
* '''upkeep''': the amount of upkeep the unit costs.&lt;br /&gt;
** '''loyal''': no upkeep cost. Can be changed by the effect 'loyal' (see [[EffectWML]])&lt;br /&gt;
** '''free''': synonymous with &amp;quot;loyal&amp;quot;.&lt;br /&gt;
** '''full''': unit costs ''level'' upkeep (see [[UnitTypeWML]]).&lt;br /&gt;
** An integer can be used to set the upkeep cost to that number.&lt;br /&gt;
** The default is &amp;quot;full&amp;quot;.&lt;br /&gt;
** Leaders (units with '''canrecruit=yes''') never pay upkeep no matter what upkeep is set to.&lt;br /&gt;
** Normally you don't want to muck with this value. If you want to give a side units without upkeep costs, give those units the 'loyal' trait.&lt;br /&gt;
&lt;br /&gt;
* '''overlays''': a list of images that are overlayed on the unit.&lt;br /&gt;
&lt;br /&gt;
* '''goto_x''':, '''goto_y''': UI settings that control courses. Default is 0,0 i.e. the unit is not on a course.&lt;br /&gt;
&lt;br /&gt;
* '''hitpoints''': the HP of the unit. Default is the max HP for ''type''.&lt;br /&gt;
&lt;br /&gt;
* '''experience''': the XP of the unit. Default is 0.&lt;br /&gt;
&lt;br /&gt;
* '''moves''': number of movement points the unit has left. Default is the movement for its unit type.&lt;br /&gt;
&lt;br /&gt;
* '''attacks_left''': number of attacks the unit has left. Default is equal to the attacks key for its unit type, that usually is 1 (see ''max_attacks'' below).&lt;br /&gt;
&lt;br /&gt;
* '''resting''': whether the unit has not moved yet this turn. Used to decide whether to give a unit rest healing.&lt;br /&gt;
&lt;br /&gt;
* '''role''': used in standard unit filter ([[FilterWML]]). Can be set using [role] (see [[InternalActionsWML]]).&lt;br /&gt;
&lt;br /&gt;
* '''ai_special''': causes the unit to act differently&lt;br /&gt;
** &amp;quot;guardian&amp;quot; the unit will not move, except to attack something in the turn it moves (so, it only can move if an enemy unit gets within range of it). {{DevFeature1.11}} Does the same as '''[status] guardian = 'yes''''.&lt;br /&gt;
&lt;br /&gt;
* '''facing''': which way the unit is facing (this only affects how the unit is displayed).&lt;br /&gt;
** Possible values are '''se''', '''s''', '''sw''', '''nw''', '''n''', '''ne'''. Using '''sw''' is preferred for a &amp;quot;reversed&amp;quot; facing (looking to the left) and '''se''' for a normal (looking to the right) facing.&lt;br /&gt;
&lt;br /&gt;
* '''profile''': sets a portrait image for this unit. If the unit type already has a portrait set, this is used instead for this unit. When the unit advances, if the value of profile is different from the unit-type portrait, that value is preserved. If the profile field is empty or the same as the unit-type portrait, the level-advance changes the unit portrait to the default for the new level and type. See [[UnitTypeWML]] for the rules used for locating files.&lt;br /&gt;
** &amp;quot;unit_image&amp;quot; if given instead of a filename, uses the unit's base image as the portrait (in the same manner that unit types without portraits do by default).&lt;br /&gt;
&lt;br /&gt;
* '''small_profile''': sets a small portrait image for this unit. See the '''profile''' attribute above for advancement and special values. As with [[UnitTypeWML]], the location heuristic of the '''profile''' attribute is disabled when the '''small_profile''' attribute is provided.&lt;br /&gt;
&lt;br /&gt;
* '''max_attacks''': Default is 1. The number of attacks the unit can have per turn.&lt;br /&gt;
&lt;br /&gt;
* '''max_experience''': The experience the unit needs to advance. If left out, this information will be taken from the unit's file.&lt;br /&gt;
&lt;br /&gt;
* '''max_hitpoints''': The maximum hitpoints the unit has. If left out, this information will be taken from the unit's file.&lt;br /&gt;
&lt;br /&gt;
* '''max_moves''': The maximum moves the unit has. If left out, this information will be taken from the unit's file.&lt;br /&gt;
&lt;br /&gt;
* '''animate''': if ''yes'', fades the unit in like when it's recruited/recalled.&lt;br /&gt;
&lt;br /&gt;
* '''[status]''' the status of the unit. This affects different features of the unit, for example whether the unit loses health each turn. Default for all keys is 'no', but this can be changed by the scenario or by special abilities (see [[AbilitiesWML]]). The Status Table displays the status of each unit using the three images '''misc/poisoned.png''', '''misc/slowed.png''' and '''misc/petrified.png'''; other keys do not appear in the Status Table.&lt;br /&gt;
** '''poisoned''': if 'yes', the unit loses 8 HP each turn. See also ''heals'', ''cures'', [[AbilitiesWML]].&lt;br /&gt;
** '''slowed''': if 'yes', the unit has 50% of its normal movement and does half damage. When the controller of the unit's turn is over, ''slowed'' is set to 'off'  &lt;br /&gt;
** '''petrified''': if 'yes', the unit cannot move, attack, or be attacked.&lt;br /&gt;
** '''uncovered''': if 'yes', the unit has performed an action (e.g. attacking) that causes it to no longer be hidden until the next turn.&lt;br /&gt;
** '''guardian''': if 'yes', the unit will not move, except to attack something in the turn it moves (so, it only can move if an enemy unit gets within range of it). {{DevFeature1.11}} Does the same as '''ai_special = &amp;quot;guardian&amp;quot;'''.&lt;br /&gt;
** '''unhealable''': if set to 'yes', the unit cannot be healed.&lt;br /&gt;
** One can add other keys to [status], but they must have boolean values. For example, a scenario can set unit.status.''my_custom_key'' to 'yes' or 'no'.&lt;br /&gt;
&lt;br /&gt;
* '''[variables]''' a set of variables that will be stored when this unit is stored (See [store_unit], [[InternalActionsWML]]). The attribute '''variable'''='''value''' means that when the unit is stored in the array ''unit'', the variable '''unit'''.variables.''variable'' will have the value ''value'' (See [[VariablesWML]]).&lt;br /&gt;
&lt;br /&gt;
* '''[modifications]''' changes that have been made to the unit.&lt;br /&gt;
** '''[trait]''' a trait the unit has. Same format as [trait], [[UnitsWML]].&lt;br /&gt;
** '''[object]''' an object the unit has. Same format as [object], [[DirectActionsWML]].&lt;br /&gt;
** '''[advance]''' an advancement the unit has. Same format as [advancement], [[UnitTypeWML]]. Might be used if the unit type has some advancements, but this particular one is supposed to have some of them already taken.&lt;br /&gt;
&lt;br /&gt;
* '''[filter_recall]''' A leader can only recall those units which pass the SUF.&lt;br /&gt;
**'''[[StandardUnitFilter]]''' tags and keys&lt;br /&gt;
&lt;br /&gt;
* '''unit_description''': overrides the unit type description for this unit. You will probably want to set up a ''post_advance'' [[EventWML|event]] to override the default description after promotions. Or better, use an object with a profile [[EffectWML|effect(s)]] to filter on unit type and change the unit description and/or portrait.&lt;br /&gt;
&lt;br /&gt;
* '''[event]''' The event is copied from this unit's wml description into the scenario. The event is carried along with the unit (it can advance etc) and inserted into every scenario where this unit is first created. A [unit][event] is required a non-empty id= attribute.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[UnitTypeWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category:WML Reference]]&lt;/div&gt;</summary>
		<author><name>Elvish Hunter</name></author>
		
	</entry>
</feed>