Message
How to define and register a message
Messages are predefined user actions that can be submitted to Cardinal and handled within a system. A message is the primary way of representing possible user actions in the game. After a message is processed within a tick, it returns a Reply
payload that can be read by the game client.
In Cardinal, messages are defined using a pair of Go structs representing a Message
and a Reply
.
Example:
- An
AttackPlayerMsg
message may contain theTargetNickname
of the player you want to attack. - A
MoveMsg
message may contain theDirection
andDistance
of the move.
Defining Messages
By convention, messages are defined in the msg
directory, with each message definition in its own separate file.
You can easily create a new message and register it to the world by following these steps:
Define the message and reply struct
A message request and and its reply are defined as a Go structs.
Register the message in the world
Messages must be registered in the world before they can be used. This is done by calling the RegisterMessage
function.
Message Options
EVM Support
Messages can be submitted by EVM smart contracts by using the WithMsgEVMSupport
option when you register your messages. This will generate the ABI types necessary for interactions with smart contracts.
Not all Go types are supported for the fields in your message structs when using this option. See EVM+ Message and Query to learn more.