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 themsg
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:
1
Define the message and reply struct
A message request and and its reply are defined as a Go structs.
/msg/attack_player.go
2
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.main.go
Message Options
EVM Support
Messages can be submitted by EVM smart contracts by using theWithMsgEVMSupport
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.
Common Message Patterns
Iterating over messages
/system/attack.go