SetUserVariables doesn't seem to be applying.

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

Moderators: Lapo, Bax

burnumd
Posts: 1
Joined: 04 Aug 2009, 18:04
Contact:

SetUserVariables doesn't seem to be applying.

Postby burnumd » 04 Aug 2009, 18:40

Hi all, I'm evaluating SFS for use with future Unity projects, and right now I'm running through the Flash-based examples and trying to convert them to Unity. One more caveat, I'm doing it in the Javascript-y flavor of Unity scripting to see if it works and also because most of our script library is in that language and we'd like to see if SFS will play nice with that. At any rate, I'm trying to convert the "Avatar Chat" example to a 3D avatar chat example, and I'm having trouble keeping track of avatar positions. In the SmartFox class, I handle creating avatars on joining a room, and none of the other users have any variables associated with them when I run the following (where user is any given User from the room's userlist):

Code: Select all

if (user.GetId() != client.myUserId) {
    var uVars : Hashtable = user.GetVariables();
    var debugString : String = "User " + user.GetId() + " variables: ";
    for (var uVar : String in uVars.Keys) {
       debugString += uVar + ", ";
    }
    Debug.Log(debugString);
    // ... and so on

The debug statement shows no variables for the user. In the same function, after other player's avatars are created locally, I instantiate a localAvatar with the FPSWalker and the following script attached:

Code: Select all

var smartFox : SmartFox;
var myPos : Hashtable = new Hashtable();
var myOldPos : Vector3;

function Awake () : void {
   smartFox = GameObject.FindObjectOfType(SmartFox);
   myOldPos = transform.position;
}

function Start () : void {
   myPos.Add("px", transform.position.x);
   myPos.Add("py", transform.position.y);
   myPos.Add("pz", transform.position.z);
   smartFox.client.SetUserVariables(myPos);
}

function FixedUpdate () : void {
   if (myOldPos != transform.position) {
      myPos["px"] = transform.position.x;
      myPos["py"] = transform.position.y;
      myPos["pz"] = transform.position.z;
                smartFox.client.myRoom.GetUser(smartFox.client.myUserId).SetVariables(myPos);
      myOldPos = transform.position;
   }
}


Am I doing something wrong in setting user variables? I couldn't find an example of setting user vars in the Unity specific tutorials, so I'd appreciate any guidance in the matter. Thanks in advance.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 08 Aug 2009, 07:51

Hi!

First off, I really really havent tested or used SFS API through Unitys JavaScript myself ever - others have reported mixed experiences with it. Primarily trouble on the registering/deregistering of delegates.

Theoretically it _should_ work, but its totally untested and unsupported - so you are slightly on your own there with the help of anyone here.

User variables is something I dont use myself, so besides them working in general tests - I cant help on the finer details. Others here on the forums have had success with them though.

The code itself in the API requires you to:
* have joined a room
* have received a room list

Do you in OnDebugMessage see it send the user variables?!

/Thomas

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 19 guests