Skip to content

Multiplayer quick reference⚓︎

Check out full tutorial here

There are 3 three ways to synchronize in the Massive Loop.

Synchronized Objects⚓︎

You can simply attach a LuaScript component to any object and select Synchronize Transform to synchronize the position, rotation, or scale of an object through the network. An example use case for this is a ball that players can play with.

Adding this property to an object is pretty simple.

Select the desired object from the scene hierarchy, and in the inspector panel, click the Add Component button.

From the menu select MassiveLoop > LuaScript.

In the newly added LuaScript component, select the synchronized Transform check box and select at least one of the properties to be synchronized.

Network events⚓︎

Adding an "Event Handler" for purpose of using it as a network event is exactly the same. As a matter of fact, an event handler can be used for both purposes. Internally and over the network.

Given the handlers exist in the intended target, we can call a different Invoke method to raise the event in specified targets.

In any over the network event, we have the following actors:

  • Sender: The client which raises the event (calls the Invoke method).
  • Receiver(s): The client in which the handlers are raised (Invoked upon).
    • Master: The master client.
    • Other Players: All players, except the sender.
    • All Players : All players, including the sender.

From Lua Events API Reference, we have following four invoke method:

  1. InvokeForAll(eventName)
    This method invokes the handlers that are attached to given eventName in all players. This includes the sender as well.

  2. invokeForOthers(eventName)
    Similar to invokeForAll() but this time the sender won't receive the event.

  3. invokeForMaster(eventName)
    This method invokes the handlers in Master Client and the sender.

  4. invokeForMasterOnly(eventName)
    This method invokes the handler only in the master client. Excluding the sender.

Synchronized Variables⚓︎

Synchronized variables stored in all clients and any change to them (from any player) will propagate to all players.

Best practices⚓︎

  • Objects:
    • Keep the number of synchronized objects as low as possible.
  • Events:
    • Avoid sending large variables with events.
    • Avoid raising too many events all at once.
    • Send events to proper target.
    • Try not to send variables with events.
  • Synchronized Variables:
    • Try synchronizing basic types.
    • Avoid synchronizing complex objects or arrays.