ComponentMessage¶
local ComponentMessage = require("encompass").ComponentMessage
A ComponentMessage is a kind of message that is consumed by ComponentModifiers to modify a particular component.
A ComponentMessage implicitly contains a component
key, but
it can and should be overwritten with a more specific Component subtype.
Function Reference¶
-
ComponentMessage.
define
(name, required_field_types, optional_field_types)¶ Arguments: - name (string) – The name of the ComponentMessage prototype.
- required_field_types (table) – A table where the keys are field names and the values are types. If one of these fields is missing when the ComponentMessage is instantiated, or a field is passed to the message with an incorrect type, an error is thrown.
- optional_field_types (table) – A table where the keys are field names and the values are types. If a field is passed to the message with an incorrect type, an error is thrown.
Returns: A new ComponentMessage prototype.
Example:
local ComponentMessage = require('encompass').ComponentMessage
local TransformComponent = require('game.components.transform')
return ComponentMessage.define('MotionMessage', {
component = TransformComponent,
x_velocity = 'number',
y_velocity = 'number',
angular_velocity = 'number',
instant_linear = 'boolean',
instant_angular = 'boolean'
})