Groups¶
Groups enable server-less multiplayer by providing a shared storage area. Multiple players can access a group's storage at the same time.
Creating a new group¶
Sending a group to a friend¶
Once you have a group, you need to send the group's ID to another player so that they can access it.
One way to do this is by embedding it into a link with playpass.createLink()
and sharing it with
playpass.share()
.
// Create a link containing the group ID
const link = playpass.createLink({ data: { myGroupId: group.groupId } });
// Share the link
playpass.share({ text: `Come play in my group! ${link}` });
Joining an existing group¶
From the above example, we can check if the player launched the game by clicking on the group link:
const data = playpass.getLinkData();
if (data && data.myGroupId) {
const group = await playpass.groups.getGroup(data.myGroupId);
// We can now access the group!
}
Writing custom data to the group¶
Reading custom data from the group¶
Player-specific data¶
To store data relevant to an individual player, the best practice is to prefix the storage key with the player's ID:
A list of players that have ever written to the group can be queried using the players
variable: