How Do I Get the Details of the Players in a Challenge
B
Bolaji Harris
started a topic
over 8 years ago
I need a way to either, get a users details with just a playerid. Or, for GetChallengeRequest to return the full details of the challenged players.
I am creating a asynchronous turn based game and using Challenges as the mechanism for managing matches. Before each user takes their turn they are presented a match detail screen that shows all the players involved in the match and their Facebook profile picture. However since GetChallengeRequest does not return a Facebook id, I have no way of fetching the Facebook profile picture. Does anyone have a way to do this?
I am using Unity3D and scripting in C#.
Best Answer
C
Customer Support
said
over 8 years ago
ListChallengeRequest might be what you're looking for. You need to supply a shortCode for the type of Challenge you are looking to get and it's current state. In my Unity project I have a GUI Component that looks like:
public class RunningGameEntry : MonoBehaviour
{
string challengeInstanceId;
string userId, facebookId;
string challengerName, challengerId;
string idOfNextTurnPlayer;
Texture2D profilePicture;
}
Then when I want to update a list of games I write a ChallengeManager which looks something like:
public class ChallenegeManager : MonoBehaviour
{
public UIGrid runningGrid;
public GameObject runningEntryPrefab;
public List<GameObject> runningGames = new List<GameObject> ();
public void GetRunningChallenges ()
{
//We refresh running games
for (int i = 0; i < runningGames.Count; i++)
{
Destroy (runningGames [i]);
}
runningGames.Clear ();
//We List the challenges called Tic Tac Toe, specifically the ones that are "Running"
new ListChallengeRequest ()
.SetShortCode ("ticTacToe")
.SetState ("RUNNING")
.SetEntryCount (50).Send ((response) =>
{
foreach (var challenge in response.ChallengeInstances)
{
go.GetComponent<RunningGameEntry> ().challengeId = challenge.ChallengeId;
go.GetComponent<RunningGameEntry> ().turnStatus = challenge.NextPlayer;
go.GetComponent<RunningGameEntry> ().challengerId = challenge.Challenger.Id;
//Player details are stored in the "Challenged" Collection
foreach (var player in challenge.Challenged)
{
go.GetComponent<RunningGameEntry> ().challengerName = player.Name;
go.GetComponent<RunningGameEntry> ().facebookId = player.BaseData.ContainsKey ("ExternalIds");
go.GetComponent<RunningGameEntry> ().challengerName = challenge.Challenger.Name;
}
}
});
}
}
The code above is for reference, but you can get the gist of what's going on. If you have multiple game types you can do the same thing but replace the shortCode.
Once you get the facebookId you can get the profile picture with the following function:
public IEnumerator getFBPicture ()
{
var www = new WWW ("http://graph.facebook.com/" + facebookId + "/picture?width=210&height=210");
yield return www;
Texture2D tempPic = new Texture2D (25, 25);
www.LoadImageIntoTexture (tempPic);
profilePicture.mainTexture = tempPic;
}
1 Comment
Customer Support
said
over 8 years ago
Answer
ListChallengeRequest might be what you're looking for. You need to supply a shortCode for the type of Challenge you are looking to get and it's current state. In my Unity project I have a GUI Component that looks like:
public class RunningGameEntry : MonoBehaviour
{
string challengeInstanceId;
string userId, facebookId;
string challengerName, challengerId;
string idOfNextTurnPlayer;
Texture2D profilePicture;
}
Then when I want to update a list of games I write a ChallengeManager which looks something like:
public class ChallenegeManager : MonoBehaviour
{
public UIGrid runningGrid;
public GameObject runningEntryPrefab;
public List<GameObject> runningGames = new List<GameObject> ();
public void GetRunningChallenges ()
{
//We refresh running games
for (int i = 0; i < runningGames.Count; i++)
{
Destroy (runningGames [i]);
}
runningGames.Clear ();
//We List the challenges called Tic Tac Toe, specifically the ones that are "Running"
new ListChallengeRequest ()
.SetShortCode ("ticTacToe")
.SetState ("RUNNING")
.SetEntryCount (50).Send ((response) =>
{
foreach (var challenge in response.ChallengeInstances)
{
go.GetComponent<RunningGameEntry> ().challengeId = challenge.ChallengeId;
go.GetComponent<RunningGameEntry> ().turnStatus = challenge.NextPlayer;
go.GetComponent<RunningGameEntry> ().challengerId = challenge.Challenger.Id;
//Player details are stored in the "Challenged" Collection
foreach (var player in challenge.Challenged)
{
go.GetComponent<RunningGameEntry> ().challengerName = player.Name;
go.GetComponent<RunningGameEntry> ().facebookId = player.BaseData.ContainsKey ("ExternalIds");
go.GetComponent<RunningGameEntry> ().challengerName = challenge.Challenger.Name;
}
}
});
}
}
The code above is for reference, but you can get the gist of what's going on. If you have multiple game types you can do the same thing but replace the shortCode.
Once you get the facebookId you can get the profile picture with the following function:
public IEnumerator getFBPicture ()
{
var www = new WWW ("http://graph.facebook.com/" + facebookId + "/picture?width=210&height=210");
yield return www;
Texture2D tempPic = new Texture2D (25, 25);
www.LoadImageIntoTexture (tempPic);
profilePicture.mainTexture = tempPic;
}
Bolaji Harris
I need a way to either, get a users details with just a playerid. Or, for GetChallengeRequest to return the full details of the challenged players.
I am creating a asynchronous turn based game and using Challenges as the mechanism for managing matches. Before each user takes their turn they are presented a match detail screen that shows all the players involved in the match and their Facebook profile picture. However since GetChallengeRequest does not return a Facebook id, I have no way of fetching the Facebook profile picture. Does anyone have a way to do this?
I am using Unity3D and scripting in C#.
ListChallengeRequest might be what you're looking for. You need to supply a shortCode for the type of Challenge you are looking to get and it's current state. In my Unity project I have a GUI Component that looks like:
Then when I want to update a list of games I write a ChallengeManager which looks something like:
The code above is for reference, but you can get the gist of what's going on. If you have multiple game types you can do the same thing but replace the shortCode.
Once you get the facebookId you can get the profile picture with the following function:
Customer Support
ListChallengeRequest might be what you're looking for. You need to supply a shortCode for the type of Challenge you are looking to get and it's current state. In my Unity project I have a GUI Component that looks like:
Then when I want to update a list of games I write a ChallengeManager which looks something like:
The code above is for reference, but you can get the gist of what's going on. If you have multiple game types you can do the same thing but replace the shortCode.
Once you get the facebookId you can get the profile picture with the following function:
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics