Get name by id

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

Moderators: Lapo, Bax

User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Get name by id

Postby rjgtav » 07 Apr 2010, 09:59

Hi guys, is there a way to get the name of a user from his id?
smoochict
Posts: 53
Joined: 18 Mar 2010, 06:21

Postby smoochict » 07 Apr 2010, 10:08

Hello,

You can get the user object from its name:

var userobj = zone.getUserByName(username)
Then get its id by:
var userid = userobj.getUserId()

But i'm not sure if theres a way to get the username from the id.

Java:
int userid = zone.getUserIdByName(username); // get user id from name

User userobj = zone.getUserByName(username); //gets user object by name

String username = userobj.getName(); //gets username

As i said, i don't think theres a way of getting the name of the user from the id, you would need to get the user object some how from the id, then retrieve the name.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 07 Apr 2010, 10:20

ok thanks. and do you know how to get roomVariables from this.getActiveRoom()?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 07 Apr 2010, 10:24

sorry, i have already found a way. My script wasn't working because of a misspelled variable.
smoochict
Posts: 53
Joined: 18 Mar 2010, 06:21

Postby smoochict » 07 Apr 2010, 10:24

If this.getActiveRoom();
returns a room object, you should be able to do:


String variable = roomobj.getVariable("variablename");

However i'v never used that, though if your looking to get a number it would perhaps be best to use:

int variable = roomobj.getVariable("variablename");

etc etc.

If this.getactiveroom(); returns a room name, you could do:

Room roomobj = zone.getRoomByName("roomname");

instead.

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 30 guests