RPC - stingray.RPC namespace reference - Stingray Lua API Reference

stingray.RPC namespace reference

Description

The RPC object is used to make remote calls to other connected peers in a networked game.

The functions available in this class are determined by the messages object that you set up in the .network_config data file that you use to initialize the Network. In order to send a message of a particular type, you call an equivalent function on the RPC object. The message is sent to the remote peer. Then, when the Network.update() function is called on the remote peer, a function with the same name is transparently invoked on the callback handler object passed to Network.update().

For example, the .network_config file could set up a message type called hello_world as follows:

messages = {
hello_world = {}
}

In this case, you could send that message to a peer by calling the hello_world() function of the RPC object:

stingray.RPC.hello_world(peer_ID)

When the remote peer calls:

stingray.Network.update(delta_time, my_callback_object)

the engine will automatically call my_callback_object:hello_world().

For complete details, see the networking documentation.