A little bit confused about the friends list's concept

Dear sirs,

How do I implement one “list of friends” in my game ?

Suppose one user have registered himself the first time on my game, and after this, he would like to add his friend as a “friend”.

The user’s friend can only provide to him your display name or email. Obviously he does not know his user_id.

But I need the user_id to call friends.add(user_id), right? (or not ?)

  • How do I get the “user_id” in this case?

  • How do I get the “user_id” starting from display name or email ?

  • Please, do you have some example showing how to manage a friend’s list, adding, deleting and retrieving friends of a logged user ?

Sorry, but I am a bit confused about the friends list’s concept.

I guess I need to show an “friend list” to the game’s users, to they be able to locate friends to invite to an match. Isn’t it?

Thank you,

Best Regards,

Marcos Tito.

the way I do it is with: friends.find( keyword )

I let the user type in a search word (keyword)  and display the results from that in a tableView. The user can then choose which to add as a friend.

The event.response you get from friends.find( keyword ) is a numbered table with all the needed info.  I use the “_id” to add a friend: friends.add( _id ) and the “username” to display what name the user has chosen.

for example: **event.response[1][“username”] **would be the username of the first result from the friends.find

inside the friends listener I have something like:

[lua]

local friends = event.response

for i = 1, # friends do

 userId[i] = friends[i]["_id"]

 userName[i] =friends[i][“username”]

end

[/lua]

Thank you !!!

I am sorry about my poor knoledge… :slight_smile:

You said that friends.find( keyword ) will return a list, and then let the user choose which to add as a friend. 

But, friends.find( keyword ) will not return just who is already a friend ?

Thank you!

no, it will search through all registered users on corona cloud using the keyword you have entered. And when I tested it I found myself with both e-mail and username as keyword, or parts of them. So certain words like “test” will yield alot of results. Seems to be alot of “test users” out there :slight_smile:

I would like to thank you so much about your help !

If I understood, " friends" give to me two lists: [all users list] and a [friend’s list], isnt?

So, what friends.add means and which is its purpose on a game logic ?

Thank you again!

friends.add(_id) will add a user to the list you get when calling friends.getAll(). I use it to keep a list of friends that I show in a tableview so that one can easily challenge a friend to a match. 

OK !

I understood everything now !

Thank you very much !

the way I do it is with: friends.find( keyword )

I let the user type in a search word (keyword)  and display the results from that in a tableView. The user can then choose which to add as a friend.

The event.response you get from friends.find( keyword ) is a numbered table with all the needed info.  I use the “_id” to add a friend: friends.add( _id ) and the “username” to display what name the user has chosen.

for example: **event.response[1][“username”] **would be the username of the first result from the friends.find

inside the friends listener I have something like:

[lua]

local friends = event.response

for i = 1, # friends do

 userId[i] = friends[i]["_id"]

 userName[i] =friends[i][“username”]

end

[/lua]

Thank you !!!

I am sorry about my poor knoledge… :slight_smile:

You said that friends.find( keyword ) will return a list, and then let the user choose which to add as a friend. 

But, friends.find( keyword ) will not return just who is already a friend ?

Thank you!

no, it will search through all registered users on corona cloud using the keyword you have entered. And when I tested it I found myself with both e-mail and username as keyword, or parts of them. So certain words like “test” will yield alot of results. Seems to be alot of “test users” out there :slight_smile:

I would like to thank you so much about your help !

If I understood, " friends" give to me two lists: [all users list] and a [friend’s list], isnt?

So, what friends.add means and which is its purpose on a game logic ?

Thank you again!

friends.add(_id) will add a user to the list you get when calling friends.getAll(). I use it to keep a list of friends that I show in a tableview so that one can easily challenge a friend to a match. 

OK !

I understood everything now !

Thank you very much !