Sign In Register

How can we help you today?

Start a new topic
Answered

Most efficient way to get a value out of a nested scriptData object?

I'm following the Cloud Code tutorial that explains how to log race data and show the best lap time.

I am now at the point where I want to show the best lap time on the Unity client.

I have the following code...

void ShowBestLapTime()
    {
        new LogEventRequest().SetEventKey("GET_RACE_DATA")
            .SetEventAttribute("TRACK", "Track1")
            .Send(r =>
            {
                if(r.HasErrors)
                    Debug.LogError("Error getting GET_RACE_DATA : " + r.Errors.GetString("DETAILS"));
                else
                {
                    var gsData = new GSData(r.ScriptData);

                    object[] list = gsData.GetObjectList("fastestRaceData").ToArray();

                    foreach (var l in list)
                    {
                        var dic = (Dictionary<string, object>)l;
                        foreach(var key in dic.Keys)
                            Debug.Log("key = " + key.ToString());
                    }
                }
            });
    }

  I need to drill down into the 'fastestRaceData' object, to get the value I am looking for.

But is there a more efficient/short hand way to access the keys/values in this 'fastestRaceData' object than incrementing through a list?

Thanks


Best Answer

Never mind lol, late night for me last night :)
This is what I've found is the most efficient to code...


var gsData = new GSData(r.ScriptData);

 

                    object[] list = gsData.GetObjectList("fastestRaceData").ToArray();

 

                    foreach (var l in list)

                    {

                        var dic = (Dictionary<string, object>)l;

                        string timeTkane = dic["timeTaken"].ToString();

                    }

1 Comment

Answer

Never mind lol, late night for me last night :)
This is what I've found is the most efficient to code...


var gsData = new GSData(r.ScriptData);

 

                    object[] list = gsData.GetObjectList("fastestRaceData").ToArray();

 

                    foreach (var l in list)

                    {

                        var dic = (Dictionary<string, object>)l;

                        string timeTkane = dic["timeTaken"].ToString();

                    }