1.14.22 - Door

A door is an obstacle that can be opened by Lua, and optionally by the hero under some conditions.

This type of map entity can be declared in the map data file. It can also be created dynamically with map:create_door().

Overview

A door may have four states: open, closed, opening or closing. States opening and closing are transitional states used to play a door opening or closing animation on the door's sprite. The sprite of a door must define animations "open" and "closed". Animations "opening" and "closing" are optional: if they don't exist, the door won't use states opening and closing. If they exist, be aware that after you call a function like map:open_doors(), your door will first be in state opening (for the duration of its sprite "opening" animation), and only after that, will get in state open. In other words, door:is_open() does not return true as soon as you open the door, unless the sprite has no animation "opening".

Doors often work by pairs. Indeed, when you have two adjacent rooms on the same map, you normally use two door entities. They can be linked by setting a common prefix to their name. Then, you can use map:open_doors() and map:close_doors() to handle both of them at the same time more easily. Additionaly, dynamic tiles whose names also have this prefix and end by _open or _closed are automatically enabled or disabled, respectively. This helps a lot to make tiles follow harmoniously the state of doors. See map:open_doors() for more information about these mechanisms.

A door may be opened by one of the following methods:

For doors whose opening method is "interaction_if_savegame_variable" or "interaction_if_item", you can specify which savegame variable or equipment item is required. You can also choose whether opening the door should consume the savegame variable of equipment item that was required.

Methods inherited from map entity

Doors are particular map entities. Therefore, they inherit all methods from the type map entity.

See Methods of all entity types to know these methods.

Methods of the type door

The following methods are specific to doors.

door:is_open()

Returns whether this door is open.

door:is_opening()

Returns whether this door is being opened.

door:is_closed()

Returns whether this door is closed.

door:is_closing()

Returns whether this door is being closed.

Events inherited from map entity

Events are callback methods automatically called by the engine if you define them.

Doors are particular map entities. Therefore, they inherit all events from the type map entity.

See Events of all entity types to know these events.

Events of the type door

The following events are specific to doors.

door:on_opened()

Called when this door starts being opened.

door:on_closed()

Called when this door starts being closed.