Page 1 of 1
SFSObject as UserVariable
Posted: 28 Oct 2014, 21:32
by oalasergiu
Hi,
I've been trying to set a SFSObject as an UserVariable on the server and play with it.
So, on the server side I have something like:
Code: Select all
ISFSObject score = new SFSObject();
score.putInt("wins", 20);
score.putLong("points", 800);
List<UserVariable> uvList = new ArrayList<>();
uvList.add(new SFSUserVariable("score", score));
someUser.setVariables(uvList);
Client:
Code: Select all
Debug.Log("Wins: " + thatUser.GetVariable("score").GetSFSObjectValue().GetInt("wins");
And I'm getting null on client. I've debugged the script, and instead of my SFSObject there, I have a score variable which is the last set value in SFSObject. In the above case it is score = 800;
Now I wonder, is it possible to set SFSObjects as UserVariables and use them on Client Side?
Thanks.
Re: SFSObject as UserVariable
Posted: 29 Oct 2014, 09:10
by Lapo
Yes, what you are doing is fine.
What server version are you using? What version of the C# API?
Do you get any server or client side errors?
Thanks
Re: SFSObject as UserVariable
Posted: 29 Oct 2014, 16:38
by oalasergiu
Server Version: Version 2.7.0.
C# Client API: 1.4.0.0
I didn't notice any errors on client/server.
However, I'll check again when I'm home. Though, I've debugged the extension, and it seems like the SFSObject variable is set to the user.
Re: SFSObject as UserVariable
Posted: 29 Oct 2014, 18:46
by oalasergiu
No errors, I've checked.
Also, I've updated the client API to 1.5.3 and it didn't solve the problem.
Re: SFSObject as UserVariable
Posted: 30 Oct 2014, 18:47
by Bax
I'm not able to reproduce the issue you mentioned.
This is the code I'm using on the server side:
Code: Select all
// Set user variable containing a SFSObject
ISFSObject score = new SFSObject();
score.putInt("wins", 20);
score.putLong("points", 800);
List<UserVariable> uvList = new ArrayList<UserVariable>();
uvList.add(new SFSUserVariable("score", score));
getApi().setUserVariables(sender, uvList);
And this is the code I'm using on the client side
Code: Select all
private void OnUserVarsUpdate(BaseEvent evt)
{
ArrayList changed = (ArrayList) evt.Params["changedVars"];
if (changed.Contains ("score")) {
User user = (User)evt.Params ["user"];
UserVariable scoreVar = user.GetVariable ("score");
ISFSObject obj = scoreVar.GetSFSObjectValue ();
Trace (obj.GetInt ("wins").ToString ());
Trace (obj.GetLong ("points").ToString ());
}
}
Please note that you can't set the User Variable directly on the User object, but you have to use the API's
setUserVariables method.
Re: SFSObject as UserVariable
Posted: 30 Oct 2014, 19:11
by oalasergiu
Hi Bax,
I've tried using "getApi().." as you suggested. It didn't work.
Some more information, I'm setting the variables when user joins a zone. Can this be the problem?
Also, on client, I'm not doing this inside a OnUserVarsUpdate method.
To clarify the flow:
1. User login.
2. Join zone.
3. The server sets the varibales.
4. User gets into a game scene.
5. In the game scene, I'm trying to access the score variable.
And I can get other primitive variables like int or string, but not the SFSObject.

Re: SFSObject as UserVariable
Posted: 30 Oct 2014, 19:26
by Lapo
I would suggest to check if the variables are really set as expected via the AdminTool > ZoneMonitor.
From there navigate the Zone, Room and User and check his variables.
Re: SFSObject as UserVariable
Posted: 30 Oct 2014, 19:35
by oalasergiu
Hmm... Via the admin tool as you suggested, I see the score variable of type INT, which must have been of type SFSObject.
Re: SFSObject as UserVariable
Posted: 30 Oct 2014, 19:46
by Lapo
Then something is not right with your code setting those variables. Or you have multiple places in the code (either client or server) that overwrite the variable.
I'd suggest to investigate that aspect.
cheers
Re: SFSObject as UserVariable
Posted: 30 Oct 2014, 19:50
by oalasergiu
Damn it! I found the problem...
The score variable have been overridden in some other place
Sorry for taking your time.
However I find the getApi().setUserVariables() useful.
Thanks.