Get name by id
Get name by id
Hi guys, is there a way to get the name of a user from his id?
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.
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.
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.
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