Class MessageType

An instance of a MessageType represents a single message type in the Kanzi message system. A message type exists throughout the lifetime of an application.

Kanzi Lua API allows you to work with existing message types. Most of the Kanzi message types are present in the Kanzi Lua API and you can use them in you scripts.

Example
-- Create an instance of the message arguments for the message type.
local arguments = ParallelActivityHost2D.DeactivateActivityMessageMessage:newMessageArguments()
arguments:setActivationPathProperty(".")
-- Locate the target node.
local targetNode = contextNode:lookupNode("Activity2D")
if targetNode ~= nil then
    -- Dispatch message.
    targetNode:dispatchMessage(ParallelActivityHost2D.DeactivateActivityMessageMessage, arguments)
end

To create an instance of MessageType for the custom message type from your project, see the MessageType.new() function.

Synopsis

Methods
new()

Creates an instance of an existing MessageType

newMessageArguments()

Creates an instance of the specific MessageArguments class for this message

MessageType:new(name, messageArgumentsClass)

Creates an instance of an existing MessageType. Use this function to create an instance of the custom message type from your project. You can use this function only once and store the result in a global variable.

Example
-- Define a MessageArguments class to use with the message.
CustomMessageArguments = MessageArguments.createMessageArgumentsClass({
    CustomIntPropertyType = PropertyType:new("project.CustomIntPropertyType"),
    CustomStringPropertyType = PropertyType:new("project.CustomStringPropertyType")
})
-- Create a MessageType instance for the existing message type.
CustomMessage = MessageType:new("CustomMessage", CustomMessageArguments)

The second parameter is optional. It allows you to link the message with the message arguments class, so you can later use MessageType.newMessageArguments() API to create a new instance of custom MessageArguments class for this message. If not specified, the MessageType.newMessageArguments() returns an instance of the basic MessageArguments class.

Parameters
name (string)

The name of the existing MessageType.

messageArgumentsClass (MessageArguments or nil)

An optional MessageArguments-derived class that describes the message arguments for this message.

Return Values
(MessageType)

A new instance of MessageType.

MessageType:newMessageArguments()

Creates an instance of the specific MessageArguments class for this message.

Example
-- Create an instance of the message arguments specific for this message.
local arguments = CustomMessage:newMessageArguments()
arguments:setCustomIntPropertyType(42)
arguments:setCustomStringPropertyType("Hello Lua world")
-- Dispatch the message.
contextNode:dispatchMessage(CustomMessage, arguments)
Return Values
(MessageArguments)

An instance of the MessageArguments-derived class that describes the message arguments for this message.