Hashtable tutorial?
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Hashtable tutorial?
cj31387
2013-10-20 02:35:14
I need some way to store kills and deaths, SetCustomProperties seems like the way to do it. But I've never really used Hashtables before. Can someone point me to a tutorial or guide. The ones I've found here or on Google give me this error, when I try to SetCustomProperties() . error CS1503: Argument #1' cannot convert
System.Collections.Hashtable' expression to type `ExitGames.Client.Photon.Hashtable'
Here is some of my code so far
[code2=csharp]using UnityEngine; using System.Collections;
public class MPKillDeathCountPing : Photon.MonoBehaviour {
public int killCount;
public int deathCount;
public Hashtable PlayerCustomProperties = new Hashtable();
//Add the kill part to when a player is hit and health is 0 or less.
// Use this for initialization
void Awake () {
if (photonView.isMine == true)
{
PlayerCustomProperties.Add("Kills", killCount);
// ERROR RIGHT HERE
PhotonNetwork.player.SetCustomProperties(PlayerCustomProperties);
killCount = 0;
deathCount = 0;
}
else
{
enabled = false;
}
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
GUILayout.Space(20);
GUILayout.Label("Ping: " + PhotonNetwork.GetPing().ToString());
GUILayout.Space(5);
GUILayout.Label("Kills: " + killCount.ToString());
GUILayout.Space(5);
GUILayout.Label("Deaths: " + deathCount.ToString());
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
// We own this player: send the others our data
}
else
{
// Network player, receive data
}
}
}[/code2] Thanks.
Comments
Btw where is code insert in this forum? Don't see it.
You have to define that you want to use Photon's Hashtable class. This is done by adding a "using" statement at the top of your class. Like so:
[code2=csharp]using UnityEngine; using System.Collections; using Hashtable = ExitGames.Client.Photon.Hashtable;[/code2]
For code insertions: The "full" editor has a drop down "Code". Select your code, then pick the fitting language from the Code dropdown. Keep in mind that less code is better for us to read and answer at all.
That worked thanks!!
Back to top