Uservariables FloatArray

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

LuffyGray
Posts: 32
Joined: 06 Feb 2017, 16:01

Uservariables FloatArray

Postby LuffyGray » 25 Mar 2017, 02:04

I've been using my uservariables for positional data which I use like this;

Code: Select all

userVariables.Add (new SFSUserVariable ("x", (double)_tempPos.x));
               userVariables.Add (new SFSUserVariable ("y", (double)_tempPos.y));
               userVariables.Add (new SFSUserVariable ("z", (double)_tempPos.z));


So to condense the amount of variables and possible overhead I decided to push data to an SFSArray so I could store the entire vector in a single variable but I'm getting odd results, my data isn't coming back correct and players are flying all over the place.

Here is an example of the sending and recieving of my data:

Sending:

Code: Select all

            //Rig position
            if (localPlayer.transform.position != lastPosRig) {

               _tempPos = localPlayer.transform.position;

               _cordArray [0] = _tempPos.x;
               _cordArray [1] = _tempPos.y;
               _cordArray [2] = _tempPos.z;

               SFSArray _dataArray = new SFSArray ();
               _dataArray.AddFloatArray (_cordArray);

               userVariables.Add (new SFSUserVariable ("xyz", _dataArray));
               lastPosRig = _tempPos;
               hasChanged = true;

            }


Recieving:

Code: Select all

      //Rig Position
      if (_changedVars.Contains ("xyz")) {

         _newData = _userData.GetVariable ("xyz").GetSFSArrayValue ().GetFloatArray (0);
         remotePlayers [_userData.Name].rigInterp.SetPosition (new Vector3 ((float)_newData[0],  (float)_newData[1],  (float)_newData[2]),  true);

      }
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Uservariables FloatArray

Postby Lapo » 25 Mar 2017, 09:14

For starters I don't think this is useful optimization. At least not for 3 values. If you had 10 or more values it could help but for three you're adding overhead by wrapping an array of floats into an SFSArray into a UserVariable.

Other than that, to fully understand what might be going on I need to see the debug of the received SFSArray.
In other words:

Code: Select all

Debug.Log(_userData.GetVariable ("xyz").GetSFSArrayValue ().GetDump())


Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 53 guests