I was trying to get some variables from an specific player, and then store them in arrays to manipulate and display them, I don't have any problems putting the keys on the array, but at the moment of putting the values of the dictionary that returns for the get user data it doesn't let me store them in the array
It displays Cannot convert from 'string[]' to ' PlayFabClientModels.UserDataRecord[]'
private String[] qDataKeys;
private String[] qDataValues;
void GetQuestionsData()
{
PlayFabClientAPI.GetUserData(new GetUserDataRequest()
{
PlayFabId = "someID",
Keys = null
},
OnQuestionsDataReceived,
OnError
);
}
void OnQuestionsDataReceived(GetUserDataResult result)
{
result.Data.Keys.CopyTo(qDataKeys, 0);
result.Data.Values.CopyTo(qDataValues, 0);// This is the one that gives the error, above one is okay
}
The issue is pretty clear in the error. The type returned from this call is of type
PlayFabClientModels.UserDataRecord[]. Checking out the docs, the type UserDataRecord is setup asI am assuming you would like the
Valueinside of the record. I am not sure how you are currently accessing theKeyeither as the docs specify that theGetUserDataResultreturnsDatawhich is of typeUserDataRecordandDataVersionwhich is of typenumber.The error is currently telling you that the
copyToyou are using is failing because the current type isPlayFabClientModels.UserDataRecord[]and you are expectingstring[]. You would need to iterate over eachUserDataRecordand grab theValuedata from each index.I believe something along the lines of
string[] yourData = result.Data.Value.Select(x => x.Value).ToArray();Should work. You will need to include
using System.Linqat the top of your file. If it does not work, I would just need to know the typing ofresult.Data.Valuesbut due to the error, I am assuming it is an innumerable array of data. I am not familiar with PlayFab so if the current docs are outdated please correct me in the comments and I'll try to update the answer.