Page 1 of 1

SetVariables Issues

Posted: 24 Apr 2009, 12:32
by matrix211v1
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?

Calling Incorrectly

Posted: 24 Apr 2009, 14:29
by matrix211v1
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
   }

Posted: 25 Apr 2009, 05:49
by ThomasLund
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