SideEffectMessage

local SideEffectMessage = require("encompass").SideEffectMessage

A SideEffectMessage is a kind of message that is consumed by SideEffecters to modify game state that isn’t captured by any particular Entities or Components. For example, if your game has multiple top-level states with separate Worlds, changing the top-level state would be a side effect.

Side effects should be used as an absolute last resort. Use them only if there is no way to produce the behavior with other types of Engines.

Function Reference

SideEffectMessage.define(name, required_field_types, optional_field_types)
Arguments:
  • name (string) – The name of the SideEffectMessage 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 SideEffectMessage 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 SideEffectMessage prototype.