Hi,
I'm trying to set user variables for my players at login and retrieve them when a player gets spawned. I get a 'null' value back.
Anyone have ideas ?
user variables
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
in my OnConnection function i have :
in my UserEnterRoom function :
when i debug user.GetVariables() i get a hash back but nothing shows up in the logs.
Code: Select all
Hashtable avatarInfo = new Hashtable();
avatarInfo.Add("avatarType", "type1");
smartFox.SetUserVariables(avatarInfo);
SmartFox.Connection = smartFox;
in my UserEnterRoom function :
Code: Select all
Hashtable uVars = new Hashtable();
uVars = user.GetVariables();
foreach (DictionaryEntry entry in uVars)
Debug.Log("enter room : " + entry.Key + " " + entry.Value);
when i debug user.GetVariables() i get a hash back but nothing shows up in the logs.
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
Thomas,
How would i change a remote player's avatar when it spawns ?
What i'm trying ( but not succeeding ) is a user selects his avatar when he is logged on, then gets spawned in the room.
It's easy for the localplayerobject... in my localplayer spawn function i check what is selected and spawn the resulting avatar but how would i handle the remotes ?
I thought uservars would be the best way to go but maybe you have a better way of handling this ?
Eddy.
How would i change a remote player's avatar when it spawns ?
What i'm trying ( but not succeeding ) is a user selects his avatar when he is logged on, then gets spawned in the room.
It's easy for the localplayerobject... in my localplayer spawn function i check what is selected and spawn the resulting avatar but how would i handle the remotes ?
I thought uservars would be the best way to go but maybe you have a better way of handling this ?
Eddy.
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
User variables are definitely a great way to do this.
When you first log in, you join some kind of room (on the server). Once you join that room (just on the server - not visually on the client side) - you show the selection screen of avatars to pick and THEN you spawn yourself into the game room with the right avatar.
Thats at least how I would (and have) done it.
/Thomas
When you first log in, you join some kind of room (on the server). Once you join that room (just on the server - not visually on the client side) - you show the selection screen of avatars to pick and THEN you spawn yourself into the game room with the right avatar.
Thats at least how I would (and have) done it.
/Thomas
actualy i'm able to set the vars from the client but reading them back out is somthing i havent figured out yet :
1. the player needs to be in a room to be able to set them.
2. once your in a room you can create a hashtable and send it:
3. once you have sent this to the server, it will send it to all other players in the room so you need to handle the local player yourself.
4. you can retrieve them with :
this all works fine.
I have a problem with getting the value from the last created hashtable :
I tried converting the object from the hash value to a string to be able to compare it, but that doens't work.
Eddy.
1. the player needs to be in a room to be able to set them.
2. once your in a room you can create a hashtable and send it:
Code: Select all
string male = "male";
Hashtable avatarInfo = new Hashtable();
avatarInfo.Add("avatarType", male);
smartFoxClient.SetUserVariables(avatarInfo);
3. once you have sent this to the server, it will send it to all other players in the room so you need to handle the local player yourself.
4. you can retrieve them with :
Code: Select all
Hashtable aTypes = new Hashtable();
Hashtable uVars = new Hashtable();
uVars = user.GetVariables();
aTypes.Add(user.GetId(), uVars["avatarType"]);
this all works fine.
I have a problem with getting the value from the last created hashtable :
Code: Select all
int remoteId = user.GetId();
if(aTypes[remoteId].ToString() == "male") {
//process code
I tried converting the object from the hash value to a string to be able to compare it, but that doens't work.
Eddy.
ok, it's working now like it should
all you need to do is set the user vars ( send them to the server ) and to retrieve them just call GetVariable on a user object :
user.GetVariable("myhashkeyname");
and cast it to a string or anything else if needed :
user.GetVariable("myhashkeyname").ToString();
this will retrieve the Value in the hashtable with key 'myhashkeyname'
hope it helps someone
all you need to do is set the user vars ( send them to the server ) and to retrieve them just call GetVariable on a user object :
user.GetVariable("myhashkeyname");
and cast it to a string or anything else if needed :
user.GetVariable("myhashkeyname").ToString();
this will retrieve the Value in the hashtable with key 'myhashkeyname'
hope it helps someone
Return to “.Net / Unity3D API”
Who is online
Users browsing this forum: No registered users and 30 guests