Private Chat Advice?

I have been working on a chat and would like to add a private chat feature to it. However, I’m not sure what the best, or even a good way is to do it. I’ve started with having an ArrayList that holds the chat entries displayed to each player that joins. Then I would use a foreach loop to go through a list of players and if a player’s name was equal to the name we wanted it would add the message to that ArrayList only.

Now, I have that made right now, but it shows the messages to all that are connected to the server when it shouldn’t. This could be a bug in my code that I haven’t found yet, but I would like to know how you guys make a private chat function, and if I’m doing it all wrong?

Thanks in advance,

  • WolfShield

Good question, I’m having the same problem.

Say we are doing a little MSN inside Unity3D…

First, we have a friends list (Mark, Bob, John), clic in Mark and a window is opened.

Course, the window has a string list for the messages, the target NetworkPlayer, and a textfield. By using NetworkView.RPC( “AddMessage”, targetPlayer, message) I send the text to he / she. Perfect !

But, what if inside a chat window I can have more than one client. In the left I have a chat window with Mark only, and in the right one with Mark and Bob.

How do I know which window should receive the message. Maybe each can have its own NetworkView with a different network group assigned.

AzulValium,
Thank you for your reply. You have given me an idea to try! :slight_smile:

As for your problem, my first thought would to use a foreach loop to search through the NetworkPlayers, then use an if statement to see if the NetworkPlayer is the one we want, then use NetworkView.RPC(“AddChatMessage”, targetPlayer, message); to send each player we want a private chat message. Sorry I don’t have any code written up, but I hope I have helped you as well.

Thanks,

  • WolfShield

Yes, that works really great, so you should use it. If you aren’t in a hurry, soon I will be posting a code for you.

My problem is related to, having a player in two different chat windows. And how to know what window should “receive” the message.

Window A, private chat with Mark

Mark.

Window B, private chat with Mark and Bob

Mark.
Bob.

Anyway…its more for fun and theaching purposes :smile: