Problems with getUserList

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

Moderators: Lapo, Bax

User avatar
ccontinisio
Posts: 32
Joined: 21 Nov 2007, 13:18
Location: Rome, Italy
Contact:

Problems with getUserList

Postby ccontinisio » 22 Feb 2008, 17:02

I banged my head all day on this one...

Code: Select all

SF.onRoomListUpdate = function(roomList:Object){
   for (var r in roomList){ //cycle trough all the rooms
      var stanza:Room = roomList[r]; //get on of the rooms
      trace("Name: " + stanza.getName() + " no. " + stanza.getUserCount() + "\n");
      var amici:Object = stanza.getUserList(); //get the user list
      for (var u in amici){
         trace(amici[u] + "\n");
      }
   }
}

When I trace the room name or the count of users I get normal results (like... "Lobby" and "2", "3"... ) but when I try to access the user list I get a heck of a lot of undefined...
It seems like he gets an empty user list, because he doesn't enter in the for cycle at all... Why??
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 22 Feb 2008, 17:33

make a trace on your u var

Code: Select all

for (var u in amici){
   trace(u)
   trace(amici[u] + "\n");
}


I had a similar problem not long ago and it turns out I had declared prototypes for arrays, witch was always being assigned whenever I pulled out a user or room list.
Solution:
Make a if to filter those prototypes:

Code: Select all

if (u != "search" && u != "copy" && u != "indexOf"){
   trace(amici[u] + "\n");
}

But I don't know, that was just me. Maybe it is something else.
User avatar
ccontinisio
Posts: 32
Joined: 21 Nov 2007, 13:18
Location: Rome, Italy
Contact:

Postby ccontinisio » 22 Feb 2008, 19:32

I don't think it's my case... Anyway, I used the "for (var u in amici)" structure to browse the object because I don't know any other method... do you know how can I look at the properties of an object without using the "for" method?
User avatar
Bax
Site Admin
Posts: 4495
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 23 Feb 2008, 11:23

When you receive the onRoomListUpdate event, you just have access to the room objects, but not to their inner list of users. You can acccedss the list of users only for the room you joined, but when you receive that event, you probably have to join one yet.
Paolo Bax
The SmartFoxServer Team
User avatar
ccontinisio
Posts: 32
Joined: 21 Nov 2007, 13:18
Location: Rome, Italy
Contact:

Postby ccontinisio » 24 Feb 2008, 02:26

Thank you Paolo, but so, how can I get the list of users? I need to get it in order to implement a buddy list...
I have the usernames of my friends in the database. I log in, I get them from the database and then I need the user list to see if some of those names are actually connected, so I can show their online status.
How can I do this without using the Smartfox buddylist features?
User avatar
Bax
Site Admin
Posts: 4495
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 24 Feb 2008, 14:01

You will have to handle this in a server-side extension. But why don't you use the SFS built-in buddy list capabilities?
Paolo Bax
The SmartFoxServer Team
User avatar
ccontinisio
Posts: 32
Joined: 21 Nov 2007, 13:18
Location: Rome, Italy
Contact:

Postby ccontinisio » 24 Feb 2008, 17:02

Well, everytime I use a new feature I must work some days to cope with the problems, I was trying to avoid that. I'll try anyway.
Thanks
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 25 Feb 2008, 13:23

U -could- make it so every user log into a "main room". Then make them go to another room without leaving the main room (lets say, the lobby). Then set a user variable named "location" and whenever that user goes to another room (from lobby to kitchen), u change that variable and capture the event with onUserVariableChange
User avatar
ccontinisio
Posts: 32
Joined: 21 Nov 2007, 13:18
Location: Rome, Italy
Contact:

Postby ccontinisio » 27 Feb 2008, 17:15

Thank you mistermind, but this was not the thing I wanted to accomplish.
Anyway I found another way using the integrated Buddy Lists, which are problematic all the same...

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 16 guests