unity3 and smartfox user variables

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

Moderators: Lapo, Bax

appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

unity3 and smartfox user variables

Postby appels » 15 Oct 2010, 13:45

Hi,

I'm trying to use user variables in SmartFox to spawn my player's avatar type but it's working for now.
what i have is this :

Code: Select all

   void onUserEnterRoom(int roomId, User user) {
      Hashtable uVars = new Hashtable();
      uVars = user.GetVariables();
      aTypes.Add(user.GetId(), uVars["avatarType"]);


As soon as a player enters the room, i retrieve the variables.
That part works fine when i debug it.
Now in my remote player spawn function i try this :

Code: Select all

string tmp = GetVars.aTypes[user.GetId()].ToString();


but when i do that i get following error from unity :

NullReferenceException: Object reference not set to an instance of an object
PlayerSpawnController.SpawnRemotePlayer (SmartFoxClientAPI.Data.User user) (at Assets/Scripts/PlayerSpawnController.cs:52)
PlayerSpawnController.SpawnRemotePlayers () (at Assets/Scripts/PlayerSpawnController.cs:45)
PlayerSpawnController.SpawnPlayers () (at Assets/Scripts/PlayerSpawnController.cs:22)
UnityEngine.Component:SendMessage(String)
GetVars:OnJoinRoom(Room) (at Assets/Scripts/GetVars.cs:52)
SmartFoxClientAPI.SmartFoxClient:_DispatchEvent(SFSEvent)
SmartFoxClientAPI.SmartFoxClient:ProcessEventQueue()
GetVars:FixedUpdate() (at Assets/Scripts/GetVars.cs:47)


Anyone have an idea ?
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC
Contact:

Re: unity3 and smartfox user variables

Postby Carl Lydon » 05 Aug 2012, 17:47

I get the same thing in SFS2X unity C#
The docs are not good.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: unity3 and smartfox user variables

Postby rjgtav » 07 Aug 2012, 09:55

Hi.
Have you checked the Object Movement example, which shows how to set and retrieve user variables?

[EDIT]
You can also check this topic:
viewtopic.php?f=20&t=14614
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC
Contact:

Re: unity3 and smartfox user variables

Postby Carl Lydon » 07 Aug 2012, 17:42

I just switched to retrieving the variables individually, instead of using getVars and now it works.

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 1 guest