The key-value pairs are virtual goods that the user has so they can be anything. Therefore GSDataList("string) won't work cause it means I would have to have over 30 variables and calls for each good available and the user won't have many of them so it's unecessary.
What is the best way to get all the info from this response into a Dictionary<string,int> in Unity C#?
Many thanks!
Alex
Best Answer
C
Customer Support
said
almost 6 years ago
Hey Alex,
You can use GetGSData() and GetInt() to get that data from the response. Check out the script below and let us know if that works for you.
new GameSparks.Api.Requests.LogEventRequest()
.Send((response) => {
if(!response.HasErrors)
{
GSData userData = response.ScriptData.GetGSData("UserOwns");
int oil = userData.GetInt("oil").Value;
int flour = userData.GetInt("flour").Value;
int donut = userData.GetInt("donut").Value;
}
else
{
Debug.LogWarning("GSM| Error /n "+response.Errors.JSON);
}
});
Thanks, Sean
1 Comment
Customer Support
said
almost 6 years ago
Answer
Hey Alex,
You can use GetGSData() and GetInt() to get that data from the response. Check out the script below and let us know if that works for you.
new GameSparks.Api.Requests.LogEventRequest()
.Send((response) => {
if(!response.HasErrors)
{
GSData userData = response.ScriptData.GetGSData("UserOwns");
int oil = userData.GetInt("oil").Value;
int flour = userData.GetInt("flour").Value;
int donut = userData.GetInt("donut").Value;
}
else
{
Debug.LogWarning("GSM| Error /n "+response.Errors.JSON);
}
});
Alex Catana
Hello,
I have an event which responds with something like:
The key-value pairs are virtual goods that the user has so they can be anything. Therefore GSDataList("string) won't work cause it means I would have to have over 30 variables and calls for each good available and the user won't have many of them so it's unecessary.
What is the best way to get all the info from this response into a Dictionary<string,int> in Unity C#?
Many thanks!
Alex
Hey Alex,
You can use GetGSData() and GetInt() to get that data from the response.
Check out the script below and let us know if that works for you.
Thanks,
Sean
Customer Support
Hey Alex,
You can use GetGSData() and GetInt() to get that data from the response.
Check out the script below and let us know if that works for you.
Thanks,
Sean
-
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