Enumerating players in a room

Options
Hello everyone! At first, a little disclaimer. I am planning to use PUN (with photon cloud) in my project as a most reliable and easy to use multiplayer backend. I am moving form combination of Google Play multiplayer and Unity networking, which was proven unusable in serious projects. I will be asking a series of questions for which I didn't find the answers in docs or somwhere else (forum, stackoverflow, unity answers). Don't get me wrong, I will be glad if I'm mistaking, and the answers are obvious or easy to find. Anyway, please point me in right direction and please don't leave any of this questions unanswered.

My fourth question is about assigning some kind of id's to players. I'm aware of actorIDs, but for my needs i would like to have an enumeration form 0 to maxPlayers-1. For now, I implemented such enumeration by counting on game start how many players has actorIDs less than mine:
static function GetPlayerNum() : int {
		var res : int = 0;
		var cur : int = PhotonNetwork.player.ID;
		for(var pl : PhotonPlayer in PhotonNetwork.playerList) {
			if(pl.ID < cur) res++;
		}
		Debug.Log("Current player is #" + res.ToString());
		return res;
	}

It is required for players in a room not to have the same number. Missing numbers due to leaving players is fine. I have a strong feeling that I'm missing something. Any advice is appreciated.

Comments

  • Kaiserludi
    Options
    Hi diablo23q.
    diablo23q wrote:
    It is required for players in a room not to have the same number. Missing numbers due to leaving players is fine.
    In that case I would just use the actor numbers decreased by 1.
  • diablo23q
    Options
    So actorIDs won't all of a sudden be 1, 115, 34324, 943 or something like that? Can I rely on how this Ids are generated?
  • Kaiserludi
    Options
    actor numbers are assigned to the players that enter a room in ascending order. When someone leaves a room, his actor number won't get reused and everyone else keeps the actor number that he already had before, the actor number of the leaving player will now just be missing.
    So actor numbers work in exactly the way that you need, except for them starting at index 1 for the room creator, not index 0.

    We can't guarantee that the system how we assign actor numbers won't ever change, but it is very unlikely to change in the foreseeable future as that would break quite some internal code that relies on it.