New to SmartFoxServer

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

gatillian
Posts: 3
Joined: 11 Mar 2010, 16:39

New to SmartFoxServer

Postby gatillian » 11 Mar 2010, 16:50

Hi everybody.

I'm new to using SmartFoxServer and I would like to know what is the best way to setup an "easy" multiplayer game.

So far, using tutorials from the Internet (and a little bit of my thinking too :wink: ) I was able to connect several users in a room correctly (everybody "sees" everybody). But all the users have the same "pre-defined" avatar.

Now I would like users to be seen through their "real" avatar, not a unique pre-defined one.

Ok, so I though the best way to do that is by creating a "uservariable" storing the id of the used avatar.
So I wrote this little code :

Code: Select all

private void OnJoinRoom(Room room) {
      GameObject avatarSelectorObject = GameObject.Find("AvatarSelector");
      AvatarIdentifier avatarSelectorScript = avatarSelectorObject.GetComponent<AvatarIdentifier>();
      
      // add custom user avatar id
      Hashtable uVars = new Hashtable();         
      uVars.Add("avatar", avatarSelectorScript.selectedAvatar);
      smartFoxClient.SetUserVariables(uVars);


But if I do :

Code: Select all

private void SpawnRemotePlayer(User user) {
      int avatarIndex = (int)user.GetVariable("avatar");
}


I get an error message saying that avatarIndex is null.

Can somebody help me? Thanks.


Edit : Actually, it seems the user variable is correctly created and set. The problem is when I try to use it, as it is defined as an "object" I can't cast it to int.
matrix211v1
Posts: 61
Joined: 16 Jan 2009, 14:48

Same Problem

Postby matrix211v1 » 17 Jun 2010, 05:27

I am having the same problem. In the Admin.swf it shows it has a value of "n" but when I use it as a int, I get:

InvalidCastException: Cannot cast from source type to destination type.

For the line:

int AvatarHair = (int)user.GetVariable("AvatarHair");

Any thoughts?

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 26 guests