User Variables set on the client

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

Moderators: Lapo, Bax

Post Reply
peter.dalton
Posts: 11
Joined: 10 Aug 2010, 21:51

User Variables set on the client

Post by peter.dalton »

I'm trying to create a User variable on the client using the c# interface however I never see the value get broadcasted up to the server and other clients.

Code: Select all

UserVariable var = new SFSUserVariable( "testVar", true );
m_smartFox.MySelf.SetVariable( var );
So my question is, are User and Room variables only passed around if they are set within the java server side extensions? Are all variables set on the client only stored locally? Or is there a way to set a variable from the client that is broadcasted to everyone?

If the variables are only local if set on the client I would recommend changing the API to something like: 'SetLocalVariable()' and don't have a method like 'SetVariable()' to help avoid confusion.

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

Post by Lapo »

UserVariables are not local.
If you set your variables when you are in a Room all other users in that Room will receive the update.
It's as simple as that.
Lapo
--
gotoAndPlay()
...addicted to flash games
peter.dalton
Posts: 11
Joined: 10 Aug 2010, 21:51

Post by peter.dalton »

I guess where I'm confused is that I set the variable using the code snippet above and then use the admin tools to monitor the user. The user is definitely in the room before the variable is created however the admin tools don't show the user having any variables when I monitor him. Is the admin tool not fully functional in this aspect yet? Or is there something else that I'm missing?

When I start up SmartFox in debug mode I don't see any output in my console window related to messages being transmitted to the server when the variables are set. I would expect the variables to be sent to the server so that the server can see the state of the variables.


Thanks,

- Peter
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Oh sorry.
there's absolutely a problem in the code. Didn't notice it at first. :(
That's not the way you set variables, you always need to send a request to the server.
You must use SetUserVariablesRequest or SetRoomVariablesRequest (for RoomVars) which you find under the requests package. That's the way you use to set/change any of those variables.

The way you are doing it now you are just hacking around with the local API data.
Lapo
--
gotoAndPlay()
...addicted to flash games
peter.dalton
Posts: 11
Joined: 10 Aug 2010, 21:51

Post by peter.dalton »

Thanks, that fixed my problem.

- Peter
tpenn
Posts: 95
Joined: 03 Aug 2010, 18:48

Post by tpenn »

Is there any reason we would ever want to call User.SetUserVariable then?

If not and we are meant to only do that by sending a request to the server, I'd suggest that function not be exposed to us; it can only cause confusion.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Yes, that's in fact what we'll do.
The function is exclusively used by the API internally. In the beta docs there's still a few of these private stuff that needs to be removed. Sorry about that.
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply