What happens first? onJoinRoom or onUserEnterRoom?

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

Moderators: Lapo, Bax

capdetrons
Posts: 72
Joined: 24 Aug 2013, 09:15
Location: Barcelona
Contact:

What happens first? onJoinRoom or onUserEnterRoom?

Postby capdetrons » 02 Jan 2015, 12:14

HI,

I'm very confused again.

All I'm trying to do is add an icon in the userList panel so I created a user variable and retrieved it in the onJoinroom function but only one client gets the update. The second one...

I placed this code in the onJoinRoom function:

Code: Select all

smartfox.onJoinRoom = function(roomObj:Room) {
   var userList:Object = roomObj.getUserList();
   chat_txt.htmlText = "";
   
   userList_lb.removeAll();
   
   for (var i in userList) {
      var user:User = userList[i];
      var uName = user.getName();
      var uId = user.getId();
      
   if(uName != _global.myName){
      var uVars:Object = user.getVariables();
      userList_lb.addItem({icon:uVars.gender, data:uId, label:uName});
   } else {
         userList_lb.addItem({icon:gender, data:uId, label:uName});
      }
      userList_lb.iconField = "icon";
   }
   
   userList_lb.sortItemsBy("label", "ASC");
   chat_txt.htmlText += "<font color='#cc0000'>>> Room [ "+roomObj.getName()+" ] joined</font>";
   
   setupMyUser();
}

function setupMyUser() {
      smartfox.setUserVariables({gender:gender});
}


Should I do the same in onUserEnterRoom perhaps or include the onUserVariablesUpdate in the code?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: What happens first? onJoinRoom or onUserEnterRoom?

Postby Lapo » 14 Jan 2015, 21:24

They are different events. JoinRoom is the event that tells you your client has joined a Room.
UserEnterRoom tells you another user has just joined a Room in which you're joined.

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
capdetrons
Posts: 72
Joined: 24 Aug 2013, 09:15
Location: Barcelona
Contact:

Re: What happens first? onJoinRoom or onUserEnterRoom?

Postby capdetrons » 17 Feb 2015, 12:13

Thanks, Lapo, I hadn't seen the reply and kept working on my problem which I still haven't been able to solve.

I have:

Code: Select all

userList_lb.removeAll();
   for (var i in userList) {
      var user:User = userList[i];
      var uName:String = user.getName();
      var uId:Number = user.getId();
      if (uName == _global.myName) {
         var uVars:Object = user.getVariables();
         trace(newline+"uVars.gender = "+uVars.gender);
         userList_lb.addItem({icon:uVars.gender, label:uName, data:uId});
      } else {
         userList_lb.addItem({icon:gender, label:uName, data:uId});
      }
   }
   userList_lb.iconField = "icon";
   userList_lb.sortItemsBy("label", "ASC");
}
on onJoinRoom right after having set the user variable, but it's bot showing the first user's updated icon.

Perhaps a room variable would be better?

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 46 guests