# wl¶

## Module Classes¶

### Game¶

class wl.Game

Child of: wl.bases.EditorGameBase

The root class to access the game internals. You can construct as many instances of this class as you like, but they all will access the one game currently running.

real_speed
(RO) The speed that the current game is running at in ms.

For example, for game speed = 2x, this returns 2000.

time

(RO) The absolute time elapsed since the game was started in milliseconds.

desired_speed

(RW) Sets the desired speed of the game in ms per real second, so a speed of 2000 means the game runs at 2x speed. Note that this will not work in network games as expected.

allow_saving

(RW) Disable or enable saving. When you show off UI features in a tutorial or scenario, you have to disallow saving because UI elements can not be saved and therefore reloading a game saved in the meantime would crash the game.

type

(RO) One string out of ‘undefined’, ‘singleplayer’, ‘netclient’, ‘nethost’, ‘replay’, describing the type of game that is played.

launch_coroutine(func[, when = now])

Hands a Lua coroutine object over to widelands for execution. The object must have been created via coroutine.create(). The coroutine is expected to coroutine.yield() at regular intervals with the absolute game time on which the function should be awakened again. You should also have a look at core.cr.

Parameters
• func (thread) – coroutine object to run

• when (integer) – absolute time when this coroutine should run

Returns

nil

save(name)

Requests a savegame. Note that the actual save will be performed later, and that you have no control over any error that may happen by then currently.

Parameters

name (string) – name of save game, as if entered in the save dialog. If this game already exists, it will be silently overwritten. If empty, the autosave name will be used.

Returns

nil

### Editor¶

class wl.Editor

Child of: wl.bases.EditorGameBase

The Editor object; it is the correspondence of the wl.Game that is used in a Game.

### World¶

class wl.World

This offers access to the objects in the Widelands world and allows to add new objects. On how to build the world and adding new objects to it, see Scripts for World.

immovable_descriptions

Returns a list of all the immovables that are available in the world.

(RO) a list of LuaImmovableDescription objects

terrain_descriptions

Returns a list of all the terrains that are available in the world.

(RO) a list of LuaTerrainDescription objects

### Tribes¶

class wl.Tribes

This offers access to the objects available for the tribes and allows to add new objects. See Scripts for Tribes for detailed documentation.

new_constructionsite_type{table}

Adds a new constructionsite building type. Takes a single argument, a table with the descriptions. See Construction Sites for detailed documentation.

Returns

0

new_dismantlesite_type{table}

Adds a new disnamtlesite building type. Takes a single argument, a table with the descriptions. See Dismantle Sites for detailed documentation.

Returns

0

new_militarysite_type{table}

Adds a new militarysite building type. Takes a single argument, a table with the descriptions. See Military Sites for detailed documentation.

Returns

0

new_productionsite_type{table}

Adds a new productionsite building type. Takes a single argument, a table with the descriptions. See Production Sites for detailed documentation.

Returns

0

new_trainingsite_type{table}

Adds a new trainingsite building type. Takes a single argument, a table with the descriptions. See Training Sites for detailed documentation.

Returns

0

new_warehouse_type{table}

Adds a new warehouse building type. Takes a single argument, a table with the descriptions. See Headquarters, Warehouses and Ports for detailed documentation.

Returns

0

new_immovable_type{table}

Adds a new immovable type. Takes a single argument, a table with the descriptions. See Immovables for detailed documentation.

Returns

0

new_ship_type{table}

Adds a new ship type. Takes a single argument, a table with the descriptions. See Ships for detailed documentation.

Returns

0

new_ware_type{table}

Adds a new ware type. Takes a single argument, a table with the descriptions. See Wares for detailed documentation.

Returns

0

new_carrier_type{table}

Adds a new carrier worker type. Takes a single argument, a table with the descriptions. See the files in tribes/ for usage examples.

Returns

nil

new_soldier_type{table}

Adds a new soldier worker type. Takes a single argument, a table with the descriptions. See the files in tribes/ for usage examples.

Returns

nil

new_worker_type{table}

Adds a new worker type. Takes a single argument, a table with the descriptions. See the files in tribes/ for usage examples.

Returns

nil

new_tribe{table}

Adds a new tribe. Takes a single argument, a table with the descriptions. See <tribename>.lua for detailed documentation.

Returns

0

add_custom_building{table}

Adds a custom building to a tribe, e.g. for use in a scenario. The building must already be known to the tribes and should be defined in the map:scripting/tribes/ directory.

Note: This function has to be called from map:scripting/tribes/init.lua.

The table has the following entries:

tribename

Mandatory. The name of the tribe that this building will be added to.

buildingname

Mandatory. The name of the building to be added to the tribe.

Returns

0