You can send a message from one VCI to another VCI, using it as a mean of communication between VCIs.
This feature allows you to control a VCI from a VCI.
There is a similar feature that called Global Sync Variable. For more information about the use of messages and Global Sync Variable, please refer to here.
Transmitter
function onUse(self) -- The first argument is the type of the message, the second argument is the content of the message -- In this example, specified a message that makes the receiving SubItem jump and value that determines the strength of that jump vci.message.Emit("message_jump",3000) end
Receiver
local receiver = vci.assets.GetTransform("Cube") -- sender: Information about the sender (set by the system) -- name: The name of the message. The first argument of Emit function. -- message: Content of the message. The second argument of Emit function. function Jump(sender, name, message) for k, v in pairs(sender) do print(k .. ":" .. v) end -- "name" contains type of the message, "message" contains content of the message print(name) print(message) -- Make the SubItem jump with the strength specified by the message receiver.AddForce(message*receiver.GetUp()) end -- When a ''vci.message.Emit'' with its message name "message_jump" is executed in the studio, the Jump function is called vci.message.On("message_jump", Jump)
What does the transmitter do?
Just send the desired message by executing Emit().
Of course, you have to decide in advance what messages to use to communicate with the receiver.
What does the receiver do?
1. Register the type of message to receive with vci.message.On()
.
When a message is sent by Emit(), you can receive a message that is registered with On().
2. In this example, the message received is passed to Jump().
The content of the message is given to Jump() as arguments.
3. The content of the Jump function's argument is the message.
So, by changing the message sent from the transmitter, you can change the behavior of the receiving VCI.