Interplayer Message Exchange
Message Exchange refers to players directly sending messages to one another. This method allows you to implement all kinds of rule logic much more freely.
For example, in the ParaSpace's World Blue Hole, when players enter the dance hall and start dancing, they can release special dance postures using Inter-player Message Exchange: Player A starts dancing using a certain posture, then sends a message to other players. Upon receiving the message, other players then play the posture on their clients.
Send and Receive Messages
By using the ParaScript API, you can send messages to other players in the following ways:
ParaScript.SendMessageToOwner(string method, params object[] args) | Send messages to an owner. |
ParaScript.SendMessageToAll(string method, params object[] args) | Send messages to all players, including yourself. |
ParaScript.SendMessageToTarget(string method, ParaPlayer target, params object[] args) | Send messages to a certain player. |
In all of the above cases, the first parameter of a message is always a method. When receiving a message, the receiver automatically executes the function with the same name as the method in the message.
A variable parameter can be passed on to the method function as needed. The input parameter of the method function must be consistent with the variable parameter so that the variable parameter can be directly used in the function.
Currently, the following parameter types are supported: bool, byte, short, int, long, float, double, string.
You can click the URLs above to view specific parameter descriptions and examples.
Remote Call
ParaSpace also allows a player to directly invoke a certain function on another player's client. This is a more flexible way.
ParaScript.OwnerCall(string method, Action onFinish, params object[] args) | Invokes a certain function of an owner. |
ParaScript.TargetCall(string method, ParaPlayer target, Action onFinish, params object[] args) | Invokes a certain function of a player. |
Message Exchange vs. Synchronization Variable
You are probably aware that both message exchanges and synchronization variables are methods of inter-player communication.
Message exchanges can achieve exactly the same effect as a synchronization variable. However, the former requires far more code than the latter.
Message exchanges allow you to synchronize multiple parameters at the same time if necessary, whereas synchronization variables can only be synchronized one by one. Therefore, if you require a variety of data to help you make certain logical judgments, message exchanges will make that easier.
But what if a player joins your World after your message has been sent? That player will be able to obtain the latest value of the synchronization variable, but will not be able to receive the previously sent message.
Be sure that you fully understand the characteristics of both of these two communication methods before attempting to create you own World.
Updated about 2 years ago