CorsixTH Lua Documentation

Entity Class

Abstraction for visible gameplay things which sit somewhere on the map.

Declared on: line 21 of Lua/entity.lua.
Subclasses: Humanoid, Litter, Object, Rat

Method Index

Member Index

function Entity:Entity(animation)

Parameters:

NameTypeDescription
animation ? ?

Declared on: line 29 of Lua/entity.lua.

function Entity:_tick()

Inner tick function that will skip every other tick when slow_animation is set.

Declared on: line 190 of Lua/entity.lua.

function Entity:afterLoad(old, new)

Stub to be extended in subclasses, if needed.

Parameters:

NameTypeDescription
old ? ?
new ? ?

Declared on: line 347 of Lua/entity.lua.

function Entity:clearDynamicInfo()

Completely clears the dynamic info.

Declared on: line 342 of Lua/entity.lua.

function Entity:eraseObject()

Stub to be extended in subclasses, if needed.

Declared on: line 361 of Lua/entity.lua.

function Entity:getDrawingLayer()

Returns the drawing layer for this particular entity. Should be overridden in derived classes. The drawing layer specifies the order in which object are drawn in a tile (the object with the smallest layer is drawn first). Litter should have layer 0, side objects to the north layer 1, side objects to the west layer 2, normal objects should have layers between 3 and 7, east side object should have layer 8 and south side objects layer 9.

Declared on: line 371 of Lua/entity.lua.

function Entity:getDynamicInfo()

Returns a table of hover info about an object.

Declared on: line 324 of Lua/entity.lua.

function Entity:getTile()

Get the map tile which the entity is on.

Declared on: line 142 of Lua/entity.lua.

function Entity:notifyNewObject(id)

Notify the entity of a new object.

Parameters:

NameTypeDescription
id ? Name of the new object. TODO Currently only used for benches placed nearby. TODO Maybe also pass the object tile coordinates?

Declared on: line 309 of Lua/entity.lua.

function Entity:notifyNewRoom(room)

Notify the entity that a new room was built.

Parameters:

NameTypeDescription
room Room The new room.

Declared on: line 316 of Lua/entity.lua.

function Entity:onDestroy()

Function which is called when the entity is to be permanently removed from the world.

Declared on: line 286 of Lua/entity.lua.

function Entity:onPickUp()

Function which is called when entity is picked up

Declared on: line 298 of Lua/entity.lua.

function Entity:playEntitySounds(name_pattern, min_silence_lengths, max_silence_lengths, num_silences)

Plays a sequence of related sounds at an entity while entity.playing_sounds_in_random_sequence = true. The silences between these sounds can either have randomly generated lengths between the min and max length parameters or they can all be a specified length by providing min and max tables with one value for the desired pause duration.

Parameters:

NameTypeDescription
name_pattern String example: LAVA00*.WAV
min_silence_lengths table the desired minimum silences length for the different tick rates, [3] = Normal
max_silence_lengths table the desired maximum silences length for the different tick rates, [3] = Normal
num_silences integer how many different silence lengths should be used, this can be a nil parameter. -

Declared on: line 66 of Lua/entity.lua.

function Entity:playSound(name, played_callback, played_callback_delay)

This plays a sound "at" the entity, meaning the sound will not be played if the entity is off-screen, and the volume will be quieter the further the entity is from the center of the screen. If this is not what you want then use UI:playSound instead.

Parameters:

NameTypeDescription
name string or integer The filename or ordinal of the sound to play.
played_callback function a optional parameter.
played_callback_delay integer a optional milliseconds parameter. --

Declared on: line 47 of Lua/entity.lua.

function Entity:setAnimation(animation, flags)

Set which animation is used to give the entity a visual appearance.

Until an entity is given an animation, it is invisible to the player. Note that some "animations" consist of a single frame, and hence the term animation is used both to mean things which are animated and things which are static.

Parameters:

NameTypeDescription
animation integer The ordinal into the main animation set
flags integer A combination of zero or more drawing flags to control the use of alternative palettes, transparency, and other similar settings. See `THDF_` values in `th_gfx.h` for the possible bit values.

Declared on: line 89 of Lua/entity.lua.

function Entity:setDynamicInfo(type, value)

Sets a piece of Dynamic_info. type could be 'text', 'progress' or 'dividers'

Parameters:

NameTypeDescription
type ? ?
value ? ?

Declared on: line 329 of Lua/entity.lua.

function Entity:setLayer(layer, id)

Set which parts of the animation to be displayed.

Each animation is made up of 13 layers, and generally has several different options for each layer. In the animation viewer tool, multiple options can be toggled on for each layer, however here only one option may be selected per layer.

Parameters:

NameTypeDescription
layer integer The layer to set (1 through 13).
id integer The option to display for the given layer.

Declared on: line 236 of Lua/entity.lua.

function Entity:setMood(mood_name, activate)

Parameters:

NameTypeDescription
mood_name ? ?
activate ? ?

Declared on: line 321 of Lua/entity.lua.

function Entity:setMoodInfo(new_mood)

Used to set a mood icon over the entity.

Parameters:

NameTypeDescription
new_mood ? ?

Declared on: line 269 of Lua/entity.lua.

function Entity:setPosition(x, y)

Set the pixel position of the entity within the current tile.

Parameters:

NameTypeDescription
x integer The 0-based X pixel offset from the default position.
y integer The 0-based Y pixel offset from the default position.

Declared on: line 157 of Lua/entity.lua.

function Entity:setSpeed(x, y)

Set the rate at which the entity pixel position changes

Parameters:

NameTypeDescription
x integer The X component of the speed in pixels per tick.
y integer The Y component of the speed in pixels per tick.

Declared on: line 166 of Lua/entity.lua.

function Entity:setTile(x, y)

Set the map tile which the entity is on.

Parameters:

NameTypeDescription
x integer The 1-based X coordinate of the tile.
y integer The 1-based Y coordinate of the tile.

Declared on: line 112 of Lua/entity.lua.

function Entity:setTilePositionSpeed(tx, ty, px, py, sx, sy)

Combined form of `setTile`, `setPosition`, and `setSpeed`

Parameters:

NameTypeDescription
tx integer The 1-based X coordinate of the tile.
ty integer The 1-based Y coordinate of the tile.
px integer The 0-based X pixel offset from the default position.
py integer The 0-based Y pixel offset from the default position.
sx integer The X component of the speed in pixels per tick.
sy integer The Y component of the speed in pixels per tick.

Declared on: line 175 of Lua/entity.lua.

function Entity:setTimer(tick_count, f)

Register a function (related to the entity) to be called at a later time.

Each `Entity` can have a single timer associated with it, and due to this limit of one, it is almost always the case that the currently active humanoid action is the only thing which calls `setTimer`. If self.slow_animation is set then all timers will be doubled as animation length will be doubled.

Parameters:

NameTypeDescription
tick_count integer If 0, then `f` will be called during the entity's next `tick`. If 1, then `f` will be called one tick after that, and so on.
f function Function which takes a single argument (the entity).

Declared on: line 250 of Lua/entity.lua.

function Entity:tick()

Function which is called once every tick, where a tick is the smallest unit of time in the game engine. Typically used to advance animations and similar recurring or long-duration tasks.

Declared on: line 203 of Lua/entity.lua.

function Entity:tickDay()

Function which is called at the end of each ingame day. Should be used to implement behaviours which happen regularly, but not as frequently as to need them in `tick`.

Declared on: line 303 of Lua/entity.lua.