How to sync IsInactive for Players?


I am just trying to get my first program working with Photon. I followed the Loadbalancing demo to recreate the scenario where there is a list of rooms and you can create one or join one.
Now, in my "inside of a room" view, I show a list of players that are currently inside the room.
I now want to implement a "Player is ready" option. That means, when a player enters the room, he is not ready. After that, he can choose to click the "ready" button to be ready.
I was thinking that I could use the "IsInactive"-Property of the LocalPlayer object. I set "IsInactive" to true when the LocalPlayer enters the room. Then, when the "ready" button is clicked, I set the "IsInactive" to false.

Now, it works just fine to set the LocalPlayers "IsInactive" property. But the other players should be able to see as well that the player is now ready. The problem is that the value of "IsInactive" isn't updated across the network, only the client of the player that pressed the "ready" button.

I don't raise an event or anything yet when I change the "IsInactive" property. Do I need to do that in order to notify the other clients? Is there anything about using "IsInactive" for this purpose that makes it not suitable for this kind of task?
I would also like to generally ask how a "ready" option is usually implemented, since there is maybe an easier way to do this. For example, maybe a custom property would work better.


  • JohnTube
    JohnTube ✭✭✭✭✭
    edited July 2016
    Hi @MasterQuestMaster,

    There is a misunderstanding here.

    IsInactive is used -internally- by Photon LoadBalancing for async. behavior in some games (to tell if an actor is currently connected and joined to the room).

    To achieve what you want you may use Photon events or Room/Player properties. I believe you may find something useful here on the forum or somewhere else on the internet.
  • MasterQuestMaster
    edited July 2016
    Hi @JohnTube

    I think the Visual Studio description of the "IsInactive" property said something about it being used to tell which player in a turnbased game is currently active. That's how I came to the assumption that it was usable for stuff like this.

    I tried my approach with a custom property of the player and it worked as expected.

    While I was trying to get it working, something came up with custom properties and I would like a confirmation on that.
    According to the description of the "SetCustomProperties" method, it synchronizes the custom properties. That means if I just change something in the custom properties without calling the function, it won't get transmitted to the other clients. Is that correct?

    Because I used something like:
    and I thought it looked a bit odd. Is this necessary to transmit the properties?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited July 2016
    I think you just need to pass only updated properties: i.e. changed, removed (value set to null) or new ones. For instance to add or update "customProp" player property:

    player.SetCustomProperties(new Hashtable(){{"customProp", value}});
  • That makes sense.
    I have a problem now though.

    When the player leaves a room and re-enters while he was ready, he is still ready when he re-enters.
    I want to reset the "ready" custom property when the player enters the room.

    Therefore, in the Load event of my "RoomDetails"-View (which contains the Ready button and the player list and is freshly created for every time the player joins a room and closed after he leaves it), I tried to set "ready" custom property of the LocalPlayer to false.

    But somehow, the change is not transmitted in this specific case. It works with the ready button, but not inside the Load event. The code to set the property is the one that you wrote in your post.

    Maybe the player hasn't finished entering the room yet and therefore it doesn't work?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @MasterQuestMaster,

    In that case you should use this method directly when a player leaves the room:

    loadBalancingClient.OpSetCustomPropertiesOfActor(actorNr, new Hashtable(){{"ready", false}});

  • MasterQuestMaster
    edited July 2016
    Thanks for your help! I tried it with the normal SetCustomProperties when the player leaves the room and it worked too. So I won't use the OpSetCustomPropertiesOfActor method, but thank you for telling me that I should set the properties when the player LEAVES the room.
  • JohnTube
    JohnTube ✭✭✭✭✭
    You are welcome.
    In fact, player.SetCustomProperties includes a call to loadBalancingClient.OpSetCustomPropertiesOfActor.
  • @JohnTube
    I thought so, since you mentioned to "call the function directly" which implied that it was indirectly called before.
    Anyway, thanks for your help.