====== Exchange variables between multiple VCIs ======
=== Example data ===
Transmitter: https://virtualcast.jp/products/6bed6503ff44d229df6225ff45534fd7e1f04b1d307d8c319fea7899d14bf7f2
Receiver: https://virtualcast.jp/products/84144a282ddc1eb0be1de580cb69357b7d602db74c430e9b5da1f432a984ee4f
=== Unitypackage ===
{{ vci:sample:sample_advanced:tutorial_message_send.zip |}}
From VCI v0.17, vci.message is implemented which allows transmission and reception of messages in VCI.\\
This allows for the exchange of variables between multiple VCIs.
{{:en:vci:sample:message:tutorial_message_send.png?direct&600|}}
In this example, we will create two VCIs, transmitter and receiver, to demonstrate the communication of messages.
onUsing the transmitter VCI will send a message, which triggers a process in the receiving side if the set condition is met.\\
In this example, the receiving cylinder VCI will jump with upward velocity when it receives a message.
For the detailed information on vci.message, refer to:\\
[[vci/updatelog/1.5.4a]]
function onUse(self)
-- Message name: MSG_NAME
-- Content of the message: 1
vci.message.Emit("send_box_state","addforce_on")
end
function onUnuse(use)
-- Message name: MSG_NAME
-- Content of the message: 1
vci.message.Emit("send_box_state","addforce_off")
end
local sub = vci.assets.GetTransform("get")
function onMessage(sender, name, message)
-- The sender is in a table structure The information of the VCI that executed the vci.message.Emit function
-- {
-- type: "vci"
-- name: "name of the vci"
-- }
-- In the future, the sender will have new messages implemented
for k, v in pairs(sender) do
print(k .. ":" .. v)
end
print(name)
print(message)
if name=="send_box_state" and message=="addforce_on" then
print("forceon")
sub.AddForce (1000*sub.GetUp())
end
end
-- When ''vci.message.Emit'' is executed in studio, the onMessage function is called
vci.message.On("send_box_state", onMessage)