Problem with ChatRoom

Options
[RPC]
public void Chat(string newLine, PhotonMessageInfo mi)
{
m_alpha = 7;
string senderName = "anonymous";

if (mi != 0 && mi.sender != 0)
{
if (!string.IsNullOrEmpty(mi.sender.name))
{
senderName = mi.sender.name;
}
else
{
senderName = "player " + mi.sender.ID;
}
}

this.messages.Add("[" + senderName + "]: " + newLine);
if (MsnSound != null && WithSound)
{
GetComponent().PlayOneShot(MsnSound);
}
if (messages.Count > MaxMsn)
{
messages.RemoveAt(0);
}

ChatText.text = "";
foreach (string m in messages)
ChatText.text += m + "\n";
}
///
/// Local Method
///
///
public void AddLine(string newLine)
{
m_alpha = 7;
this.messages.Add(newLine);
if (messages.Count > MaxMsn)
{
messages.RemoveAt(0);
}
}

public void Refresh()
{
ChatText.text = "";
foreach (string m in messages)
ChatText.text += m + "\n";
}
}




if (mi != 0 && mi.sender != 0) <- This is the error line, first time it was null not 0, i've tried all i can to solve this, no way for me, i just hope someone just can light me :smiley:

Comments

  • Hi @MGabben,

    as far as I know the PhotonMessageInfo can't be NULL, so you don't have to check this condition. The sender information of the PhotonMessageInfo is a PhotonPlayer which - I think - can't be NULL as well. So I think you can safely remove those two conditions.