<?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=SigurdTheDragon</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=SigurdTheDragon"/>
	<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/Special:Contributions/SigurdTheDragon"/>
	<updated>2026-06-07T09:33:49Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=43802</id>
		<title>LuaWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=43802"/>
		<updated>2011-10-07T04:06:41Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* Sides */  correction of match_sides to match_side&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]]. In {{DevFeature1.9}} the functions clock, date, time and difftime from the [http://www.lua.org/manual/5.1/manual.html#5.8 os] library are also available. Keep in mind that they aren't multiplayer- and replay-save.&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#wesnoth.game_events|wesnoth.game_events]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#helper.parsed|helper.parsed]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_literal|helper.shallow_literal]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_parsed|helper.shallow_parsed]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.textdomain|wesnoth.textdomain]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.delay|wesnoth.delay]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.float_label|wesnoth.float_label]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.highlight_hex|wesnoth.highlight_hex]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_hex|wesnoth.select_hex]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.scroll_to_tile|wesnoth.scroll_to_tile]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.play_sound|wesnoth.play_sound]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_music|wesnoth.set_music]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_dialog|wesnoth.show_dialog]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_value|wesnoth.set_dialog_value]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_dialog_value|wesnoth.get_dialog_value]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_callback|wesnoth.set_dialog_callback]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_canvas|wesnoth.set_dialog_canvas]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_displayed_unit|wesnoth.get_displayed_unit]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.theme_items|wesnoth.theme_items]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#helper.get_user_choice|helper.get_user_choice]]&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.match_location|wesnoth.match_location]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_tile_overlay|wesnoth.add_tile_overlay]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_tile_overlay|wesnoth.remove_tile_overlay]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#items.place_image|items.place_image]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#items.place_halo|items.place_halo]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#items.remove|items.remove]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.match_unit|wesnoth.match_unit]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_unit|wesnoth.put_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_recall_units|wesnoth.get_recall_units]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_recall_unit|wesnoth.put_recall_unit]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_modification|wesnoth.add_modification]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.races|wesnoth.races]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_traits|wesnoth.get_traits]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.simulate_combat|wesnoth.simulate_combat]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.transform_unit|wesnoth.transform_unit]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_sides|wesnoth.get_sides]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.match_side|wesnoth.match_side]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_starting_location|wesnoth.get_starting_location]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_pairs|location_set.of_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_wml_var|location_set.of_wml_var]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:empty|location_set:empty]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:size|location_set:size]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:clear|location_set:clear]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:get|location_set:get]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:insert|location_set:insert]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:remove|location_set:remove]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_pairs|location_set:of_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_wml_var|location_set:of_wml_var]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_pairs|location_set:to_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_stable_pairs|location_set:to_stable_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_wml_var|location_set:to_wml_var]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union|location_set:union]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter|location_set:inter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:iter|location_set:iter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:stable_iter|location_set:stable_iter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:filter|location_set:filter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union_merge|location_set:union_merge]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter_merge|location_set:inter_merge]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_image_size|wesnoth.get_image_size]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compare_versions|wesnoth.compare_versions]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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''' {{DevFeature1.9}}. 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>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=43801</id>
		<title>LuaWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=43801"/>
		<updated>2011-10-07T04:05:45Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* Sides */  added listings for match_sides and get_starting_location&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]]. In {{DevFeature1.9}} the functions clock, date, time and difftime from the [http://www.lua.org/manual/5.1/manual.html#5.8 os] library are also available. Keep in mind that they aren't multiplayer- and replay-save.&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#wesnoth.game_events|wesnoth.game_events]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#helper.parsed|helper.parsed]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_literal|helper.shallow_literal]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_parsed|helper.shallow_parsed]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.textdomain|wesnoth.textdomain]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.delay|wesnoth.delay]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.float_label|wesnoth.float_label]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.highlight_hex|wesnoth.highlight_hex]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_hex|wesnoth.select_hex]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.scroll_to_tile|wesnoth.scroll_to_tile]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.play_sound|wesnoth.play_sound]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_music|wesnoth.set_music]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_dialog|wesnoth.show_dialog]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_value|wesnoth.set_dialog_value]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_dialog_value|wesnoth.get_dialog_value]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_callback|wesnoth.set_dialog_callback]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_canvas|wesnoth.set_dialog_canvas]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_displayed_unit|wesnoth.get_displayed_unit]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.theme_items|wesnoth.theme_items]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#helper.get_user_choice|helper.get_user_choice]]&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.match_location|wesnoth.match_location]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_tile_overlay|wesnoth.add_tile_overlay]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_tile_overlay|wesnoth.remove_tile_overlay]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#items.place_image|items.place_image]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#items.place_halo|items.place_halo]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#items.remove|items.remove]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.match_unit|wesnoth.match_unit]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_unit|wesnoth.put_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_recall_units|wesnoth.get_recall_units]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_recall_unit|wesnoth.put_recall_unit]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_modification|wesnoth.add_modification]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.races|wesnoth.races]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_traits|wesnoth.get_traits]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.simulate_combat|wesnoth.simulate_combat]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.transform_unit|wesnoth.transform_unit]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_sides|wesnoth.get_sides]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.match_sides|wesnoth.match_sides]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_starting_location|wesnoth.get_starting_location]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_pairs|location_set.of_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_wml_var|location_set.of_wml_var]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:empty|location_set:empty]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:size|location_set:size]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:clear|location_set:clear]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:get|location_set:get]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:insert|location_set:insert]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:remove|location_set:remove]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_pairs|location_set:of_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_wml_var|location_set:of_wml_var]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_pairs|location_set:to_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_stable_pairs|location_set:to_stable_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_wml_var|location_set:to_wml_var]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union|location_set:union]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter|location_set:inter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:iter|location_set:iter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:stable_iter|location_set:stable_iter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:filter|location_set:filter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union_merge|location_set:union_merge]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter_merge|location_set:inter_merge]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_image_size|wesnoth.get_image_size]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compare_versions|wesnoth.compare_versions]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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''' {{DevFeature1.9}}. 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>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=PersistenceWML&amp;diff=43689</id>
		<title>PersistenceWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=PersistenceWML&amp;diff=43689"/>
		<updated>2011-09-15T20:07:26Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* WML Syntax */ Edited set and get examples to match description under immediate section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DevFeature1.9}}&lt;br /&gt;
{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
== Purpose ==&lt;br /&gt;
Persistent Variables are used to record information that can be accessed across savegames and session instances. &lt;br /&gt;
&lt;br /&gt;
For instance, assume that completing a campaign on hard mode should unlock a special item in subsequent playthroughs of this campaign. With a persistent variable, that can be recorded, and made available to the campaign on later plays.&lt;br /&gt;
&lt;br /&gt;
This can also be used to allow two or more related campaigns to communicate with each other about what has happened in each, allowing the player's choices in one campaign to influence the state of another.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Persistent Variables work like [[VariablesWML|normal Variables]], with a few differences.&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;center&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;text-align:center; color:red; font-size: larger&amp;quot;&lt;br /&gt;
&lt;br /&gt;
| WARNING: in multiplayer, do not use persistent variables in '''prestart''', '''start''', and other non-synchronized events.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* During multiplayer, Persistent Variables '''''cannot''''' be used in events that occur before side 1 turn 1, and will force a quit if they occur there.&lt;br /&gt;
* Persistent Variables may be assigned, retrieved, or cleared, but not directly queried.&lt;br /&gt;
* Persistent Variables may only be assigned from an existing variable, not directly from a constant&lt;br /&gt;
* In addition to a name, each Persistent Variable must have a namespace&lt;br /&gt;
* In multiplayer campaigns, each Persistent Variable also requires a side&lt;br /&gt;
* Persistent Variables will retain their values after wesnoth is closed, until they are cleared or the file containing their namespace is erased or lost.&lt;br /&gt;
&lt;br /&gt;
== Transactions ==&lt;br /&gt;
For the purposes of efficiency, and gameplay consistency, persistent variables are usually not written out to file immediately. Instead, they are grouped into transactions which are sets of changes that are either all written at once, or not written at all. &amp;lt;br/&amp;gt;&lt;br /&gt;
The policy regarding persistent variables will be written is as follows:&lt;br /&gt;
*Transactions will be committed (written to permanent file) whenever the game autosaves, whenever the player saves the game manually, or whenever a scenario is completed in either victory or defeat.&lt;br /&gt;
*Transactions will be cancelled (ignored and wiped from memory) whenever the player loads an earlier savegame, or quits without saving.&lt;br /&gt;
*A WML author can mark a change as an exception to a transaction, to be committed immediately by itself, by using setting the attribute &amp;quot;immediate&amp;quot; to &amp;quot;yes&amp;quot; in a [set_global_variable] or [clear_global_variable] tag. Such operations will be written immediately, regardless of the transaction status, without committing any waiting transactions.&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;center&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
| NOTE: Because of the interaction between persistent variable transactions and user loading/saving of games, it is suggested that any variables a WML author wants to remain consistent for a single playthrough of a scenario should be read in immediately at the beginning of the scenario (side 1 turn 1), and set or cleared only in the victory and/or defeat events.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== WML Syntax ==&lt;br /&gt;
The following WML Tags are provided.&lt;br /&gt;
    [set_global_variable]&lt;br /&gt;
      namespace=my_addon&lt;br /&gt;
      from_local=foo&lt;br /&gt;
      to_global=my_variable_name&lt;br /&gt;
      side=1&lt;br /&gt;
      immediate=no&lt;br /&gt;
    [/set_global_variable]&lt;br /&gt;
Assigns a persistent variable with the contents of a standard variable&lt;br /&gt;
&lt;br /&gt;
    [get_global_variable]&lt;br /&gt;
      namespace=my_addon&lt;br /&gt;
      from_global=my_variable_name&lt;br /&gt;
      to_local=foo&lt;br /&gt;
      side=1&lt;br /&gt;
    [/get_global_variable]&lt;br /&gt;
Retrieves the contents of a persistent variable and stores them in a standard variable.&lt;br /&gt;
and&lt;br /&gt;
    [clear_global_variable]&lt;br /&gt;
      namespace=my_addon&lt;br /&gt;
      global=my_variable_name&lt;br /&gt;
      side=1&lt;br /&gt;
      immediate=no&lt;br /&gt;
    [/clear_global_variable]&lt;br /&gt;
Clears a persistent variable entirely.&lt;br /&gt;
=== Attribute information ===&lt;br /&gt;
==== namespace ====&lt;br /&gt;
This atribute specifies the name of the namespace that the persistent variable resides in.&lt;br /&gt;
&lt;br /&gt;
*In this attribute, the character &amp;quot;.&amp;quot; means &amp;quot;child of&amp;quot;, &lt;br /&gt;
**A namespace equal to &amp;quot;foo.bar&amp;quot; will access a &amp;quot;bar&amp;quot; namespace inside &amp;quot;foo&amp;quot;, creating it if it doesn't already exist, and store the peristent variable inside &amp;quot;bar&amp;quot;.&lt;br /&gt;
**If this attribute begins with &amp;quot;.&amp;quot; it will access a child namespace of the default namespace.&lt;br /&gt;
***A namespace equal to &amp;quot;.bar&amp;quot; with the default namespace of &amp;quot;foo&amp;quot; will access a &amp;quot;bar&amp;quot; namespace inside the &amp;quot;foo&amp;quot; namespace.&lt;br /&gt;
*In this attribute, the character &amp;quot;^&amp;quot; means &amp;quot;parent of&amp;quot;, must follow a namespace and may only be directly followed by a &amp;quot;.&amp;quot; or another &amp;quot;^&amp;quot;. And is provided so that content creators can easily use macros to eliminate data repitition for the most frequently used namespaces.&lt;br /&gt;
**a namespace equal to &amp;quot;{def}^&amp;quot; with the def macro &amp;quot;foo&amp;quot; will access the &amp;quot;foo&amp;quot; namespace.&lt;br /&gt;
**a namespace equal to &amp;quot;{def}^&amp;quot; with the def macro &amp;quot;foo.bar&amp;quot; will access the &amp;quot;foo&amp;quot; namespace.&lt;br /&gt;
**a namespace equal to &amp;quot;{def}^&amp;quot; with the def macro &amp;quot;foo.bar.test&amp;quot; will access the &amp;quot;bar&amp;quot; namespace. inside the &amp;quot;foo&amp;quot; namespace.&lt;br /&gt;
**a namespace equal to &amp;quot;{def}^^&amp;quot; with the def macro &amp;quot;foo.bar.test&amp;quot; will access the &amp;quot;foo&amp;quot; namespace.&lt;br /&gt;
**a namespace equal to &amp;quot;{def}^.rod&amp;quot; with the def macro of &amp;quot;foo.bar&amp;quot; will access the &amp;quot;rod&amp;quot; namespace within the &amp;quot;foo&amp;quot; namespace.&lt;br /&gt;
**a namespace equal to &amp;quot;{def}^^.rod&amp;quot; with the def macro &amp;quot;foo.bar.test&amp;quot; will access the &amp;quot;rod&amp;quot; namespace within the &amp;quot;foo&amp;quot; namespace.&lt;br /&gt;
**a namespace equal to &amp;quot;{def}^.quiz&amp;quot; with the def macro &amp;quot;foo.bar.test&amp;quot; will access the &amp;quot;quiz&amp;quot; namespace within the &amp;quot;rod&amp;quot; namespace within the &amp;quot;foo&amp;quot; namespace.&lt;br /&gt;
**a namespace beginning with &amp;quot;^&amp;quot; is invalid and will generate a WML error, because it is impossible to determine the parent of nothing.&lt;br /&gt;
&lt;br /&gt;
==== *global ====&lt;br /&gt;
These attributes (from_global, to_global, and global) specify the name of the persistent variable to be worked with.&amp;lt;br/&amp;gt;&lt;br /&gt;
The name of the persistent variable must be a valid variable name, as defined in [[VariablesWML]]&lt;br /&gt;
&lt;br /&gt;
==== *local ====&lt;br /&gt;
These attributes (from_local, to_local) specify the name of the standard variable to be worked with.&lt;br /&gt;
&lt;br /&gt;
==== side ====&lt;br /&gt;
This attribute specifies which player client's persistence data should read from or written to in multiplayer.&amp;lt;br/&amp;gt;&lt;br /&gt;
This attribute is not used in single player, and may be omitted in single-player only scenarios.&amp;lt;br/&amp;gt;&lt;br /&gt;
If this attribute is equal to &amp;quot;global&amp;quot;, the currently active player's data will be read in [get_global_variable] operations, and all player's data will be written to in [set_global_variable] and [clear_global_variable] operations.&lt;br /&gt;
&lt;br /&gt;
==== immediate ====&lt;br /&gt;
This attribute is an optional boolean value that specifies whether the changes made by the [set_global_variable] or [clear_global_variable] should be stored permanently at the moment they occur.&amp;lt;br/&amp;gt;&lt;br /&gt;
If it is set to yes, the namespace's permanent storage will be updated with the change that occurred in the marked tag immediately.&amp;lt;br/&amp;gt;&lt;br /&gt;
The default value is no.&amp;lt;br/&amp;gt;&lt;br /&gt;
This attribute does not apply to [get_global_variable], which always occurs immediately.&lt;br /&gt;
&lt;br /&gt;
== About Namespaces ==&lt;br /&gt;
Namespaces exist in order to prevent variable collisions from occuring when two or more unrelated campaigns use the same name for some of their persistent variables.&lt;br /&gt;
A namespace is simply a name that identifies one set of variables. A namespace may contain only alphabetic characters, digits, and underscores.&lt;br /&gt;
&lt;br /&gt;
=== Internal Separation ===&lt;br /&gt;
Just as variables can contain other variables, namespaces may contain other namespaces. The syntax for this works just like container variables: to refer to a namespace &amp;quot;bar&amp;quot; contained within a namespace &amp;quot;foo&amp;quot;, use namespace=&amp;quot;foo.bar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Uniqueness ===&lt;br /&gt;
Because situations may arise where persistent variables from campaigns that are not installed concurrently have to coexist, a namespace should be unique per-context. This means that two unrelated campaigns with the same name should use different namespaces, but two or more related campaigns with different names may use the same namespace.&lt;br /&gt;
&lt;br /&gt;
The following guidelines are provided in order to facilitate this:&lt;br /&gt;
==== Single Standalone Campaign ====&lt;br /&gt;
For a single campaign which is not intended to interact with other campaigns, the format &amp;quot;(author_handle)_(campaign_name)&amp;quot; is suggested for namespaces.&lt;br /&gt;
As an example, if an author going by &amp;quot;upthorn&amp;quot; in the community were to create a campaign named &amp;quot;foo&amp;quot;, the suggested namespace would be &amp;quot;upthorn_foo&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In cases where the author wishes to remain anonymous, or there are many contributing authors (more than say, two or three), the alternate format &amp;quot;(campaign_name)_(month)(year)&amp;quot; is suggested.&lt;br /&gt;
Using the above example, assuming that upthorn began work on the campaign on the day this wiki page was created, the resulting namespace would be &amp;quot;foo_may2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== Multiple Related Campaigns ====&lt;br /&gt;
For multiple related campaigns, there are a few different suggested namespace options depending on order of development and the intended level of interaction.&lt;br /&gt;
&lt;br /&gt;
===== Developed or Conceived Concurrently =====&lt;br /&gt;
If a campaign is intended from the beginning to be part of a larger world of related campaigns, it is recommended that a namespace be created for the overall world, using the format &amp;quot;(author_handle)_(world_name)&amp;quot; for a named author, or &amp;quot;(world_name)_(month)(year)&amp;quot; for an unnamed author.&lt;br /&gt;
As an example, if an author going by &amp;quot;upthorn&amp;quot; were to begin development on a &amp;quot;hypothetical&amp;quot; world the day this page was created, this would result in a namespace of either &amp;quot;upthorn_hypothetical&amp;quot; or &amp;quot;hypothetical_may2010&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If a campaign in this world is intended to have a high level of interaction, it is recommended that the campaign simply uses the world's namespace as default, and stores any information that it needs to be kept separate in a child namespace of the format &amp;quot;(campaign_name)&amp;quot;.&lt;br /&gt;
Building on the above example, if upthorn made a &amp;quot;foo&amp;quot; campaign in the &amp;quot;hypothetical&amp;quot; world, with high level of intended interactivity with the world, it would use &amp;quot;upthorn_hypothetical&amp;quot; as its default namespace, perhaps occasionally storing information in &amp;quot;upthorn_hypothetical.foo&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If a campaign in this world is intended to have a medium level of interaction, it is recommended that the campaign creates a child namespace of the format &amp;quot;(campaign_name)&amp;quot; in the world's overall namespace, and uses it as default, accessing the parent namespace when it needs to get information from the overall world.&lt;br /&gt;
Continuing with the above examples, if upthorn made a &amp;quot;bar&amp;quot; campaign in the &amp;quot;hypothetical&amp;quot; world, with mid level of intended interactivity with the world, it would use &amp;quot;upthorn_hypothetical.bar&amp;quot; as its default namespace, and somewhat frequently access information in &amp;quot;upthorn_hypothetical&amp;quot;, by using the namespace &amp;quot;^&amp;quot; or explicitly naming &amp;quot;upthorn_hypothetical&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If a campaign in this world is intended to have a low level of interaction, it is recommended that the campaign uses an entirely separate namespace, of the format &amp;quot;(world_namespace)_(campaign)&amp;quot; as its default, and accesses the overall world's namespace when it needs to communicate with the world.&lt;br /&gt;
Continuing with the above examples, if upthorn made a &amp;quot;fnord&amp;quot; campaign in the &amp;quot;hypothetical&amp;quot; world, with a low level of intended interactivity with the world, it would use &amp;quot;upthorn_hypothetical_fnord&amp;quot; as its default namespace, and occasionally access information in &amp;quot;upthorn_hypothetical&amp;quot;, by explicitly naming &amp;quot;upthorn_hypothetical&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===== Developed Sequentially =====&lt;br /&gt;
In cases where the first campaign is intended as a standalone, but some time after its release the same author, or other authors decide to make other campaigns in the same overall continuity, the first campaign's namespace cannot be changed.&lt;br /&gt;
&lt;br /&gt;
If campaigns are intended to have a high level of interaction, it is recommended that the later campaign uses the namespace of the prior campaign, and makes a child namespace for itself 'if' it needs to save any of its variables separately.&lt;br /&gt;
As an example, if an author going by &amp;quot;upthorn&amp;quot; developed a campaign &amp;quot;foo&amp;quot; and later developed a related campaign &amp;quot;bar&amp;quot;, the &amp;quot;bar&amp;quot; campaign would use &amp;quot;upthorn_foo&amp;quot; as its default namespace, and perhaps occasionally store information in &amp;quot;upthorn_foo.bar&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If campaigns are intended to have a medium level of interaction, it is recommended that the later campaign makes its default namespace a child inside the namespace of the prior campaign that it is most heavily realted to, and accesses the parent namespace when it needs to work with variables from the prior campaign(s).&lt;br /&gt;
Working from the above example, upthorn's &amp;quot;bar&amp;quot; campaign would use &amp;quot;upthorn_foo.bar&amp;quot; as its default namespace, and somewhat frequently access the &amp;quot;foo&amp;quot; campaign's information in &amp;quot;upthorn_foo&amp;quot;, either by setting the namespace attribute to &amp;quot;upthorn_foo&amp;quot; explicitly, or by using &amp;quot;^&amp;quot; to get &amp;quot;upthorn_foo.bar&amp;quot;'s parent.&lt;br /&gt;
&lt;br /&gt;
If campaigns are intended to have a low level of interaction, it is recommended that the later campaign(s) has its own separate namespace using the &amp;quot;Single Standalone Campaign&amp;quot; guideline format, and explicitly name the prior campaign(s)'s namespace(s) for the few times it needs to access them.&lt;br /&gt;
Working from the above examples, upthorn's &amp;quot;bar&amp;quot; campaign would use &amp;quot;upthorn_bar&amp;quot; as its default namespace, and occasionally access the &amp;quot;foo&amp;quot; campaign's information in &amp;quot;upthorn_foo&amp;quot;, by explicitly naming &amp;quot;upthorn_foo&amp;quot; as the namespace.&lt;/div&gt;</summary>
		<author><name>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=43639</id>
		<title>LuaWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML&amp;diff=43639"/>
		<updated>2011-09-07T19:33:14Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* Units */  added wesnoth.races and wesnoth.get_traits links&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]]. In {{DevFeature1.9}} the functions clock, date, time and difftime from the [http://www.lua.org/manual/5.1/manual.html#5.8 os] library are also available. Keep in mind that they aren't multiplayer- and replay-save.&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#wesnoth.game_events|wesnoth.game_events]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#helper.parsed|helper.parsed]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_literal|helper.shallow_literal]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Events#helper.shallow_parsed|helper.shallow_parsed]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.textdomain|wesnoth.textdomain]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.delay|wesnoth.delay]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.float_label|wesnoth.float_label]]&lt;br /&gt;
* [[LuaWML:Display#wesnoth.hilight_hex|wesnoth.hilight_hex]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.select_hex|wesnoth.select_hex]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.scroll_to_tile|wesnoth.scroll_to_tile]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.play_sound|wesnoth.play_sound]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_music|wesnoth.set_music]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.show_dialog|wesnoth.show_dialog]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_value|wesnoth.set_dialog_value]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_dialog_value|wesnoth.get_dialog_value]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_callback|wesnoth.set_dialog_callback]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.set_dialog_canvas|wesnoth.set_dialog_canvas]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.get_displayed_unit|wesnoth.get_displayed_unit]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#wesnoth.theme_items|wesnoth.theme_items]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Display#helper.get_user_choice|helper.get_user_choice]]&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.match_location|wesnoth.match_location]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.add_tile_overlay|wesnoth.add_tile_overlay]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#wesnoth.remove_tile_overlay|wesnoth.remove_tile_overlay]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#items.place_image|items.place_image]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#items.place_halo|items.place_halo]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Tiles#items.remove|items.remove]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.match_unit|wesnoth.match_unit]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_unit|wesnoth.put_unit]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_recall_units|wesnoth.get_recall_units]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.put_recall_unit|wesnoth.put_recall_unit]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.add_modification|wesnoth.add_modification]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.races|wesnoth.races]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.get_traits|wesnoth.get_traits]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Units#wesnoth.simulate_combat|wesnoth.simulate_combat]]&lt;br /&gt;
* [[LuaWML:Units#wesnoth.transform_unit|wesnoth.transform_unit]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Sides#wesnoth.get_sides|wesnoth.get_sides]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_pairs|location_set.of_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set.of_wml_var|location_set.of_wml_var]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:empty|location_set:empty]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:size|location_set:size]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:clear|location_set:clear]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:get|location_set:get]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:insert|location_set:insert]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:remove|location_set:remove]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_pairs|location_set:of_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:of_wml_var|location_set:of_wml_var]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_pairs|location_set:to_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_stable_pairs|location_set:to_stable_pairs]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:to_wml_var|location_set:to_wml_var]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union|location_set:union]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter|location_set:inter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:iter|location_set:iter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:stable_iter|location_set:stable_iter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:filter|location_set:filter]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:union_merge|location_set:union_merge]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Location_set#location_set:inter_merge|location_set:inter_merge]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.get_image_size|wesnoth.get_image_size]] {{DevFeature1.9}}&lt;br /&gt;
* [[LuaWML:Misc#wesnoth.compare_versions|wesnoth.compare_versions]] {{DevFeature1.9}}&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]] {{DevFeature1.9}}&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''' {{DevFeature1.9}}. 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>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Misc&amp;diff=43636</id>
		<title>LuaWML/Misc</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Misc&amp;diff=43636"/>
		<updated>2011-09-07T18:37:57Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* wesnoth.game_config */ changed poison_amount example to reflect reality&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;
* '''debug''': boolean (read only)&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;
{{DevFeature1.9}}&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(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(some_dialog_cfg, nil, function() choice = wesnoth.get_dialog_value &amp;quot;some_list&amp;quot; end)&lt;br /&gt;
     return { value = choice }&lt;br /&gt;
 end, 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;
{{DevFeature1.9}}&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;
{{DevFeature1.9}}&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;
==== 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;
{{DevFeature1.9}}&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;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=GameConfigWML&amp;diff=43635</id>
		<title>GameConfigWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=GameConfigWML&amp;diff=43635"/>
		<updated>2011-09-07T17:57:34Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* The [game_config] tag */  added poison_amount&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== The [game_config] tag ==&lt;br /&gt;
&lt;br /&gt;
This tag is a top level WML tag which can only be used once because&lt;br /&gt;
it defines basic settings that are used everywhere in the game.&lt;br /&gt;
In official versions of Wesnoth it is in ''game_config.cfg''; values used there are labeled 'standard'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following keys are recognised&lt;br /&gt;
* '''base_income''': (standard 2) how much your leader earns without any villages&lt;br /&gt;
* '''village_income''': (standard 1) how much your leader earns for each village you control&lt;br /&gt;
* '''poison_amount''': (standard 8) the amount of damage poison deals to a unit&lt;br /&gt;
* '''rest_heal_amount''': (standard 2) how much HP a unit gains each turn it rests&lt;br /&gt;
* '''recall_cost''': (standard 20) how much it costs to recall a unit; this cost is independent of level.&lt;br /&gt;
* '''kill_experience''': (standard 8) killing a unit with ''level=X'' will give ''X''*''kill_experience'' experience to the killing unit. However, if a unit has ''level=0'', it will still give half of ''X'' experience.&lt;br /&gt;
&lt;br /&gt;
* '''icon''': (standard 'wesnoth-icon.png') the game icon file&lt;br /&gt;
* '''title''': (standard 'misc/title.png') the title screen image&lt;br /&gt;
* '''logo''': (standard 'misc/logo.png') the wesnoth logo which will be put over the title image&lt;br /&gt;
* '''default_defeat_music''': (standard 'defeat.ogg,defeat2.ogg') default list of music tracks that are chosen to play on player's defeat; this can be overriden per-scenario&lt;br /&gt;
* '''default_victory_music''': (standard 'victory.ogg,victory2.ogg') default list of music tracks that are chosen to play on player's victory; this can be overriden per-scenario&lt;br /&gt;
* '''title_music''': (standard 'main_menu.ogg') the music to play at the title screen&lt;br /&gt;
* '''logo_x''':      (standard 292) the x position of the logo on the title screen&lt;br /&gt;
* '''logo_y''':      (standard  120) the y position of the logo on the title screen&lt;br /&gt;
* '''buttons_x''':   (standard 760) the x position of the buttons on the title screen&lt;br /&gt;
* '''buttons_y''':   (standard 330) the y position of the buttons on the title screen&lt;br /&gt;
* '''buttons_padding''': (standard  20) space between buttons, and border in main menu&lt;br /&gt;
* '''tip_x''':       (standard 100) space between the button panel left edge and the tip-of-the-day panel right edge&lt;br /&gt;
* '''tip_y''':       (standard 500) not used (the bottom right corner of the tip-of-the-day panel is pegged to align with the bottom of the button panel)&lt;br /&gt;
* '''tip_width''':   (standard 495) max width in pixels of the tip-of-the-day panel.  The width will actually adjust to be the smallest size necessary to fit the text.  Once the max width is reached, if text must flow onto multiple lines, then the height will also automatically adjust.&lt;br /&gt;
* '''tip_padding''': (standard  20) space between the edge of the tip-of-the-day panel and an imaginary bounding box containing the text inside the panel&lt;br /&gt;
&lt;br /&gt;
* '''map_image''':   (standard 'maps/wesnoth.png') the background image for the &amp;quot;About&amp;quot; screen&lt;br /&gt;
* '''sidebar_image''': (standard 'misc/rightside.png') border of window when displaying unit statistics&lt;br /&gt;
* '''sidebar_image_bottom''': (standard 'misc/rightside-bottom.png') border of image when displaying unit statistics&lt;br /&gt;
* '''energy_image''': (standard 'misc/bar-energy.png') the images used to display hp/xp bars.&lt;br /&gt;
* '''moved_ball_image''': (standard 'misc/ball-moved.png') the orb image to add on top of the hp bar for player's moved units; see 'Orbs', [[WesnothManual]]&lt;br /&gt;
* '''unmoved_ball_image''': (standard 'misc/ball-unmoved.png') like '''moved_ball_image''', but for player's unmoved units&lt;br /&gt;
* ''partmoved_ball_image''': (standard 'misc/ball-partmoved.png') like '''moved_energy_image''', but for player's partially moved units&lt;br /&gt;
* '''flag_image''': (standard 'image/flag'terrain/flag-1.png:150,terrain/flag-2.png:150,terrain/flag-3.png:150,terrain/flag-4.png:150') the default flag animation to mark captured villages (if no custom flag is defined in the [side] tag). By example, this animation has 4 frames of 150ms each. An automatic side-coloring is applied. &lt;br /&gt;
* '''flag_icon_image''': (standard 'flags/flag-icon.png') the default flag icon to indicate the side playing in the statusbar (if no custom flag_icon is defined in the [side] tag). An automatic side-coloring is applied. &lt;br /&gt;
&lt;br /&gt;
* '''cross_image''': (standard 'misc/cross.png') the cross image displayed on the map at start of scenarios; see [[IntroWML]]&lt;br /&gt;
* '''dot_image''': (standard 'misc/dot.png') the dot image used to draw a path on the map before scenarios&lt;br /&gt;
&lt;br /&gt;
* '''footprint_left_nw''', '''footprint_left_n''', '''footprint_right_nw''', '''footprint_right_n''': images used to display the path that a unit would take to the tile the cursor is on.&lt;br /&gt;
The first image of each key is used for tiles which would take only 1 movement point for the selected unit to move onto;&lt;br /&gt;
the second for ones which would take more.&lt;br /&gt;
The 'n' and 'nw' designations distinguish between tiles which are moved from orthogonally and diagonally in the same way as described in '''[missile_frame]''', [[AnimationWML]].&lt;br /&gt;
The 'left' and 'right' designations are used alternately throughout the path;&lt;br /&gt;
however, the standard values are the same for 'left' and 'right'.&lt;br /&gt;
&lt;br /&gt;
* '''terrain_mask_image''': (standard 'terrain/alphamask.png') used to give a hex-shape from a rectangular image.&lt;br /&gt;
* '''grid_image''': (standard 'terrain/grid.png') the image used by the grid option &lt;br /&gt;
* '''unreachable_image''': (standard 'terrain/darken.png') the stripes mask used to show unreachable locations&lt;br /&gt;
&lt;br /&gt;
* '''missile_n_image''': (standard 'projectiles/missile-n.png') orthogonal missile image to use if none is specified; see ''image'', '''[missile_frame]''', [[AnimationWML]]&lt;br /&gt;
* '''missile_ne_image''': (standard 'projectiles/missile-ne.png') diagonal missile image to use if none is specified; see ''image_diagonal'', '''[missile_frame]''', [[AnimationWML]]&lt;br /&gt;
* '''observer_image''': (standard 'misc/eye.png') the image to use for observer in multi-player games. (The eye in the upper right hand corner.)&lt;br /&gt;
* '''download_campaign_image''': (standard no image) the icon for the &amp;quot;Download more Campaigns&amp;quot; campaign menu option.&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>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=GameConfigWML&amp;diff=43634</id>
		<title>GameConfigWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=GameConfigWML&amp;diff=43634"/>
		<updated>2011-09-07T17:47:58Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* The [game_config] tag */  corrected game.cfg to game_config.cfg&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== The [game_config] tag ==&lt;br /&gt;
&lt;br /&gt;
This tag is a top level WML tag which can only be used once because&lt;br /&gt;
it defines basic settings that are used everywhere in the game.&lt;br /&gt;
In official versions of Wesnoth it is in ''game_config.cfg''; values used there are labeled 'standard'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following keys are recognised&lt;br /&gt;
* '''base_income''': (standard 2) how much your leader earns without any villages&lt;br /&gt;
* '''village_income''': (standard 1) how much your leader earns for each village you control&lt;br /&gt;
* '''rest_heal_amount''': (standard 2) how much HP a unit gains each turn it rests&lt;br /&gt;
* '''recall_cost''': (standard 20) how much it costs to recall a unit; this cost is independent of level.&lt;br /&gt;
* '''kill_experience''': (standard 8) killing a unit with ''level=X'' will give ''X''*''kill_experience'' experience to the killing unit. However, if a unit has ''level=0'', it will still give half of ''X'' experience.&lt;br /&gt;
&lt;br /&gt;
* '''icon''': (standard 'wesnoth-icon.png') the game icon file&lt;br /&gt;
* '''title''': (standard 'misc/title.png') the title screen image&lt;br /&gt;
* '''logo''': (standard 'misc/logo.png') the wesnoth logo which will be put over the title image&lt;br /&gt;
* '''default_defeat_music''': (standard 'defeat.ogg,defeat2.ogg') default list of music tracks that are chosen to play on player's defeat; this can be overriden per-scenario&lt;br /&gt;
* '''default_victory_music''': (standard 'victory.ogg,victory2.ogg') default list of music tracks that are chosen to play on player's victory; this can be overriden per-scenario&lt;br /&gt;
* '''title_music''': (standard 'main_menu.ogg') the music to play at the title screen&lt;br /&gt;
* '''logo_x''':      (standard 292) the x position of the logo on the title screen&lt;br /&gt;
* '''logo_y''':      (standard  120) the y position of the logo on the title screen&lt;br /&gt;
* '''buttons_x''':   (standard 760) the x position of the buttons on the title screen&lt;br /&gt;
* '''buttons_y''':   (standard 330) the y position of the buttons on the title screen&lt;br /&gt;
* '''buttons_padding''': (standard  20) space between buttons, and border in main menu&lt;br /&gt;
* '''tip_x''':       (standard 100) space between the button panel left edge and the tip-of-the-day panel right edge&lt;br /&gt;
* '''tip_y''':       (standard 500) not used (the bottom right corner of the tip-of-the-day panel is pegged to align with the bottom of the button panel)&lt;br /&gt;
* '''tip_width''':   (standard 495) max width in pixels of the tip-of-the-day panel.  The width will actually adjust to be the smallest size necessary to fit the text.  Once the max width is reached, if text must flow onto multiple lines, then the height will also automatically adjust.&lt;br /&gt;
* '''tip_padding''': (standard  20) space between the edge of the tip-of-the-day panel and an imaginary bounding box containing the text inside the panel&lt;br /&gt;
&lt;br /&gt;
* '''map_image''':   (standard 'maps/wesnoth.png') the background image for the &amp;quot;About&amp;quot; screen&lt;br /&gt;
* '''sidebar_image''': (standard 'misc/rightside.png') border of window when displaying unit statistics&lt;br /&gt;
* '''sidebar_image_bottom''': (standard 'misc/rightside-bottom.png') border of image when displaying unit statistics&lt;br /&gt;
* '''energy_image''': (standard 'misc/bar-energy.png') the images used to display hp/xp bars.&lt;br /&gt;
* '''moved_ball_image''': (standard 'misc/ball-moved.png') the orb image to add on top of the hp bar for player's moved units; see 'Orbs', [[WesnothManual]]&lt;br /&gt;
* '''unmoved_ball_image''': (standard 'misc/ball-unmoved.png') like '''moved_ball_image''', but for player's unmoved units&lt;br /&gt;
* ''partmoved_ball_image''': (standard 'misc/ball-partmoved.png') like '''moved_energy_image''', but for player's partially moved units&lt;br /&gt;
* '''flag_image''': (standard 'image/flag'terrain/flag-1.png:150,terrain/flag-2.png:150,terrain/flag-3.png:150,terrain/flag-4.png:150') the default flag animation to mark captured villages (if no custom flag is defined in the [side] tag). By example, this animation has 4 frames of 150ms each. An automatic side-coloring is applied. &lt;br /&gt;
* '''flag_icon_image''': (standard 'flags/flag-icon.png') the default flag icon to indicate the side playing in the statusbar (if no custom flag_icon is defined in the [side] tag). An automatic side-coloring is applied. &lt;br /&gt;
&lt;br /&gt;
* '''cross_image''': (standard 'misc/cross.png') the cross image displayed on the map at start of scenarios; see [[IntroWML]]&lt;br /&gt;
* '''dot_image''': (standard 'misc/dot.png') the dot image used to draw a path on the map before scenarios&lt;br /&gt;
&lt;br /&gt;
* '''footprint_left_nw''', '''footprint_left_n''', '''footprint_right_nw''', '''footprint_right_n''': images used to display the path that a unit would take to the tile the cursor is on.&lt;br /&gt;
The first image of each key is used for tiles which would take only 1 movement point for the selected unit to move onto;&lt;br /&gt;
the second for ones which would take more.&lt;br /&gt;
The 'n' and 'nw' designations distinguish between tiles which are moved from orthogonally and diagonally in the same way as described in '''[missile_frame]''', [[AnimationWML]].&lt;br /&gt;
The 'left' and 'right' designations are used alternately throughout the path;&lt;br /&gt;
however, the standard values are the same for 'left' and 'right'.&lt;br /&gt;
&lt;br /&gt;
* '''terrain_mask_image''': (standard 'terrain/alphamask.png') used to give a hex-shape from a rectangular image.&lt;br /&gt;
* '''grid_image''': (standard 'terrain/grid.png') the image used by the grid option &lt;br /&gt;
* '''unreachable_image''': (standard 'terrain/darken.png') the stripes mask used to show unreachable locations&lt;br /&gt;
&lt;br /&gt;
* '''missile_n_image''': (standard 'projectiles/missile-n.png') orthogonal missile image to use if none is specified; see ''image'', '''[missile_frame]''', [[AnimationWML]]&lt;br /&gt;
* '''missile_ne_image''': (standard 'projectiles/missile-ne.png') diagonal missile image to use if none is specified; see ''image_diagonal'', '''[missile_frame]''', [[AnimationWML]]&lt;br /&gt;
* '''observer_image''': (standard 'misc/eye.png') the image to use for observer in multi-player games. (The eye in the upper right hand corner.)&lt;br /&gt;
* '''download_campaign_image''': (standard no image) the icon for the &amp;quot;Download more Campaigns&amp;quot; campaign menu option.&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>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=GameConfigWML&amp;diff=43633</id>
		<title>GameConfigWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=GameConfigWML&amp;diff=43633"/>
		<updated>2011-09-07T17:46:48Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* The [game_config] tag */  added village_income entry&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
== The [game_config] tag ==&lt;br /&gt;
&lt;br /&gt;
This tag is a top level WML tag which can only be used once because&lt;br /&gt;
it defines basic settings that are used everywhere in the game.&lt;br /&gt;
In official versions of Wesnoth it is in ''game.cfg''; values used there are labeled 'standard'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following keys are recognised&lt;br /&gt;
* '''base_income''': (standard 2) how much your leader earns without any villages&lt;br /&gt;
* '''village_income''': (standard 1) how much your leader earns for each village you control&lt;br /&gt;
* '''rest_heal_amount''': (standard 2) how much HP a unit gains each turn it rests&lt;br /&gt;
* '''recall_cost''': (standard 20) how much it costs to recall a unit; this cost is independent of level.&lt;br /&gt;
* '''kill_experience''': (standard 8) killing a unit with ''level=X'' will give ''X''*''kill_experience'' experience to the killing unit. However, if a unit has ''level=0'', it will still give half of ''X'' experience.&lt;br /&gt;
&lt;br /&gt;
* '''icon''': (standard 'wesnoth-icon.png') the game icon file&lt;br /&gt;
* '''title''': (standard 'misc/title.png') the title screen image&lt;br /&gt;
* '''logo''': (standard 'misc/logo.png') the wesnoth logo which will be put over the title image&lt;br /&gt;
* '''default_defeat_music''': (standard 'defeat.ogg,defeat2.ogg') default list of music tracks that are chosen to play on player's defeat; this can be overriden per-scenario&lt;br /&gt;
* '''default_victory_music''': (standard 'victory.ogg,victory2.ogg') default list of music tracks that are chosen to play on player's victory; this can be overriden per-scenario&lt;br /&gt;
* '''title_music''': (standard 'main_menu.ogg') the music to play at the title screen&lt;br /&gt;
* '''logo_x''':      (standard 292) the x position of the logo on the title screen&lt;br /&gt;
* '''logo_y''':      (standard  120) the y position of the logo on the title screen&lt;br /&gt;
* '''buttons_x''':   (standard 760) the x position of the buttons on the title screen&lt;br /&gt;
* '''buttons_y''':   (standard 330) the y position of the buttons on the title screen&lt;br /&gt;
* '''buttons_padding''': (standard  20) space between buttons, and border in main menu&lt;br /&gt;
* '''tip_x''':       (standard 100) space between the button panel left edge and the tip-of-the-day panel right edge&lt;br /&gt;
* '''tip_y''':       (standard 500) not used (the bottom right corner of the tip-of-the-day panel is pegged to align with the bottom of the button panel)&lt;br /&gt;
* '''tip_width''':   (standard 495) max width in pixels of the tip-of-the-day panel.  The width will actually adjust to be the smallest size necessary to fit the text.  Once the max width is reached, if text must flow onto multiple lines, then the height will also automatically adjust.&lt;br /&gt;
* '''tip_padding''': (standard  20) space between the edge of the tip-of-the-day panel and an imaginary bounding box containing the text inside the panel&lt;br /&gt;
&lt;br /&gt;
* '''map_image''':   (standard 'maps/wesnoth.png') the background image for the &amp;quot;About&amp;quot; screen&lt;br /&gt;
* '''sidebar_image''': (standard 'misc/rightside.png') border of window when displaying unit statistics&lt;br /&gt;
* '''sidebar_image_bottom''': (standard 'misc/rightside-bottom.png') border of image when displaying unit statistics&lt;br /&gt;
* '''energy_image''': (standard 'misc/bar-energy.png') the images used to display hp/xp bars.&lt;br /&gt;
* '''moved_ball_image''': (standard 'misc/ball-moved.png') the orb image to add on top of the hp bar for player's moved units; see 'Orbs', [[WesnothManual]]&lt;br /&gt;
* '''unmoved_ball_image''': (standard 'misc/ball-unmoved.png') like '''moved_ball_image''', but for player's unmoved units&lt;br /&gt;
* ''partmoved_ball_image''': (standard 'misc/ball-partmoved.png') like '''moved_energy_image''', but for player's partially moved units&lt;br /&gt;
* '''flag_image''': (standard 'image/flag'terrain/flag-1.png:150,terrain/flag-2.png:150,terrain/flag-3.png:150,terrain/flag-4.png:150') the default flag animation to mark captured villages (if no custom flag is defined in the [side] tag). By example, this animation has 4 frames of 150ms each. An automatic side-coloring is applied. &lt;br /&gt;
* '''flag_icon_image''': (standard 'flags/flag-icon.png') the default flag icon to indicate the side playing in the statusbar (if no custom flag_icon is defined in the [side] tag). An automatic side-coloring is applied. &lt;br /&gt;
&lt;br /&gt;
* '''cross_image''': (standard 'misc/cross.png') the cross image displayed on the map at start of scenarios; see [[IntroWML]]&lt;br /&gt;
* '''dot_image''': (standard 'misc/dot.png') the dot image used to draw a path on the map before scenarios&lt;br /&gt;
&lt;br /&gt;
* '''footprint_left_nw''', '''footprint_left_n''', '''footprint_right_nw''', '''footprint_right_n''': images used to display the path that a unit would take to the tile the cursor is on.&lt;br /&gt;
The first image of each key is used for tiles which would take only 1 movement point for the selected unit to move onto;&lt;br /&gt;
the second for ones which would take more.&lt;br /&gt;
The 'n' and 'nw' designations distinguish between tiles which are moved from orthogonally and diagonally in the same way as described in '''[missile_frame]''', [[AnimationWML]].&lt;br /&gt;
The 'left' and 'right' designations are used alternately throughout the path;&lt;br /&gt;
however, the standard values are the same for 'left' and 'right'.&lt;br /&gt;
&lt;br /&gt;
* '''terrain_mask_image''': (standard 'terrain/alphamask.png') used to give a hex-shape from a rectangular image.&lt;br /&gt;
* '''grid_image''': (standard 'terrain/grid.png') the image used by the grid option &lt;br /&gt;
* '''unreachable_image''': (standard 'terrain/darken.png') the stripes mask used to show unreachable locations&lt;br /&gt;
&lt;br /&gt;
* '''missile_n_image''': (standard 'projectiles/missile-n.png') orthogonal missile image to use if none is specified; see ''image'', '''[missile_frame]''', [[AnimationWML]]&lt;br /&gt;
* '''missile_ne_image''': (standard 'projectiles/missile-ne.png') diagonal missile image to use if none is specified; see ''image_diagonal'', '''[missile_frame]''', [[AnimationWML]]&lt;br /&gt;
* '''observer_image''': (standard 'misc/eye.png') the image to use for observer in multi-player games. (The eye in the upper right hand corner.)&lt;br /&gt;
* '''download_campaign_image''': (standard no image) the icon for the &amp;quot;Download more Campaigns&amp;quot; campaign menu option.&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>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=43343</id>
		<title>DirectActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=43343"/>
		<updated>2011-08-08T18:45:45Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* [modify_turns] */ added clarification&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.  The message ''result_message'' with the heading ''result_heading'' (see [[LanguageWML]]) are displayed.  If ''result=victory'', the player progresses to the next level; if ''result=defeat'', the game returns to the main menu.  These last two are rarely used: ''result=continue'' behaves identically to ''result=victory'' except the player's gold is not reduced to 80%, and it does not bring up a &amp;quot;Victory&amp;quot; message or the gold changing message (since it doesn't change); ''result=continue_no_save'' works similarly, except the player is not asked whether to save the game, and is taken directly to the next scenario without any messages. {{DevFeature}}: All values for result=... except victory and defeat are being discarded in favor of modifying '''[endlevel]''' behaviour with single keys.&lt;br /&gt;
Unless ''result=defeat'', the following keys can also 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. {{DevFeature1.9}}&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. {{DevFeature1.9}}&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;
&lt;br /&gt;
When the result is &amp;quot;victory&amp;quot; the following keys can be used:&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_text''': 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''': {{DevFeature1.9}} boolean yes|no (default no); whether any according prerecall or recall events shall be fired. In pre-1.9.3 these events are all automatically fired and it can't be turned off.&lt;br /&gt;
* '''check_passability''': {{DevFeature1.9}} (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit (a nearby passable hex is chosen). Before 1.9 this key is always &amp;quot;no&amp;quot;.&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;
* '''ignore_passability''': {{DevFeature}} normally, units will not be teleported into terrain that is impassable for them. Setting this attribute to &amp;quot;yes&amp;quot; permits it. {{DevFeature1.9}}Renamed to check_passability (default yes).&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;
* '''x,y''': the position (or range of positions) to change. {{DevFeature1.9}}: [terrain] accepts a [[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;
=== [gold] ===&lt;br /&gt;
Gives one side 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; {{DevFeature1.9}} takes a comma-separated list as of 1.9.5.&lt;br /&gt;
* '''[filter_side]''' {{DevFeature1.9}} with a [[StandardSideFilter]] as argument&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]]]. Note units with a negative amount of hitpoints will be unstored with 1 hitpoint.&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''': {{DevFeature1.9}} (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''': {{DevFeature1.9}}(boolean yes|no, default no) Whether any advance/post advance events shall be fired if an advancement takes place, no effect otherwise. Before 1.9 this is always &amp;quot;yes&amp;quot;.&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;
&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 {{DevFeature1.9}} side= can be a comma-separated list&lt;br /&gt;
&lt;br /&gt;
=== [allow_extra_recruit] ===&lt;br /&gt;
{{DevFeature1.9}}; 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. {{DevFeature1.9}} side= can be a comma-separated list&lt;br /&gt;
&lt;br /&gt;
=== [disallow_extra_recruit] ===&lt;br /&gt;
{{DevFeature1.9}}; 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. {{DevFeature1.9}} side= can be a comma-separated list&lt;br /&gt;
&lt;br /&gt;
=== [set_extra_recruit] === &lt;br /&gt;
{{DevFeature1.9}}; 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.&lt;br /&gt;
* '''[filter_side]''' {{DevFeature1.9}} with a [[StandardSideFilter]] as argument&lt;br /&gt;
* '''income''': the income given at the begining of each turn.&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;
* '''[ai]''': replaces a side's AI parameters with the new specified ones. Uses the same syntax described in [[AiWML]].&lt;br /&gt;
* '''switch_ai''': {{DevFeature}} 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;
* '''share_maps''': {{DevFeature}} 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''': {{DevFeature}} change the share_view side attribute. Be sure to use fog=yes for that side and have it as an ally&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 possible to change the current turn number to a greater one than the current only, cannot be changed to lesser one; also, it is not possible to change the turn number to exceed the turn limit.&lt;br /&gt;
&lt;br /&gt;
=== [capture_village] ===&lt;br /&gt;
Changes the ownership of a village.&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.&lt;br /&gt;
* '''x, y''': the location of the village. Can be a comma-separated list and/or location ranges. {{DevFeature1.9}}: [capture_village] accepts a full SLF; all village locations matching the filter are affected.&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 any 'last breath' and 'die' events triggered by this are executed immediately, interrupting the current event and thus causing the x1, y1, x2, and y2 variables to be reset for that 'die' event, which in turn causes those variables to be invalid for the remainder of this event. In the stable version, the variable second_unit in each of these die and last breath events is always the same as the variable unit (the dying unit). 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]''' {{DevFeature1.9}} 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;
{{DevFeature1.9}}; 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 passable location is chosen. All target locations passed (see below) need to be passable hexes for the particular moved units.&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;
* '''[filter_side]''' {{DevFeature1.9}} with a [[StandardSideFilter]] as argument&lt;br /&gt;
Changes the AI for a specified side. See [[Customizing_AI_in_Wesnoth_1.8#.5Bmodify_ai.5D_tag]]&lt;br /&gt;
&lt;br /&gt;
=== [modify_unit] ===&lt;br /&gt;
{{DevFeature1.9}}; 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;
         type=Troll Rocklobber&lt;br /&gt;
     [/filter]&lt;br /&gt;
     hitpoints=10&lt;br /&gt;
     [modifications]&lt;br /&gt;
         [trait]&lt;br /&gt;
             # first trait is unmodified&lt;br /&gt;
         [/trait]&lt;br /&gt;
         {TRAIT_HEALTHY}# second trait is replaced with the healthy trait&lt;br /&gt;
     [/modifications]&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;
{{DevFeature1.9}}; transforms every unit matching the filter to the given unit type. Keeps intact hitpoints, experience and status. If the unit is transformed to a non-living type (undead or mechanical), it will be also unpoisoned.&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;
{{DevFeature1.9}}(This tag never existed until r47553 (from 1.9.3 on), although it was already documented.)&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. {{DevFeature1.9}}: Do not use a [filter] tag. All units matching this filter are unpetrified {{DevFeature1.9}}: recall list units included.&lt;br /&gt;
&lt;br /&gt;
=== [object] ===&lt;br /&gt;
Gives some unit an object and removes all items on the tile the unit is on.&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;
* '''[effect]''': one or more effect elements may be listed.  See [[EffectWML]] for a description of [effect].&lt;br /&gt;
* '''duration''': 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).&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. The first unit found that matches the filter will be given the object.  If no unit matches the filter, then a message is displayed and the object is not removed.&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 '''[removeitem]''' tag, but you could probably put any tags that otherwise work in a [then] tag.&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;
* If you do not supply a filter, the object action will be applied to a unit at the location of the moveto event. Currently this isn't recommended as it is not clear that this will continue working this way. Instead it is better to explicitly include a location filter.&lt;br /&gt;
* The object action does not act on units in the recall list. There is a feature request in to allow this, but it is not clear whether or not it will be accepted.&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. {{DevFeature1.9}} takes a comma-separated list as of 1.9.5.&lt;br /&gt;
* '''[filter_side]''' {{DevFeature1.9}} 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. {{DevFeature1.9}} takes a comma-separated list as of 1.9.5.&lt;br /&gt;
* '''[filter_side]''' {{DevFeature1.9}} 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;
=== [allow_undo] ===&lt;br /&gt;
Allows the player to undo the event that this tag is inside.  Has an effect only inside moveto events.  If the move is undone, only the position of the unit will be restored; any altered variables or changes to the game will remain changed after the move 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 move 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). {{DevFeature1.9}} $heal_amount contains only the number of hitpoints the first unit that was found got healed (no change, actually).&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] the first unit matching the filter will be healed. If no filter is supplied, it is tried to take the unit at $x1, $y1. {{DevFeature1.9}} All matching on-map units are healed.&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) {{DevFeature1.9}}...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''': {{DevFeature1.9}} (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''': {{DevFeature1.9}} (boolean, default no) Whether the units' attacks_left should be reset to their max_attacks (usually 1).&lt;br /&gt;
* '''restore_statuses''': {{DevFeature1.9}} (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;
{{DevFeature1.9}}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;
*  '''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 an 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.&lt;br /&gt;
*  '''animate''': (default no) if yes, scrolls to each unit before harming it and plays its defense and death animations.&lt;br /&gt;
*  '''[secondary_attack]''': sets the weapon against which the unit harmed will defend, to allow playing specific defense animations. Takes a weapon filter as argument, see [[FilterWML]].&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;
&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] and [illuminated_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;
=== [end_turn] ===&lt;br /&gt;
End the current side's turn. {{DevFeature}} 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;
&lt;br /&gt;
=== [replace_schedule] ===&lt;br /&gt;
Replace the time of day schedule of the entire scenario. {{DevFeature1.9}}&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
&lt;br /&gt;
=== [tunnel] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.9}}&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>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=43342</id>
		<title>DirectActionsWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=DirectActionsWML&amp;diff=43342"/>
		<updated>2011-08-08T16:45:24Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* [endlevel] */ addition of replay_save 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.  The message ''result_message'' with the heading ''result_heading'' (see [[LanguageWML]]) are displayed.  If ''result=victory'', the player progresses to the next level; if ''result=defeat'', the game returns to the main menu.  These last two are rarely used: ''result=continue'' behaves identically to ''result=victory'' except the player's gold is not reduced to 80%, and it does not bring up a &amp;quot;Victory&amp;quot; message or the gold changing message (since it doesn't change); ''result=continue_no_save'' works similarly, except the player is not asked whether to save the game, and is taken directly to the next scenario without any messages. {{DevFeature}}: All values for result=... except victory and defeat are being discarded in favor of modifying '''[endlevel]''' behaviour with single keys.&lt;br /&gt;
Unless ''result=defeat'', the following keys can also 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. {{DevFeature1.9}}&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. {{DevFeature1.9}}&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;
&lt;br /&gt;
When the result is &amp;quot;victory&amp;quot; the following keys can be used:&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_text''': 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''': {{DevFeature1.9}} boolean yes|no (default no); whether any according prerecall or recall events shall be fired. In pre-1.9.3 these events are all automatically fired and it can't be turned off.&lt;br /&gt;
* '''check_passability''': {{DevFeature1.9}} (boolean yes|no, default yes): If yes, checks for terrain passability when placing the unit (a nearby passable hex is chosen). Before 1.9 this key is always &amp;quot;no&amp;quot;.&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;
* '''ignore_passability''': {{DevFeature}} normally, units will not be teleported into terrain that is impassable for them. Setting this attribute to &amp;quot;yes&amp;quot; permits it. {{DevFeature1.9}}Renamed to check_passability (default yes).&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;
* '''x,y''': the position (or range of positions) to change. {{DevFeature1.9}}: [terrain] accepts a [[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;
=== [gold] ===&lt;br /&gt;
Gives one side 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; {{DevFeature1.9}} takes a comma-separated list as of 1.9.5.&lt;br /&gt;
* '''[filter_side]''' {{DevFeature1.9}} with a [[StandardSideFilter]] as argument&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]]]. Note units with a negative amount of hitpoints will be unstored with 1 hitpoint.&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''': {{DevFeature1.9}} (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''': {{DevFeature1.9}}(boolean yes|no, default no) Whether any advance/post advance events shall be fired if an advancement takes place, no effect otherwise. Before 1.9 this is always &amp;quot;yes&amp;quot;.&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;
&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 {{DevFeature1.9}} side= can be a comma-separated list&lt;br /&gt;
&lt;br /&gt;
=== [allow_extra_recruit] ===&lt;br /&gt;
{{DevFeature1.9}}; 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. {{DevFeature1.9}} side= can be a comma-separated list&lt;br /&gt;
&lt;br /&gt;
=== [disallow_extra_recruit] ===&lt;br /&gt;
{{DevFeature1.9}}; 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. {{DevFeature1.9}} side= can be a comma-separated list&lt;br /&gt;
&lt;br /&gt;
=== [set_extra_recruit] === &lt;br /&gt;
{{DevFeature1.9}}; 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.&lt;br /&gt;
* '''[filter_side]''' {{DevFeature1.9}} with a [[StandardSideFilter]] as argument&lt;br /&gt;
* '''income''': the income given at the begining of each turn.&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;
* '''[ai]''': replaces a side's AI parameters with the new specified ones. Uses the same syntax described in [[AiWML]].&lt;br /&gt;
* '''switch_ai''': {{DevFeature}} 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;
* '''share_maps''': {{DevFeature}} 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''': {{DevFeature}} change the share_view side attribute. Be sure to use fog=yes for that side and have it as an ally&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 possible to change the current turn number to a greater one than the current only; also, it is not possible to change the turn number to exceed the turn limit.&lt;br /&gt;
&lt;br /&gt;
=== [capture_village] ===&lt;br /&gt;
Changes the ownership of a village.&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.&lt;br /&gt;
* '''x, y''': the location of the village. Can be a comma-separated list and/or location ranges. {{DevFeature1.9}}: [capture_village] accepts a full SLF; all village locations matching the filter are affected.&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 any 'last breath' and 'die' events triggered by this are executed immediately, interrupting the current event and thus causing the x1, y1, x2, and y2 variables to be reset for that 'die' event, which in turn causes those variables to be invalid for the remainder of this event. In the stable version, the variable second_unit in each of these die and last breath events is always the same as the variable unit (the dying unit). 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]''' {{DevFeature1.9}} 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;
{{DevFeature1.9}}; 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 passable location is chosen. All target locations passed (see below) need to be passable hexes for the particular moved units.&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;
* '''[filter_side]''' {{DevFeature1.9}} with a [[StandardSideFilter]] as argument&lt;br /&gt;
Changes the AI for a specified side. See [[Customizing_AI_in_Wesnoth_1.8#.5Bmodify_ai.5D_tag]]&lt;br /&gt;
&lt;br /&gt;
=== [modify_unit] ===&lt;br /&gt;
{{DevFeature1.9}}; 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;
         type=Troll Rocklobber&lt;br /&gt;
     [/filter]&lt;br /&gt;
     hitpoints=10&lt;br /&gt;
     [modifications]&lt;br /&gt;
         [trait]&lt;br /&gt;
             # first trait is unmodified&lt;br /&gt;
         [/trait]&lt;br /&gt;
         {TRAIT_HEALTHY}# second trait is replaced with the healthy trait&lt;br /&gt;
     [/modifications]&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;
{{DevFeature1.9}}; transforms every unit matching the filter to the given unit type. Keeps intact hitpoints, experience and status. If the unit is transformed to a non-living type (undead or mechanical), it will be also unpoisoned.&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;
{{DevFeature1.9}}(This tag never existed until r47553 (from 1.9.3 on), although it was already documented.)&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. {{DevFeature1.9}}: Do not use a [filter] tag. All units matching this filter are unpetrified {{DevFeature1.9}}: recall list units included.&lt;br /&gt;
&lt;br /&gt;
=== [object] ===&lt;br /&gt;
Gives some unit an object and removes all items on the tile the unit is on.&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;
* '''[effect]''': one or more effect elements may be listed.  See [[EffectWML]] for a description of [effect].&lt;br /&gt;
* '''duration''': 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).&lt;br /&gt;
* '''[filter]''' with a [[StandardUnitFilter]] as argument. The first unit found that matches the filter will be given the object.  If no unit matches the filter, then a message is displayed and the object is not removed.&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 '''[removeitem]''' tag, but you could probably put any tags that otherwise work in a [then] tag.&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;
* If you do not supply a filter, the object action will be applied to a unit at the location of the moveto event. Currently this isn't recommended as it is not clear that this will continue working this way. Instead it is better to explicitly include a location filter.&lt;br /&gt;
* The object action does not act on units in the recall list. There is a feature request in to allow this, but it is not clear whether or not it will be accepted.&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. {{DevFeature1.9}} takes a comma-separated list as of 1.9.5.&lt;br /&gt;
* '''[filter_side]''' {{DevFeature1.9}} 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. {{DevFeature1.9}} takes a comma-separated list as of 1.9.5.&lt;br /&gt;
* '''[filter_side]''' {{DevFeature1.9}} 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;
=== [allow_undo] ===&lt;br /&gt;
Allows the player to undo the event that this tag is inside.  Has an effect only inside moveto events.  If the move is undone, only the position of the unit will be restored; any altered variables or changes to the game will remain changed after the move 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 move 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). {{DevFeature1.9}} $heal_amount contains only the number of hitpoints the first unit that was found got healed (no change, actually).&lt;br /&gt;
*  '''[filter]''': [[StandardUnitFilter]] the first unit matching the filter will be healed. If no filter is supplied, it is tried to take the unit at $x1, $y1. {{DevFeature1.9}} All matching on-map units are healed.&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) {{DevFeature1.9}}...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''': {{DevFeature1.9}} (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''': {{DevFeature1.9}} (boolean, default no) Whether the units' attacks_left should be reset to their max_attacks (usually 1).&lt;br /&gt;
* '''restore_statuses''': {{DevFeature1.9}} (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;
{{DevFeature1.9}}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;
*  '''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 an 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.&lt;br /&gt;
*  '''animate''': (default no) if yes, scrolls to each unit before harming it and plays its defense and death animations.&lt;br /&gt;
*  '''[secondary_attack]''': sets the weapon against which the unit harmed will defend, to allow playing specific defense animations. Takes a weapon filter as argument, see [[FilterWML]].&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;
&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] and [illuminated_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;
=== [end_turn] ===&lt;br /&gt;
End the current side's turn. {{DevFeature}} 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;
&lt;br /&gt;
=== [replace_schedule] ===&lt;br /&gt;
Replace the time of day schedule of the entire scenario. {{DevFeature1.9}}&lt;br /&gt;
* [[TimeWML]]: the new schedule.&lt;br /&gt;
&lt;br /&gt;
=== [tunnel] ===&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.9}}&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>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=41408</id>
		<title>MapGeneratorWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=41408"/>
		<updated>2011-03-31T18:49:26Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* [generator] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== [generator] ==&lt;br /&gt;
&lt;br /&gt;
The '''[generator]''' tag replaces a scenario's map data;&lt;br /&gt;
in fact its whole purpose is to generate the map data given a set of configuration parameters.&lt;br /&gt;
The map generator function is not very well documented.  This rewrite is an attempt to remedy that.&lt;br /&gt;
&lt;br /&gt;
There are only two kinds of generators, ‘default’ and ‘cave’. As each behaves differently,  a section for each has been made.&lt;br /&gt;
To use '''[generator]''' your '''[scenario]''' tag must contain one of the following keys:&lt;br /&gt;
* '''scenario_generation''': (This is used in the cave examples below)&lt;br /&gt;
* '''map_generation''': (This is used in the multiplayer Random Map.)&lt;br /&gt;
For which key to use and what value, see the section for the generator you want to use.&lt;br /&gt;
&lt;br /&gt;
===The Default Generator===&lt;br /&gt;
The default generator can be used to generate map data for any scenario. The data in this section is inferred from “data/multiplayer/scenarios/Random_Scenario.cfg”, usage in add-on content, and inspection of mapgen.cpp&lt;br /&gt;
&lt;br /&gt;
'''Excerpt from mapgenerator comments:'''&lt;br /&gt;
&lt;br /&gt;
* Basically we generate alot of hills, each hill being centered at a certain point, with a certain radius - being a half sphere. Hills are combined additively to form a bumpy surface. The size of each hill varies randomly from 1-hill_size. We generate 'iterations' hills in total. The range of heights is normalized to 0-1000. 'island_size' controls whether or not the map should tend toward an island shape, and if so, how large the island should be. Hills with centers that are more than 'island_size' away from the center of the map will be inverted (i.e. be valleys). 'island_size' as 0 indicates no island.&lt;br /&gt;
&lt;br /&gt;
To use the default '''[generator]''' your '''[scenario]''' tag must contain one of the following keys:&lt;br /&gt;
* '''scenario_generation=default'''&lt;br /&gt;
* '''map_generation=default'''&lt;br /&gt;
If ‘scenario_generation’ is used, the engine will expect for your entire '''[scenario]''' sub tags to be inside a '''[scenario]''' tag inside '''[generator]'''. Tags outside of this will be ignored.  There may be value in this, but at this writing, it’s not clear.&lt;br /&gt;
‘map_generation=default’ is simpler and more commonly used.  It is also necessary to use this key so that you can regenerate a map in MP game creation.&lt;br /&gt;
In its use only generator data is in the '''[generator]''' tag, all other '''[scenario]''' data is placed outside of it. The exception is if you are making an initial MP scenario available in MP game creation, for this a '''[scenario]''' tag must appear inside of '''[generator]''', containing the '''[scenario]''' subtags you want to use. See “data/multiplayer/scenarios/Random_Scenario.cfg” for an example.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''' when the default generator is used:&lt;br /&gt;
* '''[scenario]''': See [[ScenarioWML]]&lt;br /&gt;
* '''name'''&lt;br /&gt;
** '''default''''&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''iterations''': the number of times an attempt is being made to generate a hill&lt;br /&gt;
* '''hill_size''': hills will have a random size between 1 and ''hill_size''&lt;br /&gt;
* '''max_lakes''': the number of times an attempt is being made to generate a lake&lt;br /&gt;
* '''min_lake_height''': lakes are the starting point of rivers and need to start above a certain height&lt;br /&gt;
* '''lake_size''': the size of a lake still randomly generated&lt;br /&gt;
* '''river_frequency''': determine how much a river can run uphill and thus generate more rivers&lt;br /&gt;
&lt;br /&gt;
* '''villages''': villages per 1,000 hexes&lt;br /&gt;
* '''players''': Number of starting locations for the map.&lt;br /&gt;
* '''castle_size''': Number of castle tiles (including the keep), per player.&lt;br /&gt;
* '''temperature_iterations''': Same as iterations, but for the temperature map.&lt;br /&gt;
* '''temperature_size''': Same as hill_size, but for the temperature map.&lt;br /&gt;
(Temperature map is generated the same way as a hill map, but is hard coded with a island_size of 0.)&lt;br /&gt;
* '''roads''': number of roads the generator will attempt to make&lt;br /&gt;
* '''road_windiness''': Use 1 for the road to be made using the cheapest path (based on [road_cost] tags), higher values introduce randomness to make the road wind a bit.&lt;br /&gt;
* '''island_size''': Use 1-5 for coastal maps and 6-10 for island maps. Bigger values may crash map generation process. Bigger numbers makes more water (and less land)&lt;br /&gt;
* '''default_flatland''': If not specified, is Grassland. If your height tags don't go down to 0, the default_flatland will be used (possibly in other cases as well).&lt;br /&gt;
* '''[height]''': list of common terrain types&lt;br /&gt;
which come in at different heights, from highest to lowest&lt;br /&gt;
Good WML will have the range of 1000-0 covered.&lt;br /&gt;
** '''height''': the terrain specified below will appear at this height and up.&lt;br /&gt;
** '''terrain''': 1 terrain code&lt;br /&gt;
* '''[convert]''': used to make terrain conversions&lt;br /&gt;
For example water becomes ice at low temperatures, grass snow, etc.&lt;br /&gt;
If the terrain is between the min_x and max_x it will be converted&lt;br /&gt;
if min_x is not defined it will default to a large negative number&lt;br /&gt;
if max_x is not defined it will default to a large positive number&lt;br /&gt;
** '''min_height'''&lt;br /&gt;
** '''max_height'''&lt;br /&gt;
** '''min_temperature'''&lt;br /&gt;
** '''max_temperature'''&lt;br /&gt;
** '''from''': a comma separated terrains to convert from&lt;br /&gt;
** '''to''': The terrain to convert these terrains to&lt;br /&gt;
* '''[road_cost]'''&lt;br /&gt;
** '''terrain''' 1 terrain code&lt;br /&gt;
** '''cost''': how expensive it is the create a road on this terrain, this influences the odds of this terrain getting a road&lt;br /&gt;
** '''convert_to_bridge''': a comma separated list of terrains; N/S, then NE/SW, then NW/SE.&lt;br /&gt;
** '''convert_to''': 1 terrain code (note using both ''convert_to_bridge'' and ''convert_to'' might result in unwanted results)&lt;br /&gt;
* '''[village]''': The conversion of terrains to villages&lt;br /&gt;
** '''terrain''': 1 terrain code which will be converted to a village&lt;br /&gt;
** '''convert_to''': 1 terrain code for the village&lt;br /&gt;
** '''adjacent_liked''': a comma separated terrain list. This list increases the rating for a certain location, every tile around the location will be tested against this list and for every match the rating of the location is increased. The same terrain twice in the list will double the rating increase for that location.&lt;br /&gt;
** '''rating''': chance of appearing&lt;br /&gt;
* '''[castle]''': the conversion of castles&lt;br /&gt;
** '''valid_terrain''': a comma-separated terrain list with terrains which are allowed to be converted to a castle.&lt;br /&gt;
** '''min_distance''': all castles generated must be this number of hexes apart from each other&lt;br /&gt;
* '''[naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[village_naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
&lt;br /&gt;
===The Cave Generator===&lt;br /&gt;
The cave generator does not appear to have been written for multiplayer scenario game creation like the default generator was.  It is used in '''campaigns\Sceptre_of_Fire\scenarios\4_Gathering_Materials.cfg''' &amp;amp; '''campaigns\Heir_To_The_Throne\scenarios\ 17_Scepter_of_Fire.cfg '''. The data here is inferred from those scenarios and an inspection of cavegen.cpp&lt;br /&gt;
&lt;br /&gt;
To use the cave '''[generator]''' your '''[scenario]'''  tag must contain one of the following keys:&lt;br /&gt;
* '''scenario_generation=cave'''&lt;br /&gt;
* '''map_generation=cave'''&lt;br /&gt;
Here it is recommend you use ‘scenario_generation’ as there are examples to follow, though it may be possible to use’ map_generation’.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''' when the cave generator is used:&lt;br /&gt;
* '''[settings]''':  behaves as if '''[scenario]''', See [[ScenarioWML]]&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''village_density''': influences number of villages&lt;br /&gt;
* '''flipx_chance''': Chance to flip x coordinates, that meens the map is mirrored at the vertical axis in its midth.&lt;br /&gt;
* '''flipy_chance''': Chance to flip y coordinates, that meens the map is mirrored at the horizontal axis in its midth.&lt;br /&gt;
* '''[chamber]''': for underground maps&lt;br /&gt;
** '''id''': a name used to identify where the passages lead.  See the [passage] tag, below.&lt;br /&gt;
** '''x''','''y''': approximate location of the center hex of the chamber.  Unfortunately it isn't always exact.  Can be a single number (x=5) or a range (x=10-20)&lt;br /&gt;
** '''size''': circular radius of the chamber, including the center hex&lt;br /&gt;
** '''jagged''': a good value is probably between 0-50 (not sure exactly)&lt;br /&gt;
** '''[items]''': See [[ScenarioWML]].  This can contain tags normally found under [scenario] like [side], [item], and [event].  Moveto events definitely work here (using the same_location_as_previous key instead of a location filter).  Other events can be placed in the [settings] tag, above.  Locations of items will be generated randomly.  The attribute '''same_location_as_previous=yes''' means that the filter for a moveto event (see [[EventWML]]) is the same as the location of the previous item.&lt;br /&gt;
** '''[passage]''': defines a pathway between chambers&lt;br /&gt;
*** '''destination''': the id key of the destination chamber&lt;br /&gt;
*** '''windiness''': a good value is probably between 1-10&lt;br /&gt;
*** '''laziness''':&lt;br /&gt;
*** '''width''': number of hexes&lt;br /&gt;
*** '''jagged''': a good value is probably between 1-10&lt;br /&gt;
*** '''chance''': chance for the passage to be generated, between 0 and 100, 100 if key not present&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=41351</id>
		<title>MapGeneratorWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=41351"/>
		<updated>2011-03-31T04:33:20Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* [generator] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== [generator] ==&lt;br /&gt;
&lt;br /&gt;
The [generator] tag replaces a scenario's map data;&lt;br /&gt;
in fact its whole purpose is to generate the map data given a set of configuration parameters.&lt;br /&gt;
&lt;br /&gt;
The map generator function is not very well documented. The data on this page are inferred from '''scenarios/multiplayer/Random_Map.cfg''' and '''scenarios/Heir_To_The_Throne/Sceptre.cfg'''.&lt;br /&gt;
An example for a random underground map that is less complex can be found in '''campaigns\Sceptre_of_Fire\scenarios\4_Gathering_Materials.cfg'''.&lt;br /&gt;
&lt;br /&gt;
'''Excerpt from mapgenerator comments:'''&lt;br /&gt;
&lt;br /&gt;
* Basically we generate alot of hills, each hill being centered at a certain point, with a certain radius - being a half sphere. Hills are combined additively to form a bumpy surface. The size of each hill varies randomly from 1-hill_size. We generate 'iterations' hills in total. The range of heights is normalized to 0-1000. 'island_size' controls whether or not the map should tend toward an island shape, and if so, how large the island should be. Hills with centers that are more than 'island_size' away from the center of the map will be inverted (i.e. be valleys). 'island_size' as 0 indicates no island.&lt;br /&gt;
&lt;br /&gt;
Updated with some more info and the changes with the new terrain system&lt;br /&gt;
&lt;br /&gt;
The following keys are recognized for '''[scenario]'''/'''[multiplayer]''' (Use one of them.)&lt;br /&gt;
* '''scenario_generation''': (This is used is the cave examples mentioned above.)&lt;br /&gt;
* '''map_generation''': (This is used in the multiplayer Random Map.)&lt;br /&gt;
&amp;quot;empty&amp;quot; or &amp;quot;default&amp;quot; will use the default generator, &amp;quot;cave&amp;quot; used the cave generator. Other values are not valid.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''':&lt;br /&gt;
* '''[scenario]'''/'''[settings]''': See [[ScenarioWML]]&lt;br /&gt;
* '''name'''&lt;br /&gt;
** '''default''''&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''iterations''': the number of times an attempt is being made to generate a hill (default only)&lt;br /&gt;
* '''hill_size''': hills will have a random size between 1 and ''hill_size'' (default only)&lt;br /&gt;
* '''max_lakes''': the number of times an attempt is being made to generate a lake (default only)&lt;br /&gt;
* '''min_lake_height''': lakes are the starting point of rivers and need to start above a certain height (default only)&lt;br /&gt;
* '''lake_size''': the size of a lake still randomly generated (default only)&lt;br /&gt;
* '''river_frequency''': determine how much a river can run uphill and thus generate more rivers (default only)&lt;br /&gt;
* '''flipx_chance''': Chance to flip x coordinates, that meens the map is mirrored at the vertical axis in its midth. (cave only)&lt;br /&gt;
* '''flipy_chance''': Chance to flip y coordinates, that meens the map is mirrored at the horizontal axis in its midth. (cave only)&lt;br /&gt;
&lt;br /&gt;
* '''villages''': villages per 1,000 hexes (default only)&lt;br /&gt;
* '''village_density''': influences number of villages (cave only)&lt;br /&gt;
* '''players'''&lt;br /&gt;
* '''castle_size''': Number of castle tiles (including the keep), per player.&lt;br /&gt;
* '''temperature_iterations''': Same as iterations, but for the temperature map.&lt;br /&gt;
* '''temperature_size''': Same as hill_size, but for the temperature map.&lt;br /&gt;
(Temperature map is generated the same way as a hill map, but is hard coded with a island_size of 0.)&lt;br /&gt;
* '''roads'''&lt;br /&gt;
* '''road_windiness'''&lt;br /&gt;
* '''island_size''': Use 1-5 for coastal maps and 6-10 for island maps. Bigger values may crash map generation process. Bigger numbers makes more water (and less land)&lt;br /&gt;
* '''default_flatland''': If not specified, is Grassland. If your height tags don't go down to 0, the default_flatland will be used (possibly in other cases as well).&lt;br /&gt;
* '''[height]''': list of common terrain types&lt;br /&gt;
which come in at different heights, from highest to lowest (default only)&lt;br /&gt;
Good WML will have the range of 1000-0 covered.&lt;br /&gt;
** '''height''': the terrain specified below will appear at this height and up.&lt;br /&gt;
** '''terrain''': 1 terrain code&lt;br /&gt;
* '''[convert]''': used to make terrain conversions (default only).&lt;br /&gt;
For example water becomes ice at low temperatures, grass snow, etc.&lt;br /&gt;
If the terrain is between the min_x and max_x it will be converted&lt;br /&gt;
if min_x is not defined it will default to a large negative number&lt;br /&gt;
if max_x is not defined it will default to a large positive number&lt;br /&gt;
** '''min_height'''&lt;br /&gt;
** '''max_height'''&lt;br /&gt;
** '''min_temperature'''&lt;br /&gt;
** '''max_temperature'''&lt;br /&gt;
** '''from''': a comma separated terrains to convert from&lt;br /&gt;
** '''to''': The terrain to convert these terrains to&lt;br /&gt;
* '''[road_cost]'''&lt;br /&gt;
** '''terrain''' 1 terrain code&lt;br /&gt;
** '''cost''': how expensive it is the create a road on this terrain, this influences the odds of this terrain getting a road&lt;br /&gt;
** '''convert_to_bridge''': a comma separated list of terrains; N/S, then NE/SW, then NW/SE.&lt;br /&gt;
** '''convert_to''': 1 terrain code (note using both ''convert_to_bridge'' and ''convert_to'' might result in unwanted results)&lt;br /&gt;
* '''[village]''': The conversion of terrains to villages (default only)&lt;br /&gt;
** '''terrain''': 1 terrain code which will be converted to a village&lt;br /&gt;
** '''convert_to''': 1 terrain code for the village&lt;br /&gt;
** '''adjacent_liked''': a comma separated terrain list. This list increases the rating for a certain location, every tile around the location will be tested against this list and for every match the rating of the location is increased. The same terrain twice in the list will double the rating increase for that location.&lt;br /&gt;
** '''rating''': chance of appearing&lt;br /&gt;
* '''[castle]''': the conversion of castles (default only)&lt;br /&gt;
** '''valid_terrain''': a comma-separated terrain list with terrains which are allowed to be converted to a castle.&lt;br /&gt;
** '''min_distance'''&lt;br /&gt;
* '''[naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[village_naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[chamber]''': for underground maps&lt;br /&gt;
** '''id''': a name used to identify where the passages lead.  See the [passage] tag, below.&lt;br /&gt;
** '''x''','''y''': approximate location of the center hex of the chamber.  Unfortunately it isn't always exact.  Can be a single number (x=5) or a range (x=10-20)&lt;br /&gt;
** '''size''': circular radius of the chamber, including the center hex&lt;br /&gt;
** '''jagged''': a good value is probably between 0-50 (not sure exactly)&lt;br /&gt;
** '''[items]''': See [[ScenarioWML]].  This can contain tags normally found under [scenario] like [side], [item], and [event].  Moveto events definitely work here (using the same_location_as_previous key instead of a location filter).  Other events can be placed in the [settings] tag, above.  Locations of items will be generated randomly.  The attribute '''same_location_as_previous=yes''' means that the filter for a moveto event (see [[EventWML]]) is the same as the location of the previous item.&lt;br /&gt;
** '''[passage]''': defines a pathway between chambers&lt;br /&gt;
*** '''destination''': the id key of the destination chamber&lt;br /&gt;
*** '''windiness''': a good value is probably between 1-10&lt;br /&gt;
*** '''width''': number of hexes&lt;br /&gt;
*** '''jagged''': a good value is probably between 1-10&lt;br /&gt;
*** '''chance''': chance for the passage to be generated, between 0 and 100, 100 if key not present&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=41350</id>
		<title>MapGeneratorWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=41350"/>
		<updated>2011-03-31T04:19:53Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* [generator] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== [generator] ==&lt;br /&gt;
&lt;br /&gt;
The [generator] tag replaces a scenario's map data;&lt;br /&gt;
in fact its whole purpose is to generate the map data given a set of configuration parameters.&lt;br /&gt;
&lt;br /&gt;
The map generator function is not very well documented. The data on this page are inferred from '''scenarios/multiplayer/Random_Map.cfg''' and '''scenarios/Heir_To_The_Throne/Sceptre.cfg'''.&lt;br /&gt;
An example for a random underground map that is less complex can be found in '''campaigns\Sceptre_of_Fire\scenarios\4_Gathering_Materials.cfg'''.&lt;br /&gt;
&lt;br /&gt;
'''Excerpt from mapgenerator comments:'''&lt;br /&gt;
&lt;br /&gt;
* Basically we generate alot of hills, each hill being centered at a certain point, with a certain radius - being a half sphere. Hills are combined additively to form a bumpy surface. The size of each hill varies randomly from 1-hill_size. We generate 'iterations' hills in total. The range of heights is normalized to 0-1000. 'island_size' controls whether or not the map should tend toward an island shape, and if so, how large the island should be. Hills with centers that are more than 'island_size' away from the center of the map will be inverted (i.e. be valleys). 'island_size' as 0 indicates no island.&lt;br /&gt;
&lt;br /&gt;
Updated with some more info and the changes with the new terrain system&lt;br /&gt;
&lt;br /&gt;
The following keys are recognized for '''[scenario]'''/'''[multiplayer]''' (Use one of them.)&lt;br /&gt;
* '''scenario_generation''': (This is used is the cave examples mentioned above.)&lt;br /&gt;
* '''map_generation''': (This is used in the multiplayer Random Map.)&lt;br /&gt;
&amp;quot;empty&amp;quot; or &amp;quot;default&amp;quot; will use the default generator, &amp;quot;cave&amp;quot; used the cave generator. Other values are not valid.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''':&lt;br /&gt;
* '''[scenario]'''/'''[settings]''': See [[ScenarioWML]]&lt;br /&gt;
* '''name'''&lt;br /&gt;
** '''default''''&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''iterations''': the number of times an attempt is being made to generate a hill (default only)&lt;br /&gt;
* '''hill_size''': hills will have a random size between 1 and ''hill_size'' (default only)&lt;br /&gt;
* '''max_lakes''': the number of times an attempt is being made to generate a lake (default only)&lt;br /&gt;
* '''min_lake_height''': lakes are the starting point of rivers and need to start above a certain height (default only)&lt;br /&gt;
* '''lake_size''': the size of a lake still randomly generated (default only)&lt;br /&gt;
* '''river_frequency''': determine how much a river can run uphill and thus generate more rivers (default only)&lt;br /&gt;
* '''flipx_chance''': Chance to flip x coordinates, that meens the map is mirrored at the vertical axis in its midth. (cave only)&lt;br /&gt;
* '''villages''': villages per 1,000 hexes (default only)&lt;br /&gt;
* '''village_density''': influences number of villages (cave only)&lt;br /&gt;
* '''players'''&lt;br /&gt;
* '''castle_size''': Number of castle tiles (including the keep), per player.&lt;br /&gt;
* '''temperature_iterations''': Same as iterations, but for the temperature map.&lt;br /&gt;
* '''temperature_size''': Same as hill_size, but for the temperature map.&lt;br /&gt;
(Temperature map is generated the same way as a hill map, but is hard coded with a island_size of 0.)&lt;br /&gt;
* '''roads'''&lt;br /&gt;
* '''road_windiness'''&lt;br /&gt;
* '''island_size''': Use 1-5 for coastal maps and 6-10 for island maps. Bigger values may crash map generation process. Bigger numbers makes more water (and less land)&lt;br /&gt;
* '''default_flatland''': If not specified, is Grassland. If your height tags don't go down to 0, the default_flatland will be used (possibly in other cases as well).&lt;br /&gt;
* '''[height]''': list of common terrain types&lt;br /&gt;
which come in at different heights, from highest to lowest (default only)&lt;br /&gt;
Good WML will have the range of 1000-0 covered.&lt;br /&gt;
** '''height''': the terrain specified below will appear at this height and up.&lt;br /&gt;
** '''terrain''': 1 terrain code&lt;br /&gt;
* '''[convert]''': used to make terrain conversions (default only).&lt;br /&gt;
For example water becomes ice at low temperatures, grass snow, etc.&lt;br /&gt;
If the terrain is between the min_x and max_x it will be converted&lt;br /&gt;
if min_x is not defined it will default to a large negative number&lt;br /&gt;
if max_x is not defined it will default to a large positive number&lt;br /&gt;
** '''min_height'''&lt;br /&gt;
** '''max_height'''&lt;br /&gt;
** '''min_temperature'''&lt;br /&gt;
** '''max_temperature'''&lt;br /&gt;
** '''from''': a comma separated terrains to convert from&lt;br /&gt;
** '''to''': The terrain to convert these terrains to&lt;br /&gt;
* '''[road_cost]'''&lt;br /&gt;
** '''terrain''' 1 terrain code&lt;br /&gt;
** '''cost''': how expensive it is the create a road on this terrain, this influences the odds of this terrain getting a road&lt;br /&gt;
** '''convert_to_bridge''': a comma separated list of terrains; N/S, then NE/SW, then NW/SE.&lt;br /&gt;
** '''convert_to''': 1 terrain code (note using both ''convert_to_bridge'' and ''convert_to'' might result in unwanted results)&lt;br /&gt;
* '''[village]''': The conversion of terrains to villages (default only)&lt;br /&gt;
** '''terrain''': 1 terrain code which will be converted to a village&lt;br /&gt;
** '''convert_to''': 1 terrain code for the village&lt;br /&gt;
** '''adjacent_liked''': a comma separated terrain list. This list increases the rating for a certain location, every tile around the location will be tested against this list and for every match the rating of the location is increased. The same terrain twice in the list will double the rating increase for that location.&lt;br /&gt;
** '''rating''': chance of appearing&lt;br /&gt;
* '''[castle]''': the conversion of castles (default only)&lt;br /&gt;
** '''valid_terrain''': a comma-separated terrain list with terrains which are allowed to be converted to a castle.&lt;br /&gt;
** '''min_distance'''&lt;br /&gt;
* '''[naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[village_naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[chamber]''': for underground maps&lt;br /&gt;
** '''id''': a name used to identify where the passages lead.  See the [passage] tag, below.&lt;br /&gt;
** '''x''','''y''': approximate location of the center hex of the chamber.  Unfortunately it isn't always exact.  Can be a single number (x=5) or a range (x=10-20)&lt;br /&gt;
** '''size''': circular radius of the chamber, including the center hex&lt;br /&gt;
** '''jagged''': a good value is probably between 0-50 (not sure exactly)&lt;br /&gt;
** '''[items]''': See [[ScenarioWML]].  This can contain tags normally found under [scenario] like [side], [item], and [event].  Moveto events definitely work here (using the same_location_as_previous key instead of a location filter).  Other events can be placed in the [settings] tag, above.  Locations of items will be generated randomly.  The attribute '''same_location_as_previous=yes''' means that the filter for a moveto event (see [[EventWML]]) is the same as the location of the previous item.&lt;br /&gt;
** '''[passage]''': defines a pathway between chambers&lt;br /&gt;
*** '''destination''': the id key of the destination chamber&lt;br /&gt;
*** '''windiness''': a good value is probably between 1-10&lt;br /&gt;
*** '''width''': number of hexes&lt;br /&gt;
*** '''jagged''': a good value is probably between 1-10&lt;br /&gt;
*** '''chance''': chance for the passage to be generated, between 0 and 100, 100 if key not present&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=PblWML&amp;diff=41290</id>
		<title>PblWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=PblWML&amp;diff=41290"/>
		<updated>2011-03-30T04:00:30Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* author */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{WML Tags}}&lt;br /&gt;
&lt;br /&gt;
To upload an add-on you have made, you need a .pbl file.&lt;br /&gt;
&lt;br /&gt;
This is a file with name '''data/add-ons/''_add_on_name.pbl'' '''(On Wesnoth 1.8+, it is &amp;quot;_server.pbl&amp;quot;)'''.  [http://exong.net/wesnoth-attach/files/pblexample_111.png Click here for an example of what we're talking about.]&lt;br /&gt;
&lt;br /&gt;
When you upload a add-on, the file '''data/add-ons/''addon-name''.cfg'''&lt;br /&gt;
and the directory '''data/add-ons/''addon-name''/''' will be published. Alternatively, '''data/add-ons/''addon-name''.cfg''' can be replaced with '''data/add-ons/''addon-name''/_main.cfg'''. Your add-on must be based entirely on these paths.&lt;br /&gt;
&lt;br /&gt;
Be aware that translations in the .pbl-files are '''not''' used, so don't mark these strings as translatable.&lt;br /&gt;
&lt;br /&gt;
== What goes into a .pbl file? ==&lt;br /&gt;
&lt;br /&gt;
'''Note:''' ''You should '''not''' use special formatting or coloring in any of these keys when uploading to the official server.'''''&lt;br /&gt;
&lt;br /&gt;
The following keys are recognized for .pbl files:&lt;br /&gt;
&lt;br /&gt;
=== icon ===&lt;br /&gt;
: An image, displayed leftmost in the add-ons download dialog. It must be a standard Wesnoth file and not a custom one. A custom file will work for users who already have the relevant add-on installed. This is not related to the icon used for entries in the campaigns menu -- see [[CampaignWML]] for more information.&lt;br /&gt;
&lt;br /&gt;
: If the icon is a unit with magenta team-color bits, please use [[ImagePathFunctionWML]] to recolor it.&lt;br /&gt;
&lt;br /&gt;
=== title ===&lt;br /&gt;
: Displayed to the right of the icon, it is just text. It should usually be the same as the name of your add-on when it is played.&lt;br /&gt;
&lt;br /&gt;
=== version ===&lt;br /&gt;
: Displayed to the right of the title, it is just text. However, starting with Wesnoth 1.6, the ''required'' format is x.y.z where x, y and z are numbers and a value for x greater than 0 implies the add-on is complete feature-wise. Trailing non-numeric elements are allowed, but nothing should appear ''before'' the numbers. This is necessary for the ''Update add-ons'' button to work correctly. ([[#Version Key Examples|See Examples]])&lt;br /&gt;
&lt;br /&gt;
=== author ===&lt;br /&gt;
: Displayed to the right of the version, it is just text. Put your name or nickname here. If several people have contributed significantly to the add-on you may want to list all of their names.&lt;br /&gt;
&lt;br /&gt;
=== passphrase ===&lt;br /&gt;
: Not displayed, it prevents others from modifying the version of your add-on on the server. You do not need to input a passphrase when initially publishing a add-on; if you do not, one will be randomly generated for you and replaced in your local copy of the .pbl file.&lt;br /&gt;
&lt;br /&gt;
=== description ===&lt;br /&gt;
: This can be used to provide a brief description of your add-on, and for pre-1.0 versions, let people know how playable it is. The description can be viewed by users by clicking on the Description button in the built-in client, or by moving their mouse over the add-on's icon in the web interface.&lt;br /&gt;
&lt;br /&gt;
=== dependencies ===&lt;br /&gt;
: An optional list of dependencies (a comma separated list of ''addon-name'' – the directory names of the needed add-ons), which should be provided if your add-on relies on other user-made content to work properly. ([[#Dependency Key Example|See Example]])&lt;br /&gt;
&lt;br /&gt;
=== translate ===&lt;br /&gt;
: If set to '''true''', the add-on will be sent to and updated with [[WesCamp|WesCamp-i18n]]. (NOTE: this is a new and experimental function, which will automatically update the translations in your add-on. Make sure you make backups of your add-on in case of problems.)&lt;br /&gt;
&lt;br /&gt;
: You should make sure your add-on complies with some very specific [[WesCamp#How_to_contribute_to_this_Project|conventions]] required to ease the process for translators.&lt;br /&gt;
&lt;br /&gt;
=== type ===&lt;br /&gt;
: Indicates the type of the add-on, used for the downloads manager dialog. Possible values are:&lt;br /&gt;
&lt;br /&gt;
:* ''campaign'': single player campaign.&lt;br /&gt;
:* ''scenario'': single player scenario.&lt;br /&gt;
:* ''era'': multiplayer era.&lt;br /&gt;
:* ''faction'': multiplayer stand-alone faction, or add-on for other available era.&lt;br /&gt;
:* ''map_pack'': multiplayer map-pack.&lt;br /&gt;
:* ''campaign_mp'': multiplayer campaign.&lt;br /&gt;
:* ''scenario_mp'': multiplayer scenario. (See the note below.)&lt;br /&gt;
:* ''media'': miscellaneous resources for UMC authors/users, for example, music packs, packages of general-purpose WML, etc.&lt;br /&gt;
:* ''other'': The type to use when no other type fits.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If your add-on contains two or more separate multiplayer scenarios, use ''map_pack''.&lt;br /&gt;
&lt;br /&gt;
=== email ===&lt;br /&gt;
: Hidden e-mail address used by the server administrators to contact content authors in case of major issues. Again, this will only be seen by the server administrators and it is ''highly'' recommended that you provide one in case you need to be contacted about your add-on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The add-on server keeps track of some other information about uploaded content, including when they were uploaded, what languages they have been at least partly translated into, how large they are on the server and the number of times they have been downloaded. For more information about this you can read [[CampaignServerWML]].&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Dependency Key Example ===&lt;br /&gt;
&lt;br /&gt;
The following dependency key could be used when the add-on needs the ''Imperial_Era'' and ''Era_of_Myths'' to be installed before it will work properly:&lt;br /&gt;
&lt;br /&gt;
 dependencies=Imperial_Era,Era_of_Myths&lt;br /&gt;
&lt;br /&gt;
=== Version Key Examples ===&lt;br /&gt;
&lt;br /&gt;
The following are examples of '''good''' version values:&lt;br /&gt;
&lt;br /&gt;
 version=&amp;quot;1.5&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 version=&amp;quot;0.11.4&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 version=&amp;quot;0.1.4beta&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 version=&amp;quot;1.5c&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following are examples of '''bad''' version values:&lt;br /&gt;
&lt;br /&gt;
 version=&amp;quot;Beta1.5&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 version=&amp;quot;Incomplete (0.3.4)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In both of the above examples the version number as read by the server will be '''0.0.0Beta1.5''' and '''0.0.0Incomplete (0.3.4)'''. You can clearly see why this will not be a good thing with the ''Update add-ons'' feature.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally, here are some example version numbers and how they will be interpreted by the ''Update add-ons'' button. The number on the left will be considered an earlier number than the number on the right in each example.&lt;br /&gt;
&lt;br /&gt;
 0.5 &amp;lt; 1.0&lt;br /&gt;
&lt;br /&gt;
 1.5 &amp;lt; 1.5c&lt;br /&gt;
&lt;br /&gt;
 1.0 &amp;lt; 1.0.1&lt;br /&gt;
&lt;br /&gt;
 1.0c &amp;lt; 1.0.1a&lt;br /&gt;
&lt;br /&gt;
 1.0.1a &amp;lt; 1.0.1c&lt;br /&gt;
&lt;br /&gt;
 1.0 Final &amp;lt; 1.0.1 Beta&lt;br /&gt;
&lt;br /&gt;
=== Example .pbl File ===&lt;br /&gt;
&lt;br /&gt;
 title=&amp;quot;My Campaign&amp;quot;&lt;br /&gt;
 type=&amp;quot;campaign&amp;quot;&lt;br /&gt;
 icon=&amp;quot;misc/ball.png&amp;quot;&lt;br /&gt;
 version=&amp;quot;0.1.2&amp;quot;&lt;br /&gt;
 author=&amp;quot;Me, artwork by myself&amp;quot;&lt;br /&gt;
 passphrase=&amp;quot;This is like a password&amp;quot;&lt;br /&gt;
 description=&amp;quot;You get to kill a lot of bad guys. But only the first map is done.&amp;quot;&lt;br /&gt;
 email=&amp;quot;name@example.com&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
* [[BuildingCampaignsThePBLFile]]&lt;br /&gt;
* [[CampaignServerWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=41125</id>
		<title>MapGeneratorWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=41125"/>
		<updated>2011-03-24T17:00:18Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* [generator] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== [generator] ==&lt;br /&gt;
&lt;br /&gt;
The [generator] tag replaces a scenario's map data;&lt;br /&gt;
in fact its whole purpose is to generate the map data given a set of configuration parameters.&lt;br /&gt;
&lt;br /&gt;
The map generator function is not very well documented. The data on this page are inferred from '''scenarios/multiplayer/Random_Map.cfg''' and '''scenarios/Heir_To_The_Throne/Sceptre.cfg'''.&lt;br /&gt;
An example for a random underground map that is less complex can be found in '''campaigns\Sceptre_of_Fire\scenarios\4_Gathering_Materials.cfg'''.&lt;br /&gt;
&lt;br /&gt;
'''Excerpt from mapgenerator comments:'''&lt;br /&gt;
&lt;br /&gt;
* Basically we generate alot of hills, each hill being centered at a certain point, with a certain radius - being a half sphere. Hills are combined additively to form a bumpy surface. The size of each hill varies randomly from 1-hill_size. We generate 'iterations' hills in total. The range of heights is normalized to 0-1000. 'island_size' controls whether or not the map should tend toward an island shape, and if so, how large the island should be. Hills with centers that are more than 'island_size' away from the center of the map will be inverted (i.e. be valleys). 'island_size' as 0 indicates no island.&lt;br /&gt;
&lt;br /&gt;
Updated with some more info and the changes with the new terrain system&lt;br /&gt;
&lt;br /&gt;
The following keys are recognized for '''[scenario]'''/'''[multiplayer]''' (Use one of them.)&lt;br /&gt;
* '''scenario_generation''': (This is used is the cave examples mentioned above.)&lt;br /&gt;
* '''map_generation''': (This is used in the multiplayer Random Map.)&lt;br /&gt;
&amp;quot;empty&amp;quot; or &amp;quot;default&amp;quot; will use the default generator, &amp;quot;cave&amp;quot; used the cave generator. Other values are not valid.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''':&lt;br /&gt;
* '''[scenario]'''/'''[settings]''': See [[ScenarioWML]]&lt;br /&gt;
* '''name'''&lt;br /&gt;
** '''default''''&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''iterations''': the number of times an attempt is being made to generate a hill (default only)&lt;br /&gt;
* '''hill_size''': hills will have a random size between 1 and ''hill_size'' (default only)&lt;br /&gt;
* '''max_lakes''': the number of times an attempt is being made to generate a lake (default only)&lt;br /&gt;
* '''min_lake_height''': lakes are the starting point of rivers and need to start above a certain height (default only)&lt;br /&gt;
* '''lake_size''': the size of a lake still randomly generated (default only)&lt;br /&gt;
* '''river_frequency''': determine how much a river can run uphill and thus generate more rivers (default only)&lt;br /&gt;
* '''flipx_chance''': Chance to flip x coordinates, that meens the map is mirrored at the vertical axis in its midth.&lt;br /&gt;
* '''villages'''&lt;br /&gt;
* '''village_density''': tiles per village ???&lt;br /&gt;
* '''players'''&lt;br /&gt;
* '''castle_size''': Number of castle tiles (including the keep), per player.&lt;br /&gt;
* '''temperature_iterations''': Same as iterations, but for the temperature map.&lt;br /&gt;
* '''temperature_size''': Same as hill_size, but for the temperature map.&lt;br /&gt;
(Temperature map is generated the same way as a hill map, but is hard coded with a island_size of 0.)&lt;br /&gt;
* '''roads'''&lt;br /&gt;
* '''road_windiness'''&lt;br /&gt;
* '''island_size''': Use 1-5 for coastal maps and 6-10 for island maps. Bigger values may crash map generation process. Bigger numbers makes more water (and less land)&lt;br /&gt;
* '''default_flatland''': If not specified, is Grassland. If your height tags don't go down to 0, the default_flatland will be used (possibly in other cases as well).&lt;br /&gt;
* '''[height]''': list of common terrain types&lt;br /&gt;
which come in at different heights, from highest to lowest (default only)&lt;br /&gt;
Good WML will have the range of 1000-0 covered.&lt;br /&gt;
** '''height''': the terrain specified below will appear at this height and up.&lt;br /&gt;
** '''terrain''': 1 terrain code&lt;br /&gt;
* '''[convert]''': used to make terrain conversions (default only).&lt;br /&gt;
For example water becomes ice at low temperatures, grass snow, etc.&lt;br /&gt;
If the terrain is between the min_x and max_x it will be converted&lt;br /&gt;
if min_x is not defined it will default to a large negative number&lt;br /&gt;
if max_x is not defined it will default to a large positive number&lt;br /&gt;
** '''min_height'''&lt;br /&gt;
** '''max_height'''&lt;br /&gt;
** '''min_temperature'''&lt;br /&gt;
** '''max_temperature'''&lt;br /&gt;
** '''from''': a comma separated terrains to convert from&lt;br /&gt;
** '''to''': The terrain to convert these terrains to&lt;br /&gt;
* '''[road_cost]'''&lt;br /&gt;
** '''terrain''' 1 terrain code&lt;br /&gt;
** '''cost''': how expensive it is the create a road on this terrain, this influences the odds of this terrain getting a road&lt;br /&gt;
** '''convert_to_bridge''': a comma separated list of terrains; N/S, then NE/SW, then NW/SE.&lt;br /&gt;
** '''convert_to''': 1 terrain code (note using both ''convert_to_bridge'' and ''convert_to'' might result in unwanted results)&lt;br /&gt;
* '''[village]''': The conversion of terrains to villages (default only)&lt;br /&gt;
** '''terrain''': 1 terrain code which will be converted to a village&lt;br /&gt;
** '''convert_to''': 1 terrain code for the village&lt;br /&gt;
** '''adjacent_liked''': a comma separated terrain list. This list increases the rating for a certain location, every tile around the location will be tested against this list and for every match the rating of the location is increased. The same terrain twice in the list will double the rating increase for that location.&lt;br /&gt;
** '''rating''': chance of appearing&lt;br /&gt;
* '''[castle]''': the conversion of castles (default only)&lt;br /&gt;
** '''valid_terrain''': a comma-separated terrain list with terrains which are allowed to be converted to a castle.&lt;br /&gt;
** '''min_distance'''&lt;br /&gt;
* '''[naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[village_naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[chamber]''': for underground maps&lt;br /&gt;
** '''id''': a name used to identify where the passages lead.  See the [passage] tag, below.&lt;br /&gt;
** '''x''','''y''': approximate location of the center hex of the chamber.  Unfortunately it isn't always exact.  Can be a single number (x=5) or a range (x=10-20)&lt;br /&gt;
** '''size''': circular radius of the chamber, including the center hex&lt;br /&gt;
** '''jagged''': a good value is probably between 0-50 (not sure exactly)&lt;br /&gt;
** '''[items]''': See [[ScenarioWML]].  This can contain tags normally found under [scenario] like [side], [item], and [event].  Moveto events definitely work here (using the same_location_as_previous key instead of a location filter).  Other events can be placed in the [settings] tag, above.  Locations of items will be generated randomly.  The attribute '''same_location_as_previous=yes''' means that the filter for a moveto event (see [[EventWML]]) is the same as the location of the previous item.&lt;br /&gt;
** '''[passage]''': defines a pathway between chambers&lt;br /&gt;
*** '''destination''': the id key of the destination chamber&lt;br /&gt;
*** '''windiness''': a good value is probably between 1-10&lt;br /&gt;
*** '''width''': number of hexes&lt;br /&gt;
*** '''jagged''': a good value is probably between 1-10&lt;br /&gt;
*** '''chance''': chance for the passage to be generated, between 0 and 100, 100 if key not present&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=41124</id>
		<title>MapGeneratorWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=41124"/>
		<updated>2011-03-24T16:58:41Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* [generator] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== [generator] ==&lt;br /&gt;
&lt;br /&gt;
The [generator] tag replaces a scenario's map data;&lt;br /&gt;
in fact its whole purpose is to generate the map data given a set of configuration parameters.&lt;br /&gt;
&lt;br /&gt;
The map generator function is not very well documented. The data on this page are inferred from '''scenarios/multiplayer/Random_Map.cfg''' and '''scenarios/Heir_To_The_Throne/Sceptre.cfg'''.&lt;br /&gt;
An example for a random underground map that is less complex can be found in '''campaigns\Sceptre_of_Fire\scenarios\4_Gathering_Materials.cfg'''.&lt;br /&gt;
&lt;br /&gt;
'''Excerpt from mapgenerator comments:'''&lt;br /&gt;
&lt;br /&gt;
* Basically we generate alot of hills, each hill being centered at a certain point, with a certain radius - being a half sphere. Hills are combined additively to form a bumpy surface. The size of each hill varies randomly from 1-hill_size. We generate 'iterations' hills in total. The range of heights is normalized to 0-1000. 'island_size' controls whether or not the map should tend toward an island shape, and if so, how large the island should be. Hills with centers that are more than 'island_size' away from the center of the map will be inverted (i.e. be valleys). 'island_size' as 0 indicates no island.&lt;br /&gt;
&lt;br /&gt;
Updated with some more info and the changes with the new terrain system&lt;br /&gt;
&lt;br /&gt;
The following keys are recognized for '''[scenario]'''/'''[multiplayer]'''&lt;br /&gt;
* '''scenario_generation''': (This is used is the cave examples mentioned above.)&lt;br /&gt;
* '''map_generation''': (This is used in the multiplayer Random Map.)&lt;br /&gt;
&amp;quot;empty&amp;quot; or &amp;quot;default&amp;quot; will use the default generator, &amp;quot;cave&amp;quot; used the cave generator. Other values are not valid.&lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''':&lt;br /&gt;
* '''[scenario]'''/'''[settings]''': See [[ScenarioWML]]&lt;br /&gt;
* '''name'''&lt;br /&gt;
** '''default''''&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''iterations''': the number of times an attempt is being made to generate a hill (default only)&lt;br /&gt;
* '''hill_size''': hills will have a random size between 1 and ''hill_size'' (default only)&lt;br /&gt;
* '''max_lakes''': the number of times an attempt is being made to generate a lake (default only)&lt;br /&gt;
* '''min_lake_height''': lakes are the starting point of rivers and need to start above a certain height (default only)&lt;br /&gt;
* '''lake_size''': the size of a lake still randomly generated (default only)&lt;br /&gt;
* '''river_frequency''': determine how much a river can run uphill and thus generate more rivers (default only)&lt;br /&gt;
* '''flipx_chance''': Chance to flip x coordinates, that meens the map is mirrored at the vertical axis in its midth.&lt;br /&gt;
* '''villages'''&lt;br /&gt;
* '''village_density''': tiles per village ???&lt;br /&gt;
* '''players'''&lt;br /&gt;
* '''castle_size''': Number of castle tiles (including the keep), per player.&lt;br /&gt;
* '''temperature_iterations''': Same as iterations, but for the temperature map.&lt;br /&gt;
* '''temperature_size''': Same as hill_size, but for the temperature map.&lt;br /&gt;
(Temperature map is generated the same way as a hill map, but is hard coded with a island_size of 0.)&lt;br /&gt;
* '''roads'''&lt;br /&gt;
* '''road_windiness'''&lt;br /&gt;
* '''island_size''': Use 1-5 for coastal maps and 6-10 for island maps. Bigger values may crash map generation process. Bigger numbers makes more water (and less land)&lt;br /&gt;
* '''default_flatland''': If not specified, is Grassland. If your height tags don't go down to 0, the default_flatland will be used (possibly in other cases as well).&lt;br /&gt;
* '''[height]''': list of common terrain types&lt;br /&gt;
which come in at different heights, from highest to lowest (default only)&lt;br /&gt;
Good WML will have the range of 1000-0 covered.&lt;br /&gt;
** '''height''': the terrain specified below will appear at this height and up.&lt;br /&gt;
** '''terrain''': 1 terrain code&lt;br /&gt;
* '''[convert]''': used to make terrain conversions (default only).&lt;br /&gt;
For example water becomes ice at low temperatures, grass snow, etc.&lt;br /&gt;
If the terrain is between the min_x and max_x it will be converted&lt;br /&gt;
if min_x is not defined it will default to a large negative number&lt;br /&gt;
if max_x is not defined it will default to a large positive number&lt;br /&gt;
** '''min_height'''&lt;br /&gt;
** '''max_height'''&lt;br /&gt;
** '''min_temperature'''&lt;br /&gt;
** '''max_temperature'''&lt;br /&gt;
** '''from''': a comma separated terrains to convert from&lt;br /&gt;
** '''to''': The terrain to convert these terrains to&lt;br /&gt;
* '''[road_cost]'''&lt;br /&gt;
** '''terrain''' 1 terrain code&lt;br /&gt;
** '''cost''': how expensive it is the create a road on this terrain, this influences the odds of this terrain getting a road&lt;br /&gt;
** '''convert_to_bridge''': a comma separated list of terrains; N/S, then NE/SW, then NW/SE.&lt;br /&gt;
** '''convert_to''': 1 terrain code (note using both ''convert_to_bridge'' and ''convert_to'' might result in unwanted results)&lt;br /&gt;
* '''[village]''': The conversion of terrains to villages (default only)&lt;br /&gt;
** '''terrain''': 1 terrain code which will be converted to a village&lt;br /&gt;
** '''convert_to''': 1 terrain code for the village&lt;br /&gt;
** '''adjacent_liked''': a comma separated terrain list. This list increases the rating for a certain location, every tile around the location will be tested against this list and for every match the rating of the location is increased. The same terrain twice in the list will double the rating increase for that location.&lt;br /&gt;
** '''rating''': chance of appearing&lt;br /&gt;
* '''[castle]''': the conversion of castles (default only)&lt;br /&gt;
** '''valid_terrain''': a comma-separated terrain list with terrains which are allowed to be converted to a castle.&lt;br /&gt;
** '''min_distance'''&lt;br /&gt;
* '''[naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[village_naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[chamber]''': for underground maps&lt;br /&gt;
** '''id''': a name used to identify where the passages lead.  See the [passage] tag, below.&lt;br /&gt;
** '''x''','''y''': approximate location of the center hex of the chamber.  Unfortunately it isn't always exact.  Can be a single number (x=5) or a range (x=10-20)&lt;br /&gt;
** '''size''': circular radius of the chamber, including the center hex&lt;br /&gt;
** '''jagged''': a good value is probably between 0-50 (not sure exactly)&lt;br /&gt;
** '''[items]''': See [[ScenarioWML]].  This can contain tags normally found under [scenario] like [side], [item], and [event].  Moveto events definitely work here (using the same_location_as_previous key instead of a location filter).  Other events can be placed in the [settings] tag, above.  Locations of items will be generated randomly.  The attribute '''same_location_as_previous=yes''' means that the filter for a moveto event (see [[EventWML]]) is the same as the location of the previous item.&lt;br /&gt;
** '''[passage]''': defines a pathway between chambers&lt;br /&gt;
*** '''destination''': the id key of the destination chamber&lt;br /&gt;
*** '''windiness''': a good value is probably between 1-10&lt;br /&gt;
*** '''width''': number of hexes&lt;br /&gt;
*** '''jagged''': a good value is probably between 1-10&lt;br /&gt;
*** '''chance''': chance for the passage to be generated, between 0 and 100, 100 if key not present&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>SigurdTheDragon</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=40718</id>
		<title>MapGeneratorWML</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=MapGeneratorWML&amp;diff=40718"/>
		<updated>2011-03-09T20:40:59Z</updated>

		<summary type="html">&lt;p&gt;SigurdTheDragon: /* [generator] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== [generator] ==&lt;br /&gt;
&lt;br /&gt;
The [generator] tag replaces a scenario's map data;&lt;br /&gt;
in fact its whole purpose is to generate the map data given a set of configuration parameters.&lt;br /&gt;
&lt;br /&gt;
The map generator function is not very well documented. The data on this page are inferred from '''scenarios/multiplayer/Random_Map.cfg''' and '''scenarios/Heir_To_The_Throne/Sceptre.cfg'''.&lt;br /&gt;
An example for a random underground map that is less complex can be found in '''campaigns\Sceptre_of_Fire\scenarios\4_Gathering_Materials.cfg'''.&lt;br /&gt;
&lt;br /&gt;
'''Excerpt from mapgenerator comments:'''&lt;br /&gt;
&lt;br /&gt;
* Basically we generate alot of hills, each hill being centered at a certain point, with a certain radius - being a half sphere. Hills are combined additively to form a bumpy surface. The size of each hill varies randomly from 1-hill_size. We generate 'iterations' hills in total. The range of heights is normalized to 0-1000. 'island_size' controls whether or not the map should tend toward an island shape, and if so, how large the island should be. Hills with centers that are more than 'island_size' away from the center of the map will be inverted (i.e. be valleys). 'island_size' as 0 indicates no island.&lt;br /&gt;
&lt;br /&gt;
Updated with some more info and the changes with the new terrain system&lt;br /&gt;
&lt;br /&gt;
The following key is recognized for '''[scenario]'''/'''[multiplayer]'''&lt;br /&gt;
* '''map_generation''': &amp;quot;empty&amp;quot; or &amp;quot;default&amp;quot; will use the default generator, &amp;quot;cave&amp;quot; used the cave generator. Other values are not valid. &lt;br /&gt;
&lt;br /&gt;
The following key/tags are recognized for '''[generator]''':&lt;br /&gt;
* '''[scenario]'''/'''[settings]''': See [[ScenarioWML]]&lt;br /&gt;
* '''name'''&lt;br /&gt;
** '''default''''&lt;br /&gt;
* '''map_width''','''map_height''': size of the map to generate&lt;br /&gt;
* '''iterations''': the number of times an attempt is being made to generate a hill (default only)&lt;br /&gt;
* '''hill_size''': hills will have a random size between 1 and ''hill_size'' (default only)&lt;br /&gt;
* '''max_lakes''': the number of times an attempt is being made to generate a lake (default only)&lt;br /&gt;
* '''min_lake_height''': lakes are the starting point of rivers and need to start above a certain height (default only)&lt;br /&gt;
* '''lake_size''': the size of a lake still randomly generated (default only)&lt;br /&gt;
* '''river_frequency''': determine how much a river can run uphill and thus generate more rivers (default only)&lt;br /&gt;
* '''flipx_chance''': Chance to flip x coordinates, that meens the map is mirrored at the vertical axis in its midth.&lt;br /&gt;
* '''villages'''&lt;br /&gt;
* '''village_density''': tiles per village ???&lt;br /&gt;
* '''players'''&lt;br /&gt;
* '''castle_size''': Number of castle tiles (including the keep), per player.&lt;br /&gt;
* '''temperature_iterations''': Same as iterations, but for the temperature map.&lt;br /&gt;
* '''temperature_size''': Same as hill_size, but for the temperature map.&lt;br /&gt;
(Temperature map is generated the same way as a hill map, but is hard coded with a island_size of 0.)&lt;br /&gt;
* '''roads'''&lt;br /&gt;
* '''road_windiness'''&lt;br /&gt;
* '''island_size''': Use 1-5 for coastal maps and 6-10 for island maps. Bigger values may crash map generation process. Bigger numbers makes more water (and less land)&lt;br /&gt;
* '''default_flatland''': If not specified, is Grassland. If your height tags don't go down to 0, the default_flatland will be used (possibly in other cases as well).&lt;br /&gt;
* '''[height]''': list of common terrain types&lt;br /&gt;
which come in at different heights, from highest to lowest (default only)&lt;br /&gt;
Good WML will have the range of 1000-0 covered.&lt;br /&gt;
** '''height''': the terrain specified below will appear at this height and up.&lt;br /&gt;
** '''terrain''': 1 terrain code&lt;br /&gt;
* '''[convert]''': used to make terrain conversions (default only).&lt;br /&gt;
For example water becomes ice at low temperatures, grass snow, etc.&lt;br /&gt;
If the terrain is between the min_x and max_x it will be converted&lt;br /&gt;
if min_x is not defined it will default to a large negative number&lt;br /&gt;
if max_x is not defined it will default to a large positive number&lt;br /&gt;
** '''min_height'''&lt;br /&gt;
** '''max_height'''&lt;br /&gt;
** '''min_temperature'''&lt;br /&gt;
** '''max_temperature'''&lt;br /&gt;
** '''from''': a comma separated terrains to convert from&lt;br /&gt;
** '''to''': The terrain to convert these terrains to&lt;br /&gt;
* '''[road_cost]'''&lt;br /&gt;
** '''terrain''' 1 terrain code&lt;br /&gt;
** '''cost''': how expensive it is the create a road on this terrain, this influences the odds of this terrain getting a road&lt;br /&gt;
** '''convert_to_bridge''': a comma separated list of terrains; N/S, then NE/SW, then NW/SE.&lt;br /&gt;
** '''convert_to''': 1 terrain code (note using both ''convert_to_bridge'' and ''convert_to'' might result in unwanted results)&lt;br /&gt;
* '''[village]''': The conversion of terrains to villages (default only)&lt;br /&gt;
** '''terrain''': 1 terrain code which will be converted to a village&lt;br /&gt;
** '''convert_to''': 1 terrain code for the village&lt;br /&gt;
** '''adjacent_liked''': a comma separated terrain list. This list increases the rating for a certain location, every tile around the location will be tested against this list and for every match the rating of the location is increased. The same terrain twice in the list will double the rating increase for that location.&lt;br /&gt;
** '''rating''': chance of appearing&lt;br /&gt;
* '''[castle]''': the conversion of castles (default only)&lt;br /&gt;
** '''valid_terrain''': a comma-separated terrain list with terrains which are allowed to be converted to a castle.&lt;br /&gt;
** '''min_distance'''&lt;br /&gt;
* '''[naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[village_naming]'''&lt;br /&gt;
** '''male_names'''&lt;br /&gt;
* '''[chamber]''': for underground maps&lt;br /&gt;
** '''id''': a name used to identify where the passages lead.  See the [passage] tag, below.&lt;br /&gt;
** '''x''','''y''': approximate location of the center hex of the chamber.  Unfortunately it isn't always exact.  Can be a single number (x=5) or a range (x=10-20)&lt;br /&gt;
** '''size''': circular radius of the chamber, including the center hex&lt;br /&gt;
** '''jagged''': a good value is probably between 0-50 (not sure exactly)&lt;br /&gt;
** '''[items]''': See [[ScenarioWML]].  This can contain tags normally found under [scenario] like [side], [item], and [event].  Moveto events definitely work here (using the same_location_as_previous key instead of a location filter).  Other events can be placed in the [settings] tag, above.  Locations of items will be generated randomly.  The attribute '''same_location_as_previous=yes''' means that the filter for a moveto event (see [[EventWML]]) is the same as the location of the previous item.&lt;br /&gt;
** '''[passage]''': defines a pathway between chambers&lt;br /&gt;
*** '''destination''': the id key of the destination chamber&lt;br /&gt;
*** '''windiness''': a good value is probably between 1-10&lt;br /&gt;
*** '''width''': number of hexes&lt;br /&gt;
*** '''jagged''': a good value is probably between 1-10&lt;br /&gt;
*** '''chance''': chance for the passage to be generated, between 0 and 100, 100 if key not present&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[ScenarioWML]]&lt;br /&gt;
* [[ReferenceWML]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WML Reference]]&lt;/div&gt;</summary>
		<author><name>SigurdTheDragon</name></author>
		
	</entry>
</feed>