-
Notifications
You must be signed in to change notification settings - Fork 5
Replicated Functions
RPC calls (or replicated function calls) allow the system to invoke a code fragment on a remote target. The system does not permit executing raw code strings.
RPC calls, as a member of the replication system, cannot be used outside of classes that subclass Replicable
First we must import a few classes from the network library
from network.descriptors import TypeFlag
from network.enums import NetmodesNow we create a typical function
def print_string(string):
print(string)Let's tell the library what type of data string is
def print_string(string: TypeFlag(str)):
print(string)And let's ask it to send this to the server, or execute it directly if called on the server
def print_string(string: TypeFlag(str)) -> Netmodes.server:
print(string)We might also want to ensure the server receives this
from network.decorators import reliable
@reliable
def print_string(string: TypeFlag(str)) -> Netmodes.server:
print(string)We can tell the network system how large a string we are sending, which is assumed 255 characters unless we specify otherwise. This helps save bandwidth, but it must always be greater than or equal to the maximum characters the string will consist of
def print_string(string: TypeFlag(str, max_length=2048)) -> Netmodes.server:
print(string)Sometimes, you may wish to inherit the Replicated Function, but change a parameter in the type information for an argument. We use the MarkAttribute decorator (belongs in the same module as the descriptors).
This will look for an attribute named message_length in every class which has this function definition (including the implementing class).
from network.descriptors import MarkAttribute
length_marker = MarkAttribute("message_length")
def print_string(string: TypeFlag(str, max_length=length_marker)) -> Netmodes.server:
print(string)Invoking an RPC call on the same network target that it is defined for will call the function locally. Otherwise, the arguments of the function are packed and sent to the remote peer.
There are some criteria that govern if the latter step takes place, or whether the function is simply dropped.
If the network object that the method is executed for is not a child of the connection network object, the call is not packaged.
If the object doesn't have authority to execute the function, it will not be called. Additionally, there are some notes on behaviour:
If an error occurs whilst executing the function, an error message is printed on the side of execution and the program continues normally. If the function defines return arguments, they are simply ignored.
#Network
##Replication Overview
##Serialisation Data handlers
##Communication Messaging
#Game Framework ##Bindings Creating bindings