...ok and getting user variables?

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
Tom
Posts: 20
Joined: 27 Apr 2007, 21:04

...ok and getting user variables?

Post by Tom »

Not seeming to have much luck here..
reading the API I see a function "getVariable" and "getVariables" but Flex keeps telling me those methods don't exist and upon opening the actionscript files for SmartFoxClient ... I can't seem to to find those methods either.

also I added an event listener to listen for user variable updates ... then in the function that gets called i just put in trace("updated") ... so while debugging I don't see that "updated" appear in the console, but I see lines (on every frame because that's how/when I'm updating my user variables with an enter frame even listener) -- anyway i see the lines saying "[Sending]: <msg t= ....." blah blah blah . and under the admin tool i can refresh and see updatinng variables. cool!

but i can't seem to now access those variables... not through an event listener for when those variables are being updated/stored and not by using the method "getVariable" or "getVariables"

i think everything has been fairly straight forward here and again I love SFS, but is it possible that the AS3 API isn't complete? do i have an old version maybe? i downloaded the one for Flash CS3 (and am using the one for Flex...the swc)
Tom
Posts: 20
Joined: 27 Apr 2007, 21:04

Post by Tom »

ok well i realized i was accessing the wrong class =0

but still ... i can't return variables ... just got the errors to all go away.
i CAN get my user name etc. through the user class but no variables.

yet the admin tool shows variables..


(also the console shows the "[Sending]" AND "[RECEIVED]" info -- so it's going there and updating, etc. even calls the event handler -- but i still can't figure out how to get the data, tracing something like: sfsUser.getVariables() doesn't seem to work)
Tom
Posts: 20
Joined: 27 Apr 2007, 21:04

Post by Tom »

[ RECEIVED ]: <msg t='sys'><body action='uVarsUpdate' r='10'><user id='140' /><vars><var n='myAvatar' t='s'><![CDATA[Tom]]></var><var n='posy' t='n'><![CDATA[298.16160615194735]]></var><var n='posx' t='n'><![CDATA[124.38240634389908]]></var></vars></body></msg>, (len: 247)
something updated

that's from my console ... no fair my console can read the data but i can't =(
lol

and "something updated" is from trace("something updated"); that I put in the listener for when user variables update...

i've instantiated a user object... called it sfsUser

so sfsUser.getVariables()
right?

trace(sfsUser.getVariables());

nothing

var theVars = sfsUser.getVariables();
trace(theVars);

nothing

i'm a noob I know. lol
Tom
Posts: 20
Joined: 27 Apr 2007, 21:04

Post by Tom »

really trying to read the documentation too... but the avatar chat example in the documentation doesn't use getVariables anywhere -- ... it seems like it was calling upon some user.variables - but that doesn't seem to be a property that i can access...
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

Tom, you said:
i've instantiated a user object... called it sfsUser
What do you mean? You should not instantiate a new user object, but simply retrieve it from the the users list, or from parameters passed with events.
Can you show the code used to create sfsUser?
Paolo Bax
The SmartFoxServer Team
Tom
Posts: 20
Joined: 27 Apr 2007, 21:04

Post by Tom »

i've tried both:

sfsUser = new User(sfs.myUserId, sfs.myUserName);
(in hopes to retrieve the user's own variables which i guess is silly because if you're setting them to begin with you know what they are)

and so i also tried

sfsUser = new User(173, "Tom");
(manually setting it to the other player which I guess ultimately I can get from a user list, but I set it to manually test)

then I'll run

sfsUser.getVariables() ... hoping to return the variables for user 173...

but doesn't return anything. yet i see the variables updating in the admin tool for user 173...

how do you run getVariables without setting up a new user object?
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

Tom, you can't create a new user!
You should do something like this:

Code: Select all

sfsUser = room.getUser(3)
where 3 is the user id, and "room" is the Room object in which user 3 is inside. The room object is passed by a number of events, or you can retrieve it like this (for example):

Code: Select all

sfs.getActiveRoom()
And, btw, you can't retrive the variables of your own user, as you should already know them when you set them).
Paolo Bax
The SmartFoxServer Team
Tom
Posts: 20
Joined: 27 Apr 2007, 21:04

Post by Tom »

thanks for all your help.
still confused but i'll give it a go here real quick.

Code: Select all

var room:Object = sfs.getActiveRoom();
	 
sfsUser = room.getUser(1) ;
	 
var userVars:Array = sfsUser.getVariables();
	 
trace(userVars);
that didn't seem to return al ist of variables... there is a user id 1 when i look in the admin tool...
Last edited by Tom on 04 Jun 2007, 17:31, edited 1 time in total.
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

Tom wrote:so you never have to use the method getVariables?

when does that come into play?
Sorry, it seems I haven't been clear... after you get an existing user (see my previous post), then you can retrieve his variables using the methods .getVariable or .getVariables
Paolo Bax
The SmartFoxServer Team
Tom
Posts: 20
Joined: 27 Apr 2007, 21:04

Post by Tom »

sorry was playing around with my post which i didn't expect you to catch so quickly :)
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

This should be the working code:

Code: Select all

var room:Room = sfs.getActiveRoom();
   
var sfsUser:User = room.getUser(1);
   
var userVars:Object = sfsUser.getVariables();

for (var k:String in userVars)
    trace(k + " -> " + userVars[k]);
Also, are you sure that user 1 has some variables set?
Paolo Bax
The SmartFoxServer Team
Tom
Posts: 20
Joined: 27 Apr 2007, 21:04

Post by Tom »

ah groovy it works! thank you sooo much you have no idea how hard i was banging my head over this.

thank you VERY MUCH for your time.

i knew it was probably something simple. just a few lines of code, but i couldn't find many examples in the documentation... they were a bit more complex than what i was after. i was just after a very specific (maybe limited) thing.

thanks again.
Post Reply