Skip to content
ConcordConcordConcord

Component

A pure data container that is contained by a single entity.

If the concord folder is in the root directory of your game, you can import this module like so:

concord.component = require('concord.component')
Name Type Description
getName fun(self: Component): string
hasName fun(self: Component): boolean
serialize fun(self: Component): table|nil
deserialize fun(self: Component, data: table): nil
removed fun(self: Component, replaced: boolean): nil

Creates a new ComponentClass and registers it by name.

component = Component.new( name, populate )
Name Type Description
name string Unique name of the ComponentClass
populate fun(component: Component, …): nil Function that populates a Component with values
Name Type Description
component ComponentClass

Returns true if the Component has a name.

boolean = component:hasName()
Name Type Description
boolean boolean

Returns the name of the Component.

string = component:getName()
Name Type Description
string string

Callback for when the Component is removed or replaced in an Entity.

component:removed( replaced )
Name Type Description
replaced boolean True when the Component is being overwritten, false when it is being removed

Callback for when the Component is serialized as part of an Entity.

component:serialize()
Name Type Description
table|nil Serialized data, or nil to omit this Component

Callback for when the Component is deserialized from serialized data.

component:deserialize( data )
Name Type Description
data table Serialized data to copy onto this Component

Registered component type returned by Component.new / Component().

Extends Component.