Get Room properties and Player properties
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Get Room properties and Player properties
AlexUnity
2021-03-10 20:35:18
It is impressive that I could not find any single direct example of how to get a room property from a hashtable.
By simply using "customProperties[myHashKeyName]" does not work. All examples from here: https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/pun-basics-tutorial/intro
does not have a single simple "get property this way" example... =/
By example, I mean:
var roomOptions = new RoomOptions();
roomOptions.CustomRoomProperties.Add(ROOM_KEY_MapSeed, "seedwhatever");
roomOptions.CustomRoomProperties.Add(ROOM_KEY_GameTimer, 300);
PhotonNetwork.CreateRoom(null, roomOptions, null);
And then when I try to get it via "PhotonNetwork.CurrentRoom.CustomProperties[ROOM_KEY_MapSeed]" it returns null. (and yes, I did it after joining a room, with everything fine running, etc).
I could not find any single example of how to do that, without going to random posts here asking some other room related stuff.
I also tried to use "PhotonNetwork.CurrentRoom.SetCustomProperties(roomData);", but it never returns something on "OnRoomPropertiesUpdate"...
How to do it? Can anyone point me to any direction please?
Thanks.
Comments
I found an answer here: https://youtu.be/aVUNiJ3MVSg?t=213
ExitGames team, you should provide some more tutorials and direct answers to important and often called methods that, at first, looks simple, but it can be confusing. I was doing in a different way, it was not returning any errors, only "null" at some point and no clear direction. ANd when I go to your documentation, it says nothing but theory, not direct examples.
Also, many examples here, does not work: https://doc.photonengine.com/en-us/pun/v2/lobby-and-matchmaking/matchmaking-and-lobby (maybe outdated from API, etc).
Hi @AlexUnity,
Thank you for choosing Photon!
Also, many examples here, does not work: https://doc.photonengine.com/en-us/pun/v2/lobby-and-matchmaking/matchmaking-and-lobby (maybe outdated from API, etc).
Sorry you ran into this, could you tell us which ones you tried and did not work for you? some snippets are missing interface members implementation to make it shorter.
@JohnTube wrote: »
Hi @AlexUnity,
Thank you for choosing Photon!
Also, many examples here, does not work: https://doc.photonengine.com/en-us/pun/v2/lobby-and-matchmaking/matchmaking-and-lobby (maybe outdated from API, etc).
Sorry you ran into this, could you tell us which ones you tried and did not work for you? some snippets are missing interface members implementation to make it shorter.
Pretty much the Lobby examples. Some I could fix it while I wanted to test (for example, the Lobby custom property can be changed in a different way, I think it is now array based, can't remember).
@AlexUnity wrote: »
I found an answer here: https://youtu.be/aVUNiJ3MVSg?t=213
ExitGames team, you should provide some more tutorials and direct answers to important and often called methods that, at first, looks simple, but it can be confusing. I was doing in a different way, it was not returning any errors, only "null" at some point and no clear direction. ANd when I go to your documentation, it says nothing but theory, not direct examples.
Also, many examples here, does not work: https://doc.photonengine.com/en-us/pun/v2/lobby-and-matchmaking/matchmaking-and-lobby (maybe outdated from API, etc).
thank you so much i thought i was just doing something stupid, goign to watch this now
here is my code for anyone else stuch maybe it will help a n00b
private void CreateRoom()
{
RoomOptions roomOptions =
new RoomOptions()
{
IsVisible = true,
IsOpen = true,
MaxPlayers = desiredMaxplayers,
};
Hashtable RoomCustomProps = new Hashtable();
RoomCustomProps.Add(MAP_PROP_KEY, desiredCourse);
RoomCustomProps.Add(GAME_MODE_PROP_KEY, desiredGamemode);
roomOptions.CustomRoomProperties = RoomCustomProps;
string[] customPropsForLobby = {MAP_PROP_KEY, GAME_MODE_PROP_KEY };
roomOptions.CustomRoomPropertiesForLobby = customPropsForLobby;
PhotonNetwork.CreateRoom(null, roomOptions);
}
Back to top