ShareKeyedEntity entity,key$

Parameters

entity - an entity this copy built for itself, not one from the world file

key$ - a name, up to 128 characters, that matches it to the same entity on every other copy

Description

Shares an entity that every copy of a server room builds for itself, matched by a key.

A level your program builds from code - moving platforms, pushers, a swinging hammer - exists on every copy already, so there is nothing to spawn: each copy calls ShareKeyedEntity with the same key, such as "platform-3", and the server's copy is in charge. On the server the entity is shared and your code moves it. On each player's copy, its own entity with that key follows the server's from the moment the server shares it, whether you call ShareKeyedEntity before joining or after.

On a player's copy, don't move a keyed entity yourself while it follows: SharedEntityRemote(entity) is True then, so skip it in your movement code. A key the server never shares leaves the entity this copy's own, and when the server unshares it with UnshareEntity, it becomes this copy's own again. Something whose motion depends only on time can follow SharedTick instead, with no traffic at all.

Keyed entities belong to server rooms. A key names one entity, and the entity can't be the child of one from the world file. Otherwise nothing changes and SharedWorldError() says why.

For the full story - server rooms, hosting, sharing and host migration - see the Shared World guide and its complete Shared_World_Playground.bb sample.


See also: ShareWorldEntity, UnshareEntity, SharedEntityRemote, SharedTick, SharedEntityRange.

Index