Sign In Register

How can we help you today?

Start a new topic
Answered

Unexpected behaviour in Unity3d SDK GetGSDataList()

Hello,


I have something like the following object I set as script data in cloud code:


  

Spark.setScriptData("test", {
    "slots": [
        null,
        null,
        { "someID": { "$oid": "someOID" } },
        null,
        { "someID": { "$oid": "someOtherOID" } },
        null
    ]
});

response.ScriptData.GetGSDataList("slots") gives me a list with Count = 2. So the null objects are filtered out. They are included in the underlying dictionary though.

Is this by design or a bug? I would expect an unfiltered list as return value.


Best Answer

It took a while to find this behaviour as the cause for some bugs in our game. But I implemented a workaround:


  

                List<GSData> GetUnfilteredGSDataList (GSData data, string key)
		{
			var objectList = data.BaseData [key] as List<object>;
			var gsDataList = new List<GSData> ();

			if (null != objectList)
			{
				foreach (Dictionary<string, object> obj in objectList)
				{
					gsDataList.Add ( null == obj ? null : new GSData (obj));
				}
			}
			return gsDataList;
		}

  


Hey David,

Im going to check with our tech-guys as to how GetGSDataList retrieves these elements, but i presume the problem is that a null object cannot be parsed as an object even-though it can recognize the 'slots' array as having a certain number of elements.

Is this causing problems for you in your game?
Please let us know,

Thanks,
Sean

 

Answer

It took a while to find this behaviour as the cause for some bugs in our game. But I implemented a workaround:


  

                List<GSData> GetUnfilteredGSDataList (GSData data, string key)
		{
			var objectList = data.BaseData [key] as List<object>;
			var gsDataList = new List<GSData> ();

			if (null != objectList)
			{
				foreach (Dictionary<string, object> obj in objectList)
				{
					gsDataList.Add ( null == obj ? null : new GSData (obj));
				}
			}
			return gsDataList;
		}

  

This really put a kink in things for me.  I'm trying to work around it using {} but that's not ideal.

Also, {} won't work in an array of ints.  I'll have to come up with a secret number to use to indicate where a null should be.  I hope the null parsing thing gets fixed.

Login to post a comment