determine room user is in when USER_VARIABLES_UPDATE fires

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
levancho
Posts: 71
Joined: 27 Jun 2011, 16:03

determine room user is in when USER_VARIABLES_UPDATE fires

Postby levancho » 22 Feb 2012, 11:44

Hi,
I have case where user can be in more than one room at the same time,
so whenever USER_VARIABLES_UPDATE is fired in my listener I need to obtain the room that is relative to that event, problem is that if I use

Code: Select all

User player = (User) event.getParameter(SFSEventParam.USER);
       curRoom = player.getLastJoinedRoom();   


not gonna work because user can join room A and the join room B and fire event from room A,

so call to getLastJoinedRoom will return room B even though event was related to room A, so what would be the best approach to solve this ?


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

Re: determine room user is in when USER_VARIABLES_UPDATE fir

Postby rjgtav » 22 Feb 2012, 12:08

Hi.
Hmm... In this case, I think the best scenario is to send a custom ExtensionRequest instead of a setUserVariablesRequest, and then send the roomId as one of the parameters.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
levancho
Posts: 71
Joined: 27 Jun 2011, 16:03

Re: determine room user is in when USER_VARIABLES_UPDATE fir

Postby levancho » 22 Feb 2012, 12:21

yeah, I was afraid that would be the option too,

can I make this as a feature request ? I think it is a reasonable to have a room identification as a parameter in Event object.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: determine room user is in when USER_VARIABLES_UPDATE fir

Postby Lapo » 22 Feb 2012, 14:06

There is a conceptual problem here.
UserVariables are properties linked to a User not to a Room.

Example:
User Piggy is joined in RoomA and RoomB at the same time. User Piggy updates her variables --> all other Users that can "see" Piggy will receive an update with the new Piggy's values. (which means: All Users in RoomA + all in Room B)
Question: where did the UserVariable update originate from? There is no such information, because it's the user variables that change regardless of the Room in which the owner is in.

I can understand your use case and I think that your application should know which variables should be tracked from a certain Room or not. In other words if you have a player that is in the Lobby and a GameRoom at the same time you can easily detect if a certain variable is related to a change of the User's state in the game room or not.
This alone should solve the problem.

If it doesn't then I think you should review your game logic and think of using RoomVariables instead. If you need to link certain User's state to specific Rooms that's probably the best way to do it. This will also optimize the server updates because RoomVariables are seen only in the Room where they are created (unless you set them as global)

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
levancho
Posts: 71
Joined: 27 Jun 2011, 16:03

Re: determine room user is in when USER_VARIABLES_UPDATE fir

Postby levancho » 22 Feb 2012, 14:48

HI ,

ahaaa, that opened up a different direction for me and I think i can easy adjust logic to follow your suggestion,
thanks for your prompt reply
Kind Regards
Levancho.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Baidu [Spider] and 85 guests