Forum Multiplayer Help?

Discussion and help relating to the PlayerIO Multiplayer API.

Help?

Postby 12345hassan » January 8th, 2018, 4:27 pm

Help please i cant see myself im working on a test server of a game called stickrun
Attachments
help.png
help.png (42.46 KiB) Viewed 13861 times
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: Help?

Postby 12345hassan » January 8th, 2018, 4:29 pm

in first picture, i can see myself and in the 2nd i when i connected i cant see the others who join only the first who join can see
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: Help?

Postby 12345hassan » January 12th, 2018, 4:37 pm

Pleaseeebhelp
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

Re: Help?

Postby 12345hassan » January 25th, 2018, 4:45 pm

anyone?
12345hassan
 
Posts: 44
Joined: August 5th, 2016, 11:40 am

send existing game state to newly joined player

Postby nev » January 29th, 2018, 10:52 pm

Hi,

I think your problem is that you are not sending ALL the game state to a new player the first time they join. To fix your exact problem, you need to send a list of already connected player objects (or just the player names) to EACH new player.

The reason player1 sees player2 is because the default code on the server sends a message to all connected players whenever a new player joins. This message contains the new player info. The default code in the client handles these 'Join' messages. You probably modified this part to add the players to your window. But player2 never got sent a message when player1 joined, so they do not see player1 in their window. Now just for fun, try and connect with a 3rd player and you should see that player1 window has all 3, player2 is missing just player1, and player3 only sees them self.

To fix this, modify the default server code in
Code: Select all
UserJoined(P newPlayer) {

    foreach (Player p in Players) {

        if (p != newPlayer) {

            // Send info for just newPlayer in a 'Join' message.

        } else { // so p == newPlayer

            // Send newPlayer info for ALL players including themselves.
            // Make sure it's in a special 'JoinAll' message, or whatever you want to call it.

        }
    }
}


then in client, you just have to add code to listen for the 'JoinAll' message and then handle displaying all the users in your window at once.

I hope I explained clearly and that this solves your problem. Also remember to send EVERYTHING a player needs to know about the game state in the 'JoinAll' message, like the # of deals, money, chat messages, and anything else a player can change before another player joins.

PS: I suggest you change the subject of this post by editing you original post. Give it a more meaningful title like "Second player to join cannot see the first player." That way others who have your problem can find this more quickly.

PPS: Just so you know the default code sends the joined player's info right back to them the first time they join as part of the 'Join' message, and and lets the client display their info using the same code that displays the info of new players who join after. I think this is a little inefficient (lazy), because the player already knows about themselves. So I handle it differently and when sending the 'JoinAll' message I leave them out of it, but make sure to add them in at the end of the list on the client using the info the client ALREADY knows about who they are. So just in case you end up with the problem that the player sees everyone else but not themselves, it is because you left their info off the 'JoinAll' or you did not handle it client side if you purposely left them off.
nev
 
Posts: 4
Joined: April 24th, 2013, 8:39 pm


Return to Multiplayer



cron