Author Topic: duplicated players  (Read 3789 times)

meganuke

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
    • View Profile
duplicated players
« on: July 04, 2014, 11:15:50 AM »
hi!!!

i have this extrange behaviour.

i created a simple lobby, and when a player joins, he is added twice to TNManager.players

this is the code for creating and joining the channel:
  1.                 if (Input.GetKeyDown(KeyCode.Alpha5)) {
  2.                         TNManager.JoinChannel(0,"lobby1");
  3.                 }
  4.  
  5.  

and this is how i finally noticed that they were duplicating:
  1.         void OnGUI ()
  2.         {
  3.                 string players = null;
  4.                 players = TNManager.players.size + " players\n";
  5.                 //TNManager.
  6.                 for (int i =0; i<TNManager.players.size;i++){
  7.                         players += TNManager.players[i].id + "-" + TNManager.players[i].name + "\n";
  8.                 }
  9.                
  10.                 GUILayout.Label(players);
  11.         }
  12.  

when 1 player joins it says
Quote
2 players
2 Guest
2 Guest

when another player joins it says:
Quote
4 players
2 Guest
2 Guest
3 Guest
3 Guest

the last player that joins will see the information correctly, i mean: every user only once.
but if a new player joiins after him he will see him duplicated!!


what could be causing this?

meganuke

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
    • View Profile
Re: duplicated players
« Reply #1 on: July 04, 2014, 12:22:28 PM »
also
forgot to mention this message shows only once:

Quote
   void OnNetworkPlayerJoin (Player p)
   {
      Debug.Log("a player has joined..." );
      message+="a player has joined.....\n";
   }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: duplicated players
« Reply #2 on: July 04, 2014, 03:28:55 PM »
I am not seeing this on my end. Try it with the chat example that comes with TNet. I even used your script adding its code to ExampleChat's OnGUI function, and I only see each player once.

meganuke

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 33
    • View Profile
Re: duplicated players
« Reply #3 on: July 04, 2014, 08:32:08 PM »
i reproduced the problem i was trying to copy the player list

like this:

  1.         void Start () {
  2.                 TNPlayers = TNManager.players;
  3.         }
  4.  

 then on the join events i did this:

  1.         void OnNetworkPlayerJoin (Player p)
  2.         {
  3.                 Debug.Log("player " + p.id + " has joined. " );
  4.                 TNPlayers.Add(p);
  5.                 mPlayerCount++;
  6.  
  7.         }
  8.  

well, it seems that the first call, doesnt "extract" the player list, but creates a reference to the list itself, so i was actually adding the players twice.

not sure if thats the real case, but removing the "TNPlayers = TNManager.players" line solved the problem.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: duplicated players
« Reply #4 on: July 05, 2014, 11:10:32 PM »
Yeah, you should never be adding anything to the player list. Player list isn't yours to modify, it's TNet's. You can modify the player data though.