====== VCI update on Virtual Cast 1.5.4a ======
* Implemented message system
----
===== vci.message.Emit =====
* Sends a message
* The message will be sent to all VCIs of all users including the sender itself.
function onUse(self)
-- Message name: MSG_NAME
-- Content of the message: 1
vci.message.Emit('MSG_NAME', 1)
end
===== vci.message.On =====
* Receives a message
* The message can be received by the same VCI that sent the message or the other VCIs.
* Receives an Emit message with the first argument that matches the first argument of the On.
The receiving function receives 3 arguments.
* 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 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)
end
vci.message.On('MSG_NAME', onMessage)
===== About this feature =====
* This is mainly intended for sending messages from one VCI to another
* For example, creating a switch VCI and a bomb VCI separately.
* In the future, VCI will be able to receive messages from the system (Planned for future version up)
The difference between the shared variable and the message
* Shared variable does not have the function to clear all values.
* As the holder of the shared variable is unknown, it is hard to decide if it's ok to delete them all or not.
* It is hard to give variable names that are unique to each item
* What if multiple users spawned same items?
* Message is one-way and values are not saved (When a user joins a studio in the middle of a session, the messages from the past will not be applied)
* Almost the same feature can be implemented by combining the item variable `vci.state` and the message system.
* Item variables can be cleared by deleting the item and re-spawning it