Skip to content

Replecs


Creates a new ReplecsLib. This contains both the server and client replicators in one object and provides methods to interact with both of them at the same time.

function Replecs.create(world: jecs.World?): ReplecsLib
  • world: The world to use for the replicators. Can also be provided when initing the replicator.

Creates a new server replicator.

function Replecs.create_server(world: jecs.World?): Replecs.Server
  • world: The world to use for the replicators. Can also be provided when initing the replicator.

Creates a new client replicator.

function Replecs.create_client(world: jecs.World?): Replecs.Client
  • world: The world to use for the replicators. Can also be provided when initing the replicator.

Creates a new handler for parsing custom entity ids.

function Replecs.create_custom_id(
identifier: string,
handler: ((ctx: HandleContext) -> Entity?)?
): CustomId
  • identifier: A string that will be used to identify the custom id when gets through the network. Must be the same in both the server and client.
  • handler: A function handler that will pass use the HandleContext to create or return the entity. Optionally, the handler can be ommited and set later with customid:handler(handler)

Container for both the server and client replicators.

type ReplecsLib = {
server: Replecs.Server?,
client: Replecs.Client?,
after_replication: (self: ReplecsLib, callback: () -> ()) -> (),
register_custom_id: (self: ReplecsLib, custom_id: CustomId) -> (),
}
  • server: The server replicator, nil in the client.
  • client: The client replicator, nil in the server.
  • after_replication(): Registers a callback to be called after the replication has finished.
    If not replication is in progress, the callback will be called immediately. If this is called in the server, the callback will always be called immediately.
    • Arguments
      • callback: The callback to be called.

  • register_custom_id(): Calls register_custom_id on the server and/or client replicators.
    • Arguments
      • custom_id: The custom id to register.