Skip to main content

Entity

Description:

  A record type representing an entity for an ECS game system.

Class Object: Entity Class.

Inherits from: Object.

index

Type: Readonly Field.

Description:

  The index of the entity.

Signature:

const index: integer

oldValues

Type: Readonly Field.

Description:

  A syntax shortcut for accessing the old values of the entity's properties. The old values are values before last change of the component values of the Entity. Don't keep a reference to it for it is not an actual table.

Signature:

const oldValues: {string: Item}

destroy

Type: Function.

Description:

  A function that destroys the entity.

Signature:

destroy: function(self: Entity)

set

Type: Function.

Description:

  A function that sets a property of the entity to a given value. This function will trigger events for Observer objects.

Signature:

set: function(self: Entity, key: string, item: Item)

Parameters:

ParameterTypeDescription
keystringThe name of the property to set.
itemItemThe value to set the property to.

get

Type: Function.

Description:

  A function that retrieves the value of a property of the entity

Signature:

get: function(self: Entity, key: string): Item

Parameters:

ParameterTypeDescription
keystringThe name of the property to retrieve the value of.

Returns:

Return TypeDescription
ItemThe value of the specified property.

getOld

Type: Function.

Description:

  A function that retrieves the previous value of a property of the entity

Signature:

getOld: function(self: Entity, key: string): Item

Parameters:

ParameterTypeDescription
keystringThe name of the property to retrieve the previous value of.The old values are values before last change of the component values of the Entity.

Returns:

Return TypeDescription
ItemThe previous value of the specified property

__index

Type: Metamethod.

Description:

  A metamethod that retrieves the value of a property of the entity.

Signature:

metamethod __index: function(self: Entity, key: string): Item

Usage:

local valueX = entity.valueX

Parameters:

ParameterTypeDescription
keystringThe name of the property to retrieve the value of.

Returns:

Return TypeDescription
ItemThe value of the specified property.

__newindex

Type: Metamethod.

Description:

  A metamethod that sets the value of a property of the entity.

Signature:

metamethod __newindex: function(self: Entity, key: string, item: Item)

Usage:

entity.valueX = 123

Parameters:

ParameterTypeDescription
keystringThe name of the property to set.
itemItemThe value to set the property to.