Updating userList, playerList client side with AS3

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

Post Reply
protodaniel
Posts: 1
Joined: 17 Jan 2011, 21:53
Contact:

Updating userList, playerList client side with AS3

Post by protodaniel »

Hi guys,

I'm new to multiplayer game development and I'm trying to wrap my head around the optimization that needs to be in place.

I've noticed that the data for a room rarely gets updated client side beyond the User count change. So userList, and playerList will return empty after a JoinRoom event even if the userCount shows the right number of users on a Room.

I'm trying to create a game with 4 rooms, 2 players per room (for testing) and I would like to display the names of the players in each room so the user can choose to join a known friend (probably not good practice with potentially gazillion users and rooms) is there a way to do this on the client side or do I need to do a java extension?

Thank you!

- D.
wajdiazar
Posts: 6
Joined: 17 Jan 2011, 11:19
Location: Jordan

Post by wajdiazar »

hi,

i had this problem before but i solve it this way:

you put eventlistener for User Count Change

sfs.addEventListener(SFSEvent.onUserCountChange, usersCountUpdated);


private function usersCountUpdated(e:SFSEvent)
{
//selectedRoom is a public variable that i create to save the name of the selected room
var users = sfs.getRoomByName(selectedRoom).getUserList();
//users now is object that holds all users in our room
updataUsersList(users);

}

private function updataUsersList(users)
{
var list:List = usersAv;// users list UIComponent
list.removeAll();

for (var i in users)
{
if (users.getName().indexOf(thisUser) < 0)
{
var obj:Object = new Object();
obj.name = users.getName();
obj.id = users.getId();
obj.label = users.getName();
list.addItem(obj);
}
}
}

i hope this help :)
love
nunobarao
Posts: 36
Joined: 21 Mar 2011, 19:41

Post by nunobarao »

Hi wajdiazar, iv tried your code but it trace an error .getName , it is necessary to create any extension for this? or the error is for somethingeles?

Thank you
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

The list of users inside a Room can be retrieved on the client only if it joined the same Room. Otherwise you have to go your own way using a server-side Extension.
Paolo Bax
The SmartFoxServer Team
Post Reply