Sending an item to a friend ?

Hi everybody !

I’d like to try something but I have absolutely no clue how to do it. In my game, I want users to be able to send items to their friends. If their friends actually got the app and accept to receive the item, users get a reward (or a simple message).

I was thinking about running some script on my server where I’d register each “pending transaction”. But I’m not sure if that would work and if that would be the best solution… Everytime someone launch the app, it would connect to my server, check if there’s a pending transaction, return the result.

Or maybe by using Game Center / Play Games services (gameNetwork.match) ?

If anyone has already done it, I’d be happy to learn something :slight_smile:

sending the item to a table in an database, with the id_sender_user, id_destination_user, item, flag_accept should do the trick. when app starts will it will check if your id is in that table (sender or destination) and will check the flag_ if its false and depending of the user if it’s sender or destination will ask if you want to accept the item (it will turn the flag to true) if your the sender and the flag is already true, will give you a reward because the destination already accepted…hope i explained it well enought :wink:

Depending the the flow of your game, it might also be a good idea to check at regular intervals while the game is running. That way the user doesn’t have to close+reopen the game to get the item. 

Perhaps you could check the server every time the player returns to the main menu, or level select, or something like that.

Edit:

Also, this might seem obvious but once the user has agreed to accept and your code has given them the item, you may as well call a function to delete the entry from the database. This prevents:

a ) accidentally being able to reward the item twice if the flag fails for some reason

b ) filling up the database with used entries that are no longer needed.

Thanks a lot to both of you ! This is what I had in mind, but wasn’t sure if it was the “right way” to do it :slight_smile:

One more question though : to retrieve the user ID, I’m thinking about using the “deviceID” retrieved by “system.getInfo()” function. But, what if the player changes his device ? Is there some way to get an ID from his Apple account or Android account ?

Yes Game Center and Google Play Game Services both have IDs you can use.  

How do you intend for each person to specify who they want to send the item to? i.e. when I open the game and decided I want to send an item to my friend Jimmy, currently your app don’t know who my friend Jimmy is.

The most obvious way would be to use Facebook, which lets you request a list of their friends (and also means you could use their Facebook id as the identifier). One important thing to be aware of is that the “friends” request will only return a list of friends who have also installed your app and logged into Facebook.

e.g. 

My friends are:

Jimmy  - Has played my game and has logged in to FB

Bob  - Has played my game but has   not logged in to FB

Sally  - Has not played my game

Pam  - Has played my game and has logged in to FB

Eric  - Has not  played my game

Calling facebook.request( “me/friends” ) will only return Jimmy and Pam, because they are the only people who have logged into my game. There is another request which I think is called “me/invitable_friends” but that possibly needs an extra FB permission (I’m not 100% sure on that).

Also if you have multiple apps, the ID for each person is “app scoped”. That is to say that for each user, they will have an ID for app 1, a different ID for app 2 etc. So if I save the ID for Jimmy from app 1, and he logs into app 2, his ID will not match the one held on the database and so he will be a “new” user. This is not an issue if you just have 1 app that does not need to interact with other apps.

Oh, you’re absolutely right ! I totally forgot about the fact the app needs to have some kind of player list somewhere…

Also if you have multiple apps, the ID for each person is “app scoped”. That is to say that for each user, they will have an ID for app 1, a different ID for app 2 etc. So if I save the ID for Jimmy from app 1, and he logs into app 2, his ID will not match the one held on the database and so he will be a “new” user. This is not an issue if you just have 1 app that does not need to interact with other apps.

When you’re talking about “multiple apps”, you’re talking about differents apps, right ? The same app installed on an iPhone and on a iPad would still share the same ID ?

Even if Facebook is the “obvious solution”, would it possibly possible to do the exact same thing with Game Center / Play Game services (since there’s a friendlist, IDs) ? Guess I’ll have to study more about the gameNetwork library !

Thanks again for your time !

Yes I mean if you have different apps - QuizTix is a series of quiz games so we ran into this problem, the same app on multiple devices would share the same Facebook ID. 

I believe you could do the same with GC / GPGS. I’m not sure how many people actually add their friends to those accounts but tbh I’d be surprised if the friendslist was even 10% of the size they would have on Facebook. The advantage though is that in my experience most people don’t have an issue with games auto-signing into the game services, but many people dislike being forced to sign into Facebook (you’ll see lots of reviews saying they instantly installed the game if you do this).

If the sign in is optional though, I’d recommend implementing FB if you can. Since you need both people to have the game installed in order to send them anything, FB will allow your iOS users to send things to Android users, and vice versa. Using the game networks will limit you to only sending items on the same platform.

Ok thanks a lot ! I really appreciate your advices !

I’m gonna tag carloscosta’s answer as “Mark Solved”, but you really helped too ! 

Again, thanks for your time !

sending the item to a table in an database, with the id_sender_user, id_destination_user, item, flag_accept should do the trick. when app starts will it will check if your id is in that table (sender or destination) and will check the flag_ if its false and depending of the user if it’s sender or destination will ask if you want to accept the item (it will turn the flag to true) if your the sender and the flag is already true, will give you a reward because the destination already accepted…hope i explained it well enought :wink:

Depending the the flow of your game, it might also be a good idea to check at regular intervals while the game is running. That way the user doesn’t have to close+reopen the game to get the item. 

Perhaps you could check the server every time the player returns to the main menu, or level select, or something like that.

Edit:

Also, this might seem obvious but once the user has agreed to accept and your code has given them the item, you may as well call a function to delete the entry from the database. This prevents:

a ) accidentally being able to reward the item twice if the flag fails for some reason

b ) filling up the database with used entries that are no longer needed.

Thanks a lot to both of you ! This is what I had in mind, but wasn’t sure if it was the “right way” to do it :slight_smile:

One more question though : to retrieve the user ID, I’m thinking about using the “deviceID” retrieved by “system.getInfo()” function. But, what if the player changes his device ? Is there some way to get an ID from his Apple account or Android account ?

Yes Game Center and Google Play Game Services both have IDs you can use.  

How do you intend for each person to specify who they want to send the item to? i.e. when I open the game and decided I want to send an item to my friend Jimmy, currently your app don’t know who my friend Jimmy is.

The most obvious way would be to use Facebook, which lets you request a list of their friends (and also means you could use their Facebook id as the identifier). One important thing to be aware of is that the “friends” request will only return a list of friends who have also installed your app and logged into Facebook.

e.g. 

My friends are:

Jimmy  - Has played my game and has logged in to FB

Bob  - Has played my game but has   not logged in to FB

Sally  - Has not played my game

Pam  - Has played my game and has logged in to FB

Eric  - Has not  played my game

Calling facebook.request( “me/friends” ) will only return Jimmy and Pam, because they are the only people who have logged into my game. There is another request which I think is called “me/invitable_friends” but that possibly needs an extra FB permission (I’m not 100% sure on that).

Also if you have multiple apps, the ID for each person is “app scoped”. That is to say that for each user, they will have an ID for app 1, a different ID for app 2 etc. So if I save the ID for Jimmy from app 1, and he logs into app 2, his ID will not match the one held on the database and so he will be a “new” user. This is not an issue if you just have 1 app that does not need to interact with other apps.

Oh, you’re absolutely right ! I totally forgot about the fact the app needs to have some kind of player list somewhere…

Also if you have multiple apps, the ID for each person is “app scoped”. That is to say that for each user, they will have an ID for app 1, a different ID for app 2 etc. So if I save the ID for Jimmy from app 1, and he logs into app 2, his ID will not match the one held on the database and so he will be a “new” user. This is not an issue if you just have 1 app that does not need to interact with other apps.

When you’re talking about “multiple apps”, you’re talking about differents apps, right ? The same app installed on an iPhone and on a iPad would still share the same ID ?

Even if Facebook is the “obvious solution”, would it possibly possible to do the exact same thing with Game Center / Play Game services (since there’s a friendlist, IDs) ? Guess I’ll have to study more about the gameNetwork library !

Thanks again for your time !

Yes I mean if you have different apps - QuizTix is a series of quiz games so we ran into this problem, the same app on multiple devices would share the same Facebook ID. 

I believe you could do the same with GC / GPGS. I’m not sure how many people actually add their friends to those accounts but tbh I’d be surprised if the friendslist was even 10% of the size they would have on Facebook. The advantage though is that in my experience most people don’t have an issue with games auto-signing into the game services, but many people dislike being forced to sign into Facebook (you’ll see lots of reviews saying they instantly installed the game if you do this).

If the sign in is optional though, I’d recommend implementing FB if you can. Since you need both people to have the game installed in order to send them anything, FB will allow your iOS users to send things to Android users, and vice versa. Using the game networks will limit you to only sending items on the same platform.

Ok thanks a lot ! I really appreciate your advices !

I’m gonna tag carloscosta’s answer as “Mark Solved”, but you really helped too ! 

Again, thanks for your time !