ユーザ用ツール

サイト用ツール


この翻訳は元のページよりも更新日が古く、内容が古い可能性があります。 変更点を参照して下さい。
Language:

サイドバー

en:vci:script:reference:message

vci.message

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.
It is handled differently from shared variables.
VCI update with Virtual Cast 1.5.4a

  • Messages are only processed by the players present at the time of the message submission.
  • (It is different from shared variables which can have their information shared with “set”, even with the player that entered the room later)
  • A feature to receive messages from the system is planned for future release.

List of functions

Emit()

  • Sends a message
  • The message will be sent to all VCIs of all users including the sender itself.

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.
  • Passes the received message to the function in the second argument.
  • The On must be declared after the receiving function specified in the second argument. Declaring On before the receiving function will result in an error.

Receiver function

  • Receives three 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.

Example

Transmitter

send.lua
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

get.lua
local receiver = vci.assets.GetSubItem("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.


Another example

en/vci/script/reference/message.txt · 最終更新: 2019/07/01 17:52 by h-eguchi

ページ用ツール