LuaAPI/types

From The Battle for Wesnoth Wiki

Race

This represents a possible unit race. It has the following attributes:

  • race.description → translatable string

The description of the race, for showing to players.

The name of the race, for showing to players.

  • race.num_traits → number

The number of random traits given to units of this race.

  • race.ignore_global_traits → boolean

Whether this race can receive the global traits.

  • race.undead_variation → string

The variation to transform this race to if killed by a plague attack.

  • race.traits → trait list

The traits available to this race. Includes global traits if available. You can access specific traits by their ID, and the full trait definition is included.

  • race.male_name_gen → name generator
  • race.female_name_gen → name generator

The name generators for this race. These are callable userdatas that return a random name each time, equivalent to the one created by wesnoth.name_generator.

  • race.__cfg → config

The entire race definition as raw WML.

Unit Type

This represents a type of unit in the game, rather than a specific instance of a unit. It has the following attributes:

  • unit_type.name → translatable string

The name of the unit type, for displaying to the player.

  • unit_type.id → string

The unit's ID.

  • unit_type.race → string

The ID of the unit's race. To get the actual race object, use this to look it up in wesnoth.races.

  • unit_type.alignment → alignment

The unit's alignment.

  • unit_type.image → image string
  • unit_type.icon → image string
  • unit_type.profile → image string
  • unit_type.small_profile → image string

Various images used to represent the unit.

  • unit_type.max_hitpoints → number
  • unit_type.max_moves → number
  • unit_type.max_experience → number
  • unit_type.cost → number
  • unit_type.level → number
  • unit_type.recall_cost → number

Various stats of the unit type.

  • unit_type.advances_to → list of strings

A list of unit type IDs that this unit can advance to.

  • unit_type.advances_from → list of strings

A list of unit type IDs that can advance to this unit.

  • unit_type.traits → table

A table of the traits that this unit type can get. The key is the trait ID and the value is the trait's full definition as a config.

  • unit_type.abilities → list of strings

A list of abilities that this unit type possesses. This is only the abilities' IDs, not their full definition.

  • unit_type.attacks → attack list

A list of weapons that this unit type possesses. This list can be indexed as an array, but you can also look up an attack by its ID (name field). Each attack is a weapon userdata.

  • unit_type.variations → variation list

Returns a list of unit type userdata representing possible variations of this unit, including gender variations. You can look up specific variations by their ID. Male and female variations have the ID male or female.

  • unit_type.__cfg → config

Returns the full unit type definition as raw WML. This can be used if you need something that's not directly supported.

Weapon

This represents a single attack on a unit or unit type; it can also exist as an orphaned attack not attached to either a unit or unit type. It has the following attributes:

  • weapon.read_only → boolean

Indicates whether you can write to the attributes of this attack. It will be true when getting an attack from a unit type userdata.

  • weapon.description ↔ translatable string

The attack's name, for displaying to the player.

  • weapon.name ↔ string

The attack's ID.

  • weapon.type ↔ string

The attack's damage type.

  • weapon.icon ↔ image string

The attack's icon.

  • weapon.damage ↔ number
  • weapon.range ↔ string
  • weapon.number ↔ number
  • weapon.movement_used ↔ number
  • (Version 1.17.13 and later only) weapon.attacks_used ↔ number

Basic stats of the attack.

  • weapon.attack_weight ↔ number
  • weapon.defense_weight ↔ number

The attack's weighting values.

  • weapon.accuracy ↔ number
  • weapon.parry ↔ number

The defense modifications of the attack.

The attack's distance requirement between attacker and defender.

  • weapon.specials ↔ list of configs

The special abilities of this attack.

  • weapon:matches(filter) → boolean

Tests if this attack matches the given StandardWeaponFilter.

  • weapon.__cfg → config

The entire attack as raw WML

See Also

  • translatable strings - a string that will be translated by the engine.
  • vconfig - a WML object that automatically substitutes variables on the fly.
  • unit - represents a reference to Wesnoth unit on the map, on the recall list, or private to Lua.
  • side - represents a single side (player) in the game.
  • widget - represents a GUI2 widget.
  • map - represents the game map.
  • hex - represents a single hex on the map.
This page was last edited on 1 March 2025, at 14:29.