LuaAPI/old
Functionalities of the game engine are available through the functions contained in the wesnoth global table. Some of these functions return proxy tables. Writes to fields marked "read-only" 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.
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 wesnoth.require.
helper = wesnoth.require "lua/helper.lua"
Contents
WML variables
- wesnoth.get_variable
- wesnoth.set_variable
- wesnoth.get_all_vars (Version 1.13.0 and later only)
- wesnoth.wml_matches_filter (Version 1.13.8 and later only)
- helper.set_wml_var_metatable
- helper.get_child
- helper.get_nth_child (Version 1.13.2 and later only)
- helper.child_count (Version 1.13.2 and later only)
- helper.child_range
- helper.child_array (Version 1.13.2 and later only)
- helper.get_variable_array
- helper.get_variable_proxy_array
- helper.set_variable_array
Events and WML actions
- wesnoth.fire
- wesnoth.wml_actions
- wesnoth.wml_conditionals (Version 1.13.0 and later only)
- wesnoth.game_events
- wesnoth.persistent_tags (Version 1.13.12 and later only)
- wesnoth.fire_event
- wesnoth.fire_event_by_id (Version 1.13.6 and later only)
- wesnoth.add_event_handler (Version 1.13.0 and later only)
- wesnoth.remove_event_handler (Version 1.13.0 and later only)
- wesnoth.eval_conditional
- wesnoth.tovconfig
- helper.set_wml_action_metatable
- helper.wml_error
- helper.literal
- helper.parsed
- helper.shallow_literal
- helper.shallow_parsed
- on_event.on_event (Version 1.13.6 and later only)
User interface
- wesnoth.get_viewing_side (Version 1.13.? and later only)
- wesnoth.message
- wesnoth.clear_messages
- wesnoth.textdomain
- wesnoth.delay
- wesnoth.float_label
- wesnoth.select_hex
- wesnoth.select_unit
- wesnoth.highlight_hex
- wesnoth.deselect_hex (Version 1.13.2 and later only)
- wesnoth.scroll_to_tile
- wesnoth.lock_view
- wesnoth.view_locked
- wesnoth.play_sound
- wesnoth.set_music
- wesnoth.music_list (Version 1.13.8 and later only)
- wesnoth.sound_volume (Version 1.13.8 and later only)
- wesnoth.show_message_dialog (Version 1.13.2 and later only)
- wesnoth.show_popup_dialog (Version 1.13.2 and later only)
- wesnoth.show_story (Version 1.13.8 and later only)
- wesnoth.show_message_box (Version 1.13.8 and later only)
- wesnoth.show_menu (Version 1.13.8 and later only)
- wesnoth.alert (Version 1.13.8 and later only)
- wesnoth.confirm (Version 1.13.8 and later only)
- wesnoth.show_dialog
- wesnoth.set_dialog_value
- wesnoth.get_dialog_value
- wesnoth.set_dialog_active
- wesnoth.set_dialog_callback
- wesnoth.set_dialog_markup
- wesnoth.set_dialog_focus (Version 1.13.2 and later only)
- wesnoth.set_dialog_visible (Version 1.13.2 and later only)
- wesnoth.set_dialog_canvas
- wesnoth.add_dialog_tree_node (Version 1.13.0 and later only)
- wesnoth.remove_dialog_item (Version 1.13.1 and later only)
- wesnoth.get_displayed_unit
- wesnoth.theme_items
- helper.get_user_choice
- wesnoth.is_skipping_messages (Version 1.13.2 and later only)
- wesnoth.skip_messages (Version 1.13.2 and later only)
- wesnoth.log (Version 1.13.5 and later only)
- wesnoth.zoom (Version 1.13.8 and later only)
Map and terrains
- wesnoth.get_map_size
- wesnoth.get_terrain
- wesnoth.set_terrain
- wesnoth.get_terrain_info
- wesnoth.get_selected_tile
- wesnoth.get_locations
- wesnoth.get_villages
- wesnoth.match_location
- wesnoth.add_tile_overlay
- wesnoth.remove_tile_overlay
- wesnoth.add_fog (Version 1.13.5 and later only)
- wesnoth.remove_fog (Version 1.13.5 and later only)
- wesnoth.add_sound_source (Version 1.13.5 and later only)
- wesnoth.remove_sound_source (Version 1.13.5 and later only)
- wesnoth.get_sound_source (Version 1.13.5 and later only)
- wesnoth.map.get_direction (Version 1.13.8 and later only)
- wesnoth.map.get_relative_dir (Version 1.13.8 and later only)
- wesnoth.map.rotate_right_around_center (Version 1.13.8 and later only)
- wesnoth.map.get_adjacent_tiles (Version 1.13.8 and later only)
- wesnoth.map.tiles_adjacent (Version 1.13.8 and later only)
- wesnoth.map.distance_between (Version 1.13.8 and later only)
- wesnoth.label (Version 1.13.0 and later only)
- wesnoth.special_locations (Version 1.13.12 and later only)
- items.place_image
- items.place_halo
- items.remove
Time of day schedule
- wesnoth.get_time_of_day
- wesnoth.add_time_area (Version 1.13.0 and later only)
- wesnoth.remove_time_area (Version 1.13.0 and later only)
- wesnoth.get_max_liminal_bonus (Version 1.15.4 and later only)
Units
- wesnoth.get_units
- wesnoth.get_unit
- wesnoth.match_unit
- wesnoth.put_unit
- wesnoth.erase_unit (Version 1.13.2 and later only)
- wesnoth.get_recall_units
- wesnoth.put_recall_unit
- wesnoth.create_unit
- wesnoth.copy_unit
- wesnoth.extract_unit
- wesnoth.add_modification
- wesnoth.remove_modifications (Version 1.13.? and later only)
- wesnoth.unit_resistance
- wesnoth.unit_defense
- wesnoth.unit_movement_cost
- wesnoth.unit_vision_cost
- wesnoth.unit_jamming_cost
- wesnoth.unit_ability
- wesnoth.unit_types
- wesnoth.races
- wesnoth.get_traits
- wesnoth.advance_unit (Version 1.13.? and later only)
- wesnoth.add_known_unit (Version 1.13.? and later only)
- wesnoth.simulate_combat
- wesnoth.transform_unit
- wesnoth.create_animator (Version 1.13.7 and later only)
- wesnoth.effects (Version 1.13.2 and later only)
Sides
- wesnoth.sides
- wesnoth.get_sides
- wesnoth.get_village_owner
- wesnoth.set_village_owner
- wesnoth.is_enemy
- wesnoth.match_side
- wesnoth.get_starting_location
- wesnoth.set_side_id (Version 1.13.7 and later only)
- wesnoth.place_shroud (Version 1.13.7 and later only)
- wesnoth.remove_shroud (Version 1.13.7 and later only)
- wesnoth.is_fogged (Version 1.13.7 and later only)
- wesnoth.is_shrouded (Version 1.13.7 and later only)
- wesnoth.switch_ai (Version 1.13.7 and later only)
- wesnoth.append_ai (Version 1.13.7 and later only)
- wesnoth.add_ai_component (Version 1.13.7 and later only)
- wesnoth.change_ai_component (Version 1.13.7 and later only)
- wesnoth.delete_ai_component (Version 1.13.7 and later only)
- helper.all_teams
- helper.get_side_variable (Version 1.13.? and later only)
- helper.set_side_variable (Version 1.13.? and later only)
Pathfinder
- wesnoth.find_path
- wesnoth.find_vacant_tile
- wesnoth.find_reach
- wesnoth.find_cost_map
- helper.distance_between
- helper.adjacent_tiles
Lua files
- wesnoth.dofile
- wesnoth.require
- wesnoth.have_file (Version 1.13.5 and later only)
- wesnoth.read_file (Version 1.13.5 and later only)
Location sets
- location_set.create
- location_set.of_pairs
- location_set.of_wml_var
- location_set:empty
- location_set:size
- location_set:clear
- location_set:get
- location_set:insert
- location_set:remove
- location_set:of_pairs
- location_set:of_wml_var
- location_set:to_pairs
- location_set:to_stable_pairs
- location_set:to_wml_var
- location_set:union
- location_set:inter
- location_set:iter
- location_set:stable_iter
- location_set:filter
- location_set:union_merge
- location_set:inter_merge
Miscellaneous
- wesnoth.game_config
- wesnoth.get_era
- wesnoth.current
- wesnoth.synchronize_choice
- wesnoth.synchronize_choices (Version 1.13.? and later only)
- wesnoth.unsynced (Version 1.13.? and later only)
- wesnoth.get_image_size
- wesnoth.compare_versions
- wesnoth.have_file
- wesnoth.debug
- wesnoth.get_time_stamp
- wesnoth.random (Version 1.13.2 and later only)
- wesnoth.eval_formula (Version 1.13.5 and later only)
- wesnoth.compile_formula (Version 1.13.5 and later only)
- wesnoth.name_generator (Version 1.13.5 and later only)
- wesnoth.set_next_scenario (Version 1.13.5 and later only)
- wesnoth.format (Version 1.13.8 and later only)
- wesnoth.format_conjunct_list (Version 1.13.8 and later only)
- wesnoth.format_disjunct_list (Version 1.13.8 and later only)
- wesnoth.end_turn (Version 1.13.? and later only)
- wml.tag
- helper.modify_unit
- helper.move_unit_fake
- helper.rand
- helper.round
- helper.shuffle
Functions that should not be used
If you take a look at Wesnoth's own lua files, you might find some undocumented functions use in the implementations of WML tags. Where possible, you should avoid using them, as they might be changed or removed with no compatibility for further releases. Instead, use the corresponding wml tags (in lua you can use wesnoth.wml_actions.tag_name(cfg), though keep in mind that this won't substitute variables in the config).
If uncertain whether an undocumented feature is safe to use, ask on the forums, Discord, or IRC. It may turn out that someone simply forgot to add it to the wiki.
- wesnoth.redraw
- wesnoth.set_menu_item
- wesnoth.clear_menu_item
- wesnoth.modify_ai
- wesnoth.print
- wesnoth.end_level