u.getName

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

Moderators: Lapo, Bax

ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

u.getName

Postby ProgramBoy » 31 Aug 2016, 21:24

Hello, It's me again haha :D

Is it possible to do something like: u.getId(u.getName(!=Player))
Meanning select everyone except someone with that name?

Thanks again!
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: u.getName

Postby Bax » 01 Sep 2016, 07:44

No sorry, there's no such thing.
Paolo Bax
The SmartFoxServer Team
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: u.getName

Postby ProgramBoy » 01 Sep 2016, 13:21

Is there an other way I can do this?
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: u.getName

Postby Bax » 01 Sep 2016, 16:34

In a for loop, run through all the players in the room and just keep the one you don't need.
(unfortunately you are using SFS Pro; in 2X we introduced the Match Expressions: http://docs2x.smartfoxserver.com/Advanc ... s/game-api)
Paolo Bax
The SmartFoxServer Team
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: u.getName

Postby ProgramBoy » 01 Sep 2016, 17:30

Bax wrote:In a for loop, run through all the players in the room and just keep the one you don't need.
(unfortunately you are using SFS Pro; in 2X we introduced the Match Expressions: http://docs2x.smartfoxserver.com/Advanc ... s/game-api)


I am using a for loop, but how can I make it run on everybody except from one player // more than one player.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: u.getName

Postby Bax » 02 Sep 2016, 10:39

Loop on the users list, checking their name or some other property.
Paolo Bax
The SmartFoxServer Team
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: u.getName

Postby ProgramBoy » 02 Sep 2016, 12:29

How can I do that?
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: u.getName

Postby Bax » 02 Sep 2016, 12:36

Is this server side or client side? What programming language?
Paolo Bax
The SmartFoxServer Team
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: u.getName

Postby ProgramBoy » 02 Sep 2016, 12:44

Client side AS3 (Class File)
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: u.getName

Postby Bax » 02 Sep 2016, 13:23

This is an example showing how to iterate over users after joining a Room, putting them in a separate list which can be used for whatever purpose (for example show them in a list of users in the game's interface).
The example is taken from the SmartFoxChat demo application available in the SmartFoxServer Pro package. We strongly recommend that you take inspiration from the provided demos.

Code: Select all

         public function onJoinRoom(evt:SFSEvent):void
         {
            var room:Room = evt.params.room as Room                  
            var provider:ArrayCollection = new ArrayCollection()
            
            // Cycle through all users in the list and add them to the provider
            for each(var u:User in room.getUserList())
            {
               // Exclude myself
               if (u.getName() != sfsClient.myUserName)
                  provider.addItem( {label:u.getName(), data:u.getId()} )
            }
            
            ...
         }
Paolo Bax
The SmartFoxServer Team
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: u.getName

Postby ProgramBoy » 03 Sep 2016, 14:37

It works! haha awesome man thanks

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 32 guests