Many p5party games and apps need to store information specific to each connected client. For example, in an MMO each client has their own position in the world. This position needs to be shared so that everyone can see everyone else. In the idle_clicker example each player clicks as quickly as they can and the number of times they have clicked needs to be shared to everyone.

One might put this information in a common shared object but in many cases this will likely lead to conflicts when multiple clients try to write to that object at the same time. Keeping a separate shared object for each player makes it easier to avoid a conflict. If every client writes to their own shared object and not anyone else’s a conflict won’t occur.

P5party keeps track of the connected clients and automatically creates and manages shared objects for each one. The shared objects are called “myShared” objects here in the docs. P5party creates a “myShared” object for when a client connects and forgets it when they disconnect.

P5party also keeps a list of all* the connected client’s “my shared” objects in an array. This array is the “guestShareds” array.

What is the “myShared” object?

The “myShared” object is a shared object automatically created for every client that connects to your game. You can use it to store any data about that specific client that should be accessible by the other clients.

Use partyLoadMyShared() load the “myShared” object for the current client.

partyLoadMyShared()

What is the “guestShareds” array?

The “guestShareds” array is an array that holds a reference to the “myShared” object of every client currently connected to your game. You can use this array to information about the other clients.

Use partyLoadGuestShareds() to load the “guestShareds” array.

partyLoadGuestShareds()

Examples

idle_clicker

cursors

sign_up