Skip to content

Remote Call

In this example we create a button that will open up a dialog screen where the player can type a message.

This message will then show up in all other players in the room if they also have the same mod.

This works by using self.CallFunctionOnEveryone(), which calls a function on all players. There are other methods to call a function on "other players" excluding your own and another for calling a function on the host only.

function OnTemplate()
    -- Registers for the Start of the menu UI so we can create our pause button
    self.RegisterListener(Messager.StartGameUI,MakeUIButton)

    -- Make sure we can listen for function calls from the network.
    self.ListenForNetworkCalls()
end

function MakeUIButton()
    -- Adds a button to send our networked test call
    UI.AddMenuButton("Networked Msg",WriteMessage)
end

function WriteMessage()
   -- Displays a Dialog window with a input field to type our networked message.
   -- If the player presses Yes calls the function CallFunctionOnNetwork
   Dialog.ShowInputDialog("Networked Message", "Would you like to send a networked message?", "Write it here", 60, CallFunctionOnNetwork)
end

function CallFunctionOnNetwork(message)
    -- Calls the function on everyone in the room including us.
    self.CallFunctionOnEveryone('RemoteMessage',message)
end

function RemoteMessage(message)
    -- Shows the received message as a corner notification.
    UI.ShowCornerNotification(message)
end

Comments