User.getId() / user.getName() / Add a new one???

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

Moderators: Lapo, Bax

poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

User.getId() / user.getName() / Add a new one???

Postby poppop » 19 Aug 2007, 19:51

Hello,

is it possible to add a new User."Command"

i really need User.Age() , User.Sex(), etc

How easy is it to add this, i've looked in the advanced chat example, but cannot see where the User object is made, or how to edit it.


Many thanks.
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 20 Aug 2007, 07:57

You can't add properties or methods to the User object.
But you can use the userVariables to add properties to each user. Check the "Avatar chat" tutorial in the online documentation.
Paolo Bax
The SmartFoxServer Team
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Postby poppop » 20 Aug 2007, 22:15

Thanks for the reply bax,

I cannot seem to get the "getVariable" to work, I tried the following:

Code: Select all

smartfox.joinRoom(roomName)
smartfox.setUserVariables({age:"26",team:"16",init:true})


Then, in the onPublicMessage function, i want to access these varibles, from the "user" sending the message, not the "onUserVariablesUpdate" function. As once these varibles are set, they will not be updated again.

I tried the following:

Code: Select all

smartfox.onPublicMessage = function(msg:String, user:User)
{
   chat_txt.htmlText += "<b>" + user.getName() + ": </b> " + user.getVariable('team') + msg
   main_sb.setScrollPosition(chat_txt.maxscroll)
}


All i get is undefined???

Please help.

working with smartfox so far is great, and the help on this forum is perfect! :)
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 21 Aug 2007, 07:05

poppop wrote:I cannot seem to get the "getVariable" to work, I tried the following:

Code: Select all

smartfox.joinRoom(roomName)
smartfox.setUserVariables({age:"26",team:"16",init:true})


This is wrong: you need to wait to be joined successfully into a room (so the onJoinRoom event) before setting the user variables.
Paolo Bax
The SmartFoxServer Team
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Postby poppop » 21 Aug 2007, 13:24

Sweet mate!!

Thanks so much! :P

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 52 guests