question

undertheweatherllc avatar image
undertheweatherllc asked

MemoryDemoCloudScript question

I have a question about the cloud script for the Photon Memory Demo here:

https://github.com/JohnTube/MemoryDemoCloudScript/blob/master/MemoryDemo.js

On line 331, the shared group is deleted:

deleteSharedGroup(args.GameId);

I don't understand why it's being deleted here. It's outside of either the Type 'Close' or 'Save' blocks. Shouldn't it be part of the 'Close' block since the room is being closed for ending the game? Wouldn't the player lose the save game data if calling deleteSharedGroup here?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

That's actually not one of our samples - it's from @Hamza Lazaar. He can correct me if my assumptions are wrong, but from a quick look at the code, that Shared Group Data only exists while the room is "active". When it closes, if the game session is to be saved, it's doing that above that line, where you see the call to updateSharedGroupEntry. The GameId Shared Group Data is then re-created the next time a player creates a Room for their game.

7 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hamza Lazaar avatar image Hamza Lazaar commented ·

Hi @undertheweatherllc,

Yes @Brendan is right I use 2 SharedGroups per Photon Room:

1. One SharedGroup to hold the saved games data of closed Photon rooms. Since MemoryDemo is 1v1, we save the rooms data as key/value of a SharedGroup data of the rooms' creator (key is Room name (GameId) and value is stringified JSON data which contains Photon State among other things). The SharedGroup ID is composed of the PlayFabId and a suffix "_GamesList".

2. One SharedGroup has the same lifetime as the Photon Room and has the same ID as the Photon Room Name (GameId). The purpose of this SharedGroup is to hold the room data on PlayFab's side while the room is open and save it elsewhere when the room is "closed". For instance we need this SharedGroup to know the PlayFabId of the room creator at any time in order to save the data.

In my game I embed the PlayFabId of the room creator inside the room name (GameId) itself so I don't have to use (2).

0 Likes 0 ·
undertheweatherllc avatar image undertheweatherllc Hamza Lazaar commented ·

Okay, I understand that

deleteSharedGroup(args.GameId);

is for deleting the instance of the Playfab-side data that reflects the state of the Photon room while it is open.

Hamza Lazaar said:

I use 2 SharedGroups per Photon Room:

Is this statement correct, or do you mean 1 SharedGroup for "closed" rooms, plus n SharedGroups for each opened PhotonRoom, per player? It sounds like the _GamesList sharedgroup stores a list of keys of all the closed, in-progress game rooms, with their Photon state data stored as the value of the pair. Is this right? Or is this still wrong?

0 Likes 0 ·
Hamza Lazaar avatar image Hamza Lazaar undertheweatherllc commented ·

Yes that is right and you are correct.
Each player has a GamesList SharedGroup where keys are GameIDs and values are game data (Photon room state + other extra metadata). The creator of the room is the one that should keep the game data in whole while the joined actor should just have an entry (reference/redirect) to the creator.

0 Likes 0 ·
undertheweatherllc avatar image undertheweatherllc Hamza Lazaar commented ·

Thanks for the clarification. Er, one more related question... What was the reason for designing the shared groups as such? Why not create a shared group for each room, say like "<PlayFabId>_0", "<PlayFabId>_1", etc. and maintain that shared group until the match ends, rather than saving/loading the room data to a _GamesList shared group, and "per-session" shared groups for each Photon room lifetime?

0 Likes 0 ·
Hamza Lazaar avatar image Hamza Lazaar Hamza Lazaar commented ·

@undertheweatherllc well you need to persist room state between sessions so you can restore it on photon servers when you rejoin the room. that's the point of saving and loading game data in "<RoomCreatorPlayFabId>_GamesList".

0 Likes 0 ·
Hamza Lazaar avatar image Hamza Lazaar Hamza Lazaar commented ·
@undertheweatherllc

the reason is simple: PlayFab limits # of SharedGroups to 10 per player.

0 Likes 0 ·
undertheweatherllc avatar image undertheweatherllc Hamza Lazaar commented ·

Isn't the room state already stored and edited in the shared group for the room? Basically, I'm wondering what the reason is for deleting this shared group when the Photon room is closed, rather than keeping that shared group around, until the entire game match is completed.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.