Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
omard2000

[PHOTON QUESTION CHAT] OnGetMessage Function

Question

Hello,

I understand that whenever a message is received this function is called. However, I do not know how I can extract the information that is being received...

public void OnGetMessages(string channelName, string[] senders, object[] messages) {
string msg = "";
for (int i = 0; i < senders.Length; i++) {
msg = string.Format("{0}{1}={2}, ", msg, senders, messages);
}
Debug.LogFormat("OnGetMessages: {0} ({1}) > {2}", channelName, senders.Length, msg);
}

This is the code that I am referring to.

For example, this is the output when I send the message "hello" from another user...
OnGetMessages: channelA (1) > 1f83f13b-666d-4f11-97d6-d4adb6624242=hello, 

How can I get the sender name and the message sent from this information?

Thanks!

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Just use these arrays.

 

public void OnGetMessages(string channelName, string[] senders, object[] messages) {
for (int i = 0; i < senders.Length; i++) {
}
Debug.LogFormat("Message from user {0}: {1}", senders, messages);
}

 

Sender with number '0' corresponds to message with number '0', sender with number '1' corresponds to message with number '1' and so on

Share this post


Link to post
Share on other sites

  • 0
Please login or register to see this quote.

 

What you are saying makes sense, but I don't understand the output that is being displayed in the console. This is the output with the code that you suggested: "Message from user System.String[]: System.Object[]"

 

Shouldn't it be displaying the username and the message?

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Ohh, this makes sense now. Thank you! 😄

Share this post


Link to post
Share on other sites
  • 0

Never mind, stupid mistake I made lol. Thanks again! :)

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote. Please login or register to see this code.

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...