Sign In Register

How can we help you today?

Start a new topic

Retrieving properties from ScriptData in Unity

Let's say my cloud code for AuthenticationResponse looks like this:

Spark.setScriptData("coins", 10);

In Unity, I do something like this:


new DeviceAuthenticationRequest().SetDurable(false).Send((response) => {    
    if (response.HasErrors) {     
    } else {    
        Debug.Log(debugName + " Device auth successful");
        Debug.Log(response.ScriptData.ContainsKey("coins")); //true
        Debug.Log(response.ScriptData.GetString("coins")); //null
        Debug.Log(response.ScriptData.GetInt("coins").GetValueOrDefault()); //0
Although "ContainsKey" reports true for the key "coins", I don't get any value when I call "GetString" or "GetInt". How do I retrieve the value of "coins"?


1 Comment

Okay, seems like a bug in the GameSparks plugin API:

 This format works: 


GSData responseData = response.ScriptData;    
int bonus = responseData.GetInt("coins").GetValueOrDefault(-1);


This format inexplicably does not work:

 int bonus = response.ScriptData.GetInt("coins").GetValueOrDefault(-1);


Login to post a comment