From The Battle for Wesnoth Wiki

[edit]WML Tags


abilities, about, add_ai_behavior, advance, advanced_preference, advancefrom, advancement, advances, affect_adjacent, ai, allied_with, allow_end_turn, allow_extra_recruit, allow_recruit, allow_undo, and, animate, animate_unit, animation, aspect, attack, attack_anim, attacks, avoid;


base_unit, berserk, binary_path, break, brush;


campaign, cancel_action, candidate_action, capture_village, case, chance_to_hit, change_theme, chat, choose, clear_global_variable, clear_menu_item, clear_variable, color_adjust, color_range, command (action, replay), continue, criteria;


damage, death, deaths, default, defend, defends, defense, delay, deprecated_message, destination, difficulty, disable, disallow_end_turn, disallow_extra_recruit, disallow_recruit, do, do_command, drains, draw_weapon_anim;


editor_group, editor_music, editor_times, effect, else (action, animation), elseif, endlevel, end_turn (action, replay), enemy_of, engine, entry, era, event, extra_anim;


facet, facing, fake_unit, false, feedback, female, filter (concept, event), filter_adjacent, filter_adjacent_location, filter_attack, filter_attacker, filter_base_value, filter_condition, filter_defender, filter_enemy, filter_location, filter_opponent, filter_own, filter_owner, filter_radius, filter_recall, filter_second, filter_second_attack, filter_self, filter_side, filter_vision, filter_weapon, filter_wml, find_path, fire_event, firststrike, floating_text, for, foreach, frame, full_heal;


game_config, get_global_variable, goal, gold, gold_carryover;


harm_unit, has_ally, has_attack, has_unit, have_location, have_unit, heal_on_hit, heal_unit, healed_anim, healing_anim, heals, hide_help, hide_unit, hides;


idle_anim, if (action, animation), illuminates, image, init_side, insert_tag, inspect, item, item_group;


jamming_costs, join;


kill, killed;


label, language, leader_goal, leadership, leading_anim, levelin_anim, levelout_anim, lift_fog, limit, literal, load_resource, locale, lock_view, lua;


male, menu_item, message, micro_ai, missile_frame, modification, modifications, modify_ai, modify_side, modify_turns, modify_unit, move, move_unit, move_unit_fake, move_units_fake, movement_anim, movement costs, movetype, multiplayer, multiplayer_side, music;


not, note;


object, objective, objectives, on_undo, open_help, option, options, or;


part, petrifies, petrify, place_shroud, plague, poison, portrait, post_movement_anim, pre_movement_anim, primary_attack, primary_unit, print, put_to_recall_list;


race, random_placement, recall (action, replay), recalls, recruit, recruit_anim, recruiting_anim, recruits, redraw, regenerate, remove_event, remove_item, remove_object, remove_shroud, remove_sound_source, remove_time_area, remove_unit_overlay, repeat, replace_map, replace_schedule, replay, replay_start, reset_fog, resistance (ability, unit), resistance_defaults, resource, return, role, rule;


save, scenario, scroll, scroll_to, scroll_to_unit, secondary_attack, secondary_unit, section, select_unit, sequence, set_extra_recruit, set_global_variable, set_menu_item, set_recruit, set_specials, set_variable, set_variables, sheath_weapon_anim, show_if (message, set_menu_item), show_objectives, side, skirmisher, slow, snapshot, sound, sound_source, source (replay, teleport), specials, split, stage, standing_anim, statistics, status, store_gold, store_items, store_locations, store_map_dimensions, store_reachable_locations, store_relative_direction, store_side, store_starting_location, store_time_of_day, store_turns, store_unit, store_unit_defense, store_unit_type, store_unit_type_ids, store_villages, story, swarm, switch, sync_variable;


target, team, teleport (ability, action), teleport_anim, terrain, terrain_defaults, terrain_graphics, terrain_mask, terrain_type, test, test_condition, text_input, textdomain, theme, then, tile, time, time_area, topic, toplevel, trait, transform_unit, traveler, true, tunnel, tutorial;


unhide_unit, unit, unit_overlay, unit_type, unit_worth, units, unlock_view, unpetrify, unstore_unit, unsynced;


value, variable, variables, variation, victory_anim, village, vision_costs, volume;


while, wml_message, wml_schema;



SchemaWML is a way of describing the form of a WML document using WML. A WML schema consists of a root [wml_schema] tag containing a single [tag] tag and possibly some [type] tags.

Defining a type

A type in SchemaWML is defined by the [type] tag. Types are used to validate the values of WML keys. The [type] tag supports the following keys and subtags:

  • name: The name of the type, to be referenced from elsewhere in the schema.
  • value: A regular expression that matches the type. Note that anchors (^ and $) are not automatically added, so the expression will match if it can match any substring of the key's value. (Version 1.15.0 and later only) Regular expressions are now anchored. To obtain the previous behaviour, add .* at the beginning and end of the expression.
  • link: (Version 1.15.0 and later only) Use instead of value to define an alias for another type. The value of link must name another defined type.
  • [union]: (Version 1.15.0 and later only) Use instead of value to define a type as a union of one or more other types. It contains one or more [type] subtags, without the name key. The union type matches any value that matches one of the subtypes.
  • [intersection]: (Version 1.15.0 and later only) Use instead of value to define a type as an intersection of one or more other types. It contains one or more [type] subtags, without the name key. The intersections type matches only values that matches all of the subtypes.
  • [list]: (Version 1.15.0 and later only) Use instead of value to define a list type. Supports the following additional keys and tags:
    • min: The minimum number of list elements
    • max: The maximum number of list elements
    • split: A regular expression used to split the key value up into list elements; defaults to \s*,\s*.
    • [element]: One or more of these tags is required; they are equivalent to the [type] subtags in [union] and [intersection], and specify possible types for the list elements. Each list element must match at lease one of these subtypes for the whole list to match.

Defining a tag

The [tag] tag defines a single WML tag that is allowed in a particular context. All WML schemas have at least one tag, the "root" tag; this represents the root level of the WML document and is not actually a real tag.

Each tag can be uniquely referenced by a path, which consists of a sequence of tag names (as specified in the name key) separated by slashes. The initial "root" tag is omitted from the path.

Tags support the following keys and subtags:

  • name: The name of the tag; should be "root" for the root tag. (Version 1.15.0 and later only) Supports glob syntax, which allows a single [tag] to match multiple actual tags. Also note that the name does not need to be a valid tag name - if it's not a valid tag name, it will never match any tags in the document, but can still be referenced by other tag definitions.
  • min: The minimum number of times this tag may occur. (Version 1.15.0 and later only) Defaults to 0.
  • max: The maximum number of times this tag may occur. Specify -1 if it may occur an unlimited number of times. (Version 1.15.0 and later only) Defaults to 1. Also, you can now use infinite instead of -1.
  • super: The path to a defined tag that is used as a starting point for this tag. That is, anything defined in the supertag is also allowed in this tag. Note that min and max are not inherited from the parent tag, though any_tag is. (Version 1.15.0 and later only) This can also be a comma-separated list of paths, supporting multiple inheritance of tag definitions.
  • any_tag: (Version 1.15.0 and later only) If set to true, this tag will accept any subtag without error. Known subtags that match a tag definition will be validated as normal; unknown subtags will simply be ignored.
  • deprecated: (Version 1.15.0 and later only) Set to true to mark the tag as deprecated. A warning will be issued if it is used.
  • [tag]: Define a subtag.
  • [key]: Define a key. See below.
  • [switch]: (Version 1.15.0 and later only) Sometimes the allowed content of a tag may be governed by the value of one particular key in the tag. That's what a [switch] tag is for. It supports the following keys and subtags:
    • key: The key whose value is checked to determine which branch to take.
    • [case]: Defines a single branch of the switch.
      • value: The value or values (a comma-separated list) that cause this branch to match. Note that cases are considered in order of appearance.
      • trigger_if_missing: If true, this case also matches if the key is absent. If no case includes this, the [else] tag matches when the key is absent.
      • Anything that is allowed in [tag] is allowed in [case], including another [switch]. Note that tags defined inside a [switch] do not have a path and thus cannot be referenced from elsewhere, not even by other tags in the same [switch]. Note that the min and max keys, although accepted, have no effect here. Both super and any_tag keys may be conditionally applied, though.
    • [else]: A switch may have one of these, which matches if none of the cases match. Other than the lack of value and trigger_if_missing keys, and the fact that there can be only one, this is equivalent to [case].
  • [if]: (Version 1.15.0 and later only) Sometimes the allowed content of a tag may depend on some subset of its content. That's what an [if] tag is for - it runs a [filter_wml] on the tag being validated and uses the outcome to determine what else is allowed in that tag.
    • The same syntax as [filter_wml] is supported.
    • [then]: Contains tag contents (same as in [else]) that will be used if the filter matches. This can also be omitted if needed.
    • [elseif]: Adds another filter to test if the first fails. You can use more than one of these. Each one requires a [then] tag in addition to the filter.
    • [else]: Contains tag contents to be used if none of the filters match

If you want to include an existing tag definition verbatim with no changes, including inheriting the min and max attributes, you can use the [link] tag instead of [tag]. It accepts just one key, name, which must be the path to the parent tag.

Defining a key

The [key] tag defines an allowed key that can occur in the current context. It supports the following keys:

  • name: The name of the key. (Version 1.15.0 and later only) Supports glob syntax, allowing a single [key] definition to match multiple actual keys.
  • type: The type of the key. Must reference a valid type defined elsewhere in the document. (Version 1.15.0 and later only) This can also be a comma-separated list of types, in which case the key value may match any one of the referenced types.
  • mandatory: If set to true, this key is required, and an error will be raised if it is missing.
  • default: Contains the default value for this key. Note that this must match the key's type. Mutually exclusive with mandatory.
  • deprecated: (Version 1.15.0 and later only) Set to true to mark the key as deprecated. A warning will be issued if it is used.
This page was last edited on 9 March 2019, at 18:41.