PhotonNetwork.JoinOrCreateRoom() for random rooms?
Hello,
Is there a way to atomically join-or-create a random room? I thought it would be the case when I call PhotonNetwork.JoinOrCreateRoom() with a null room name, but that does not work. If I do specify a name then I can only create up to 1 room with the required criteria.
The use-case I am trying to implement is - users can join a Photon room to play a specific level. For that, I am setting a custom property 'Level'= and use that property for the lobby.
I'd like the 1st player to attempt to join-or-create that room to succeed and create a room with a random name, and other players to join that player in that room. When the room is full and another player tries to join-or-create, another room with a random name is created (but with the same 'Level'= property.
Is this possible?
As a workaround I am currently performing two separate calls - JoinRandomRoom() followed by CreateRoom() if the former has failed. This, however is not ideal, because players who attempt to join a room at roughly the same time end up in separate room instances.
Thanks,
Sylwester
Is there a way to atomically join-or-create a random room? I thought it would be the case when I call PhotonNetwork.JoinOrCreateRoom() with a null room name, but that does not work. If I do specify a name then I can only create up to 1 room with the required criteria.
The use-case I am trying to implement is - users can join a Photon room to play a specific level. For that, I am setting a custom property 'Level'= and use that property for the lobby.
I'd like the 1st player to attempt to join-or-create that room to succeed and create a room with a random name, and other players to join that player in that room. When the room is full and another player tries to join-or-create, another room with a random name is created (but with the same 'Level'= property.
Is this possible?
As a workaround I am currently performing two separate calls - JoinRandomRoom() followed by CreateRoom() if the former has failed. This, however is not ideal, because players who attempt to join a room at roughly the same time end up in separate room instances.
Thanks,
Sylwester
0
Best Answer
-
Hi @Sly,Is there a way to atomically join-or-create a random room?No there isn't currently.I thought it would be the case when I call PhotonNetwork.JoinOrCreateRoom() with a null room name, but that does not work.You misunderstood how JoinOrCreateRoom works. It tries to join or create a room that is not random, so its name must be known.As a workaround I am currently performing two separate calls - JoinRandomRoom() followed by CreateRoom() if the former has failed. This, however is not ideal, because players who attempt to join a room at roughly the same time end up in separate room instances.Well, you summarized everything in this §.
We already have a new feature planned (no ETA) to allow JoinRandomRoom to automatically create a room if none found w/o the need for an extra CreateRoom call. However, I do not think that this will solve the issue of when two clients call JoinRandomRoom at the same time.5
Answers
-
Hi @Sly,Is there a way to atomically join-or-create a random room?No there isn't currently.I thought it would be the case when I call PhotonNetwork.JoinOrCreateRoom() with a null room name, but that does not work.You misunderstood how JoinOrCreateRoom works. It tries to join or create a room that is not random, so its name must be known.As a workaround I am currently performing two separate calls - JoinRandomRoom() followed by CreateRoom() if the former has failed. This, however is not ideal, because players who attempt to join a room at roughly the same time end up in separate room instances.Well, you summarized everything in this §.
We already have a new feature planned (no ETA) to allow JoinRandomRoom to automatically create a room if none found w/o the need for an extra CreateRoom call. However, I do not think that this will solve the issue of when two clients call JoinRandomRoom at the same time.5