- Home /
Overload methods of Hashtable using System and Photon namespaces
Project is in uJS and using Photon PUN.
So I'm trying to use a hashtable for setting some custom properties in the Photon player custom properties :
function ResetScores()
{
var props : Hashtable = new Hashtable();
props.Add( "Kills", 0 );
props.Add( "Deaths", 0 );
props.Add( "Assists", 0 );
PhotonNetwork.player.SetCustomProperties( props );
}
Now the only reference to uJS hashtables is here but there is no example of adding keys and values. I check a MSDN example and a few Photon questions and they are all in C#, but declared the same.
well that gave the error :
Assets/_Scripts/GameManager.js(386,57): BCE0017: The best overload for the method 'PhotonPlayer.SetCustomProperties(ExitGames.Client.Photon.Hashtable)' is not compatible with the argument list '(System.Collections.Hashtable)'.
I'm using generic List in the same script :
import System.Collections.Generic;
public class GameManager extends Photon.MonoBehaviour {
so thinking I had to use the photons system of collection, I tried using :
var props : ExitGames.Client.Photon.Hashtable = new Hashtable();
which gave the error :
Assets/_Scripts/GameManager.js(380,69): BCE0022: Cannot convert 'System.Collections.Hashtable' to 'ExitGames.Client.Photon.Hashtable'.
This is the first time I've used hashtable, all out of ideas and could really do with some advice and/or help. Maybe the problem is using System.Collections or Photon.MonoBehaviour ?
Thanks for reading.
Please help.
Should I be importing namespaces? If not, I need a re$$anonymous$$der on how to use a namespace on a variable only. How can I use Systems namespace for List, and Photon namespace for Hashtable?
Edit :
var spawnPoints : System.Collections.Generic.List.< SpawnPoint >;
gives the error
Assets/_Scripts/Game$$anonymous$$anager.js(65,28): BCE0018: The name 'List' does not denote a valid type ('not found'). Did you mean 'UnityEngine.Light'?
using :
var props : Photon.Hashtable = new Hashtable();
gives the error :
Assets/_Scripts/Game$$anonymous$$anager.js(428,29): BCE0018: The name 'Photon.Hashtable' does not denote a valid type ('not found'). Did you mean 'ExitGames.Client.Photon.Hashtable'?
using :
var props : ExitGames.Client.Photon.Hashtable = new Hashtable();
gets me closer, but now I'm back to the original error :
Assets/_Scripts/Game$$anonymous$$anager.js(428,69): BCE0022: Cannot convert 'System.Collections.Hashtable' to 'ExitGames.Client.Photon.Hashtable'.
Edit 2 :
I've now posted this question on the forums. $$anonymous$$y guess is everyone here hates me. Unless one of the top two users here on UA responds, I never get any help ....
Also, to optimise it a little bit, try to keep the hash keys as small as possible. For instance, ins$$anonymous$$d of "$$anonymous$$ills", call it "$$anonymous$$L".
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:
using UnityEngine;
using System.Collections;
using Hashtable = ExitGames.Client.Photon.Hashtable;
Answer by Jamora · Oct 28, 2013 at 06:57 PM
Have you tried
var props : ExitGames.Client.Photon.Hashtable = new ExitGames.Client.Photon.Hashtable();
Looked like you were trying to fit a System Hashtable to the Photon Hashtable...
you could also try importing the photon namespace instead of the System one.
import ExitGames.Client.Photon;
So now
var props : Hashtable = new Hashtable();
should mean the Photon one, and not the System one.
Even though you're not using C#, I assume there's something similar to aliases in UnityScript. In C#, I would declare an alias by
using PhotonHashTable = ExitGames.Client.Photon.Hashtable;
right below all the other using directives. Now the compiler knows, at compile-time, to swap each instance of PhotonHashTable into that dot-monster.
Thank you Jamora. Now I see it, it seems so obvious :S Really appreciate the help.
Using :
import ExitGames.Client.Photon;
Gives an Ambiguous reference error but I can understand why.
Assets/_Scripts/Damageable.js(238,56): BCE0004: Ambiguous reference 'Hashtable': ExitGames.Client.Photon.Hashtable, System.Collections.Hashtable.
So for now, declaring the class to use locally is fine. Again, many thanks for your help.