Get list of all avatars in room when entering

Post here your questions about the OpenSpace 1.x or notify bugs and suggestions.

Moderators: Lapo, Bax

Spiralagnus
Posts: 7
Joined: 28 Jan 2009, 18:22

Get list of all avatars in room when entering

Postby Spiralagnus » 19 Apr 2010, 23:02

We're working on a game with OpenSpace that needs to do two things:

1. When two avatars stop on the same tile, a custom event happens that we define.

2. When the user rolls over another avatar, a pop-up menu that we create reveals information about that avatar.

To accomplish both of these tasks, we need some way for each player to have access to a list of all of the avatars in the room. I know that we can use events such as EnterTile to track an avatar's change in position, but we need the player to immediately know who all other avatars in the room are when he or she first enters the room.

Is there any way to generate such a list upon entering a room? Any suggestions would be welcome.

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

Postby Bax » 20 Apr 2010, 13:44

Simply get the list of users in the SmartFoxServer room.
Paolo Bax
The SmartFoxServer Team
Spiralagnus
Posts: 7
Joined: 28 Jan 2009, 18:22

Postby Spiralagnus » 21 Apr 2010, 13:19

Sounds like a good suggestion, but I'm a little unclear on how to do this. How do you get a list of users in a room in SFS? Please let me know.

Thanks.
User avatar
Bax
Site Admin
Posts: 4385
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 21 Apr 2010, 16:35

Please check the SmartFoxServer documentation, in particular theclient-side API: you will find the getUserList method on the Room object.
Paolo Bax
The SmartFoxServer Team
Spiralagnus
Posts: 7
Joined: 28 Jan 2009, 18:22

Postby Spiralagnus » 26 Apr 2010, 23:28

This has been extremely useful so far. Similar to this thread, I need to get the positions of all of the avatars in the room when I first enter the room. Using your advice here and the (undocumented) getAvatarMovieClipById() method described in the other thread, I've written this function, which gets called from the onAvatarMovementEnd event handler:

Code: Select all

function collisionTest():void
{
   //Get the tile I'm on
   var myTile:Tile = os.getCurrentTile();
            
   //Get the room
   var thisRoom:Room = smartFox.getActiveRoom();
         
   //Get the users in this room
   var users:Array = thisRoom.getUserList();
         
   //Test the other avatars to see if they're on the same tile   
   for (var u:String in users)
   {
      var uid:int = users[u].getID();
      var thisAv:MovieClip = OpenSpace.getAvatarMovieClipById(uid);
      //..more to come
   }
         
}


Unfortunately, running the code gives me this error:

Code: Select all

1061: Call to a possibly undefined method getAvatarMovieClipById through a reference with static type Class.


Now, I'm not clear on whether getAvatarMovieClipById is a static method or not. If I make a non-static call to the method, I get a similar error:

Code: Select all

var thisAv:MovieClip = os.getAvatarMovieClipById(uid);


produces

Code: Select all

1061: Call to a possibly undefined method getAvatarMovieClipById through a reference with static type com.smartfoxserver.openspace:OpenSpace.


I'm using the trial version of OpenSpace, and the os compiled clip that comes with the trial version is my OpenSpace instance.

Any help would be appreciated. Thanks.
User avatar
Bax
Site Admin
Posts: 4385
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 27 Apr 2010, 16:26

All the OpenSpace methods are non-static, so calling OpenSpace. getAvatarMovieClipById(uid) is wrong.
Instead var thisAv:MovieClip = os.getAvatarMovieClipById(uid) should work. Are you sure you recompiled your application correctly?
Paolo Bax
The SmartFoxServer Team
Spiralagnus
Posts: 7
Joined: 28 Jan 2009, 18:22

Postby Spiralagnus » 27 Apr 2010, 17:14

Hmmm...No, I just tried it again with the os and received the same error:

Code: Select all

1061: Call to a possibly undefined method getAvatarMovieClipById through a reference with static type com.smartfoxserver.openspace:OpenSpace.


It's interesting that an earlier line in the same function that also references the compiled clip

Code: Select all

var myTile:Tile = os.getCurrentTile();


doesn't have a problem. Is it possible that my version of the os compiled clip doesn't contain the getAvatarMovieClipById method?

It's Flash, so I'm not really sure how I could be recompiling the file incorrectly. I'll keep playing around with it on my end, but I'd welcome any additional suggestions.

Thanks.
User avatar
Bax
Site Admin
Posts: 4385
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 28 Apr 2010, 06:08

You may reinstall OpenSpace, open Flash and drag the OpenSpace component in your application's library. If you have an older version, Flash will ask you to overwrite the existing component.
Paolo Bax
The SmartFoxServer Team
Spiralagnus
Posts: 7
Joined: 28 Jan 2009, 18:22

Postby Spiralagnus » 28 Apr 2010, 16:53

I just did a fresh download of the OpenSpace v1 trial from the website. In both the FarWest_Ranch and the Slopes examples, I added this line of code in the onOpenSpaceInitialized event handler, right before the call to os.loadMap():

Code: Select all

os.getAvatarMovieClipById(3);


Both examples produced the same 1061 error message that my project was giving me. Is it possible that there's something else on my end that's causing the problem? Please let me know.

Thanks.
User avatar
Bax
Site Admin
Posts: 4385
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 29 Apr 2010, 07:48

I guess the problem might be in the trial version: that method you are using was added later, as requested by one of our customers, and probably we added it to the retail version only. Sorry, this didn't come to my mind before (also I thought you were using the retail version).
Paolo Bax
The SmartFoxServer Team
Spiralagnus
Posts: 7
Joined: 28 Jan 2009, 18:22

Postby Spiralagnus » 29 Apr 2010, 12:01

Fair enough. However, I still need to get the positions of every avatar in the room when I first enter the room. Is there a way to do this within the limitations of the trial version? Please let me know.

Thanks.
User avatar
Bax
Site Admin
Posts: 4385
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 29 Apr 2010, 19:45

Actually not, sorry.
Paolo Bax
The SmartFoxServer Team

Return to “OpenSpace v1 discussions and help”

Who is online

Users browsing this forum: No registered users and 1 guest