Difference between revisions of "LuaWML/Sides"

From The Battle for Wesnoth Wiki
m (improved documentation of is_enemy)
(Mentioned wesnoth.sides)
Line 17: Line 17:
  
 
The metatable of these proxy tables appears as '''"side"'''.
 
The metatable of these proxy tables appears as '''"side"'''.
 +
 +
==== wesnoth.sides ====
 +
 +
{{DevFeature1.9}}
 +
 +
This is not a function but a table indexed by side numbers. Its elements are the proxy tables returned by [[#wesnoth.get_side]].
 +
 +
local team = wesnoth.sides[1]
 +
team.gold = team.gold + 50
 +
wesnoth.message(string.format("%d sides", #wesnoth.sides))
  
 
==== wesnoth.get_village_owner ====
 
==== wesnoth.get_village_owner ====
Line 23: Line 33:
  
 
  local owned_by_side_1 = wesnoth.get_village_owner(12, 15) == 1
 
  local owned_by_side_1 = wesnoth.get_village_owner(12, 15) == 1
 +
 +
==== wesnoth.set_village_owner ====
 +
 +
Gives ownership of the village at the given location to the given side (or remove ownership if none).
 +
 +
wesnoth.set_village_owner(12, 15, 1)
  
 
==== wesnoth.is_enemy ====
 
==== wesnoth.is_enemy ====
 +
 
{{DevFeature1.9}}
 
{{DevFeature1.9}}
  
 
Returns true if side A is enemy of side B, false otherwise.
 
Returns true if side A is enemy of side B, false otherwise.
  
  local enemy_flag = wesnoth.is_enemy(1,3)
+
  local enemy_flag = wesnoth.is_enemy(1, 3)
 
 
==== wesnoth.set_village_owner ====
 
 
 
Gives ownership of the village at the given location to the given side (or remove ownership if none).
 
 
 
wesnoth.set_village_owner(12, 15, 1)
 
  
 
==== helper.all_teams ====
 
==== helper.all_teams ====

Revision as of 17:51, 18 July 2010

This page describes the LuaWML functions and helpers for handling sides and villages.

wesnoth.get_side

Returns the team with given number.

local team = wesnoth.get_side(1)
team.gold = team.gold + 50

Teams are proxy tables with the following fields:

  • gold, village_gold, base_income: integers (read/write)
  • total_income: integer (read only)
  • objectives, user_team_name: translatable strings (read/write)
  • objectives_changed: boolean (read/write)
  • team_name: string (read/write)
  • __cfg: WML table (dump)

The metatable of these proxy tables appears as "side".

wesnoth.sides

Template:DevFeature1.9

This is not a function but a table indexed by side numbers. Its elements are the proxy tables returned by #wesnoth.get_side.

local team = wesnoth.sides[1]
team.gold = team.gold + 50
wesnoth.message(string.format("%d sides", #wesnoth.sides))

wesnoth.get_village_owner

Returns the side that owns the village at the given location.

local owned_by_side_1 = wesnoth.get_village_owner(12, 15) == 1

wesnoth.set_village_owner

Gives ownership of the village at the given location to the given side (or remove ownership if none).

wesnoth.set_village_owner(12, 15, 1)

wesnoth.is_enemy

Template:DevFeature1.9

Returns true if side A is enemy of side B, false otherwise.

local enemy_flag = wesnoth.is_enemy(1, 3)

helper.all_teams

Returns an iterator over teams that can be used in a for-in loop.

for team in helper.all_teams() do team.gold = 200 end