SetVariables Issues

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

Moderators: Lapo, Bax

matrix211v1
Posts: 61
Joined: 16 Jan 2009, 14:48

SetVariables Issues

Postby matrix211v1 » 24 Apr 2009, 12:32

Has anyone got "SetVariables" to work?

Using the Island Demo, I am trying to do is "SetVariables" for the LocalSpawnPlayer so when the next person logs in, and it loops to set the RemoteSpawnPlayer, it will show the values I set for that User.

Also, when I log into the AdminTool of SmartFoxServer, I don't see any values set.

Here is a sample code:

Code: Select all

   private void SpawnLocalPlayer() {

      int n = spawnPoints.Length;

      String colorChoice;
      String characterType;
      
      SetCharacterInfo myTest;
      myTest = GameObject.Find("PivotParams").GetComponent(typeof(SetCharacterInfo)) as SetCharacterInfo;

      SmartFoxClient client = NetworkController.GetClient();
      Hashtable myUserList = client.GetActiveRoom().GetUserList();
      User myUser = (User)myUserList[client.myUserId];
      Hashtable myHashtable = new Hashtable();
      
      colorChoice = myTest.colorChoice;
      characterType = myTest.characterType;
      
      myHashtable.Add("colorChoice", colorChoice);
      myHashtable.Add("characterType", characterType);

      myUser.SetVariables (myHashtable);
      
      Debug.Log("myUser.characterType: "+myUser.GetVariable("characterType"));
      Debug.Log("myUser.colorChoice: "+myUser.GetVariable("colorChoice"));
   
      Transform spawnPoint = spawnPoints[random.Next(n)];
      localPlayerObject.transform.position = spawnPoint.transform.position;
      localPlayerObject.transform.rotation = spawnPoint.transform.rotation;
      localPlayerObject.SendMessage("StartSending");  // Start sending our transform to other players
   }


It works locally, but not across the network.

Any thoughts?
matrix211v1
Posts: 61
Joined: 16 Jan 2009, 14:48

Calling Incorrectly

Postby matrix211v1 » 24 Apr 2009, 14:29

It seems that I was calling the wrong function for what I wanted to do. Here is the correct version:

Code: Select all

   private void SpawnLocalPlayer() {

      int n = spawnPoints.Length;

      String colorChoice;
      String characterType;
      
      SmartFoxClient client = NetworkController.GetClient();

      SetCharacterInfo myTest;
      
      myTest = GameObject.Find("PivotParams").GetComponent(typeof(SetCharacterInfo)) as SetCharacterInfo;

      colorChoice = myTest.colorChoice;
      characterType = myTest.characterType;
      
      Hashtable myHashtable = new Hashtable();
      myHashtable.Add("colorChoice", colorChoice);
      myHashtable.Add("characterType", characterType);
      client.SetUserVariables(myHashtable);
    
      Transform spawnPoint = spawnPoints[random.Next(n)];
      localPlayerObject.transform.position = spawnPoint.transform.position;
      localPlayerObject.transform.rotation = spawnPoint.transform.rotation;
      localPlayerObject.SendMessage("StartSending");  // Start sending our transform to other players
   }
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 25 Apr 2009, 05:49

Hi
Super you found the issue yourself.

I will check the API code and see if I can remove the setter from the public interface, so that others wont be tempted to use it.

As you found, you need to use the client commands and not set variables directly on objects. There is no automation at all on those object methods!

Best
Thomas

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 18 guests