RPC.AllBuffered?

Options
Hi,

Do you receive the buffered message before or after Start() ?
I'm sending an RPC message in Start(). If buffered message gets recived after Start() where could i place it, so that i send the RPC after Ive received all buffered messages?

Hope you understand my question :roll:

Comments

  • Tobias
    Options
    Start() is called by the engine client side to init scripts/objects. RPCs (buffered or not) are called by scripts we run in the engine and should all be called after start.
    There is no difference between buffered or "live" RPCs but the buffered ones are called first, when you join a room.
    There is no place or method to put your code to be called once the buffered calls are done.
    Is this really necessary? What's the plan?
  • This is for team joining, and you join a team randomly according to how many is on each team.
    So what's happening in my case is, a player joins a team before knowing how many is on them.

    What I'm doing is i send an RPC.AllBuffered at start letting everybody know that I'm joining a team,
    and when a new player joins i was hoping he gets that information and then sends an RPC that he is joining,
    But that's not the case :(.
    Maybe it's me who is doing that the wrong way then?
  • Tobias
    Options
    Buffered RPCs are not the best solution for this. You could use a custom property per player. Example name: "t" for "team" and value would be (byte)1 or (byte)2.
    These are synced when you join a room. Until your client picked a team, you can check of the properties are set for everyone and sum up the team sizes to decide which side the new player is on.
  • Oh Thanks.
    But is there a class reference for CustomProperties or a little guide/tutorial that involves it?
  • Tobias
    Options
    Err. No. :oops:
    This page handles room properties for matchmaking: http://doc.exitgames.com/photon-server/ ... references

    Custom properties are stored in a Hashtable. The keys must be of type string, the value can be anything serializable (strings, bytes, byte[] and many more). Preferably the string keys are really short.
    Anyone can set the values when in room via SetProperties. This makes sure they are synced but racing conditions will happen if every client changes something at the same time.
    You can update a key's value or set it to null to remove the key.
  • After OnJoinedRoom I'm doing this:
    public int team = 0;
    public Hashtable h;
    
    void Awake()
    {
        if (photonView.isMine)
        {
    	    h = new Hashtable();
    		h.Add("t", team);
    		PhotonNetwork.player.SetCustomProperties(h);
    			
    	    PhotonNetwork.player.customProperties["t"] = 1;
    	}
    }
    

    And then this:
    void Start()
    {
        foreach(PhotonPlayer name in PhotonNetwork.playerList)
    	{
            Debug.Log(name.name + " is on team " + name.customProperties["t"]);
    	}
    }
    

    Player 1 joins and player 2 gets this:
    Player1 is on team 0
    player2 is on team 1

    And i wanted both to be 1. What am i doing wrong?
  • Tobias
    Options
    Always use SetCustomProperties() to sync any prop change. It will cache the new values to another hashtable locally and send the changed ones.
  • I appreciate your help. But i have no idea how i could change the value of "t" with SetCustomProperties(). :? Can you give me an example or something? Thanks!
  • Tobias
    Options
    Hm. We're lacking another sample. Let me make up one on the fly:

    [code2=csharp]Hashtable propertiesToSet = new Hashtable();

    Hashtable propertiesToSet = new Hashtable();
    // to set "t" property to 1. i use a byte explicitly, because a integer (default number type) would be 4 bytes traffic
    propertiesToSet.Add("t", (byte)1);
    PhotonNetwork.player.SetCustomProperties(propertiesToSet);

    // to set "t" property to 2
    // i can re-use propertiesToSet here as I override the only value in it.
    propertiesToSet.Add("t", (byte)2);
    PhotonNetwork.player.SetCustomProperties(propertiesToSet);

    // to remove "t" property from your player's properties
    propertiesToSet.Add("t", null);
    PhotonNetwork.player.SetCustomProperties(propertiesToSet);

    // you can access any player's customProperties like so - remember: we used byte as value's type
    byte team = (byte)PhotonNetwork.player.customProperties["t"];



    // keep in mind: propertiesToSet is not becoming the new player.customProperties hashtable. it's merged with existing key-values pairs[/code2]
  • Thank you so much for that example! Helped me allot.