True, that should be taken into consideration, but philipp3 claims that even with 5 values it was failing, which in my testing didn’t fail.
No worries, I think you missed a follow up post saying "But my original table has more than 5 values, it has 144 x true, then 4 x false and then 1 x true again. Could that be a problem?"
But that limitation is for keys, not values.
The key is his example is “theTable”.
I modified the example to generate 150 values, and the returned result from iCloud is correct.
local iCloud = require( "plugin.iCloud" ) local json = require("json") local theTable = {} for index = 1, 150 do local value = math.random( 100 ) \< 50 and true or false theTable[index] = value end iCloud.set("theTable", json.encode(theTable)) print ("before", json.prettify(theTable)) --- theTableDownload = iCloud.get("theTable") if (theTableDownload ~= nil) then theTableDownload = json.decode(theTableDownload) print ("after", json.prettify(theTableDownload)) end
Thank you very much. I think I messed up everything. Is there a way to remove the iCloud data to start all over? I don’t see the app in the iCloud settings.
Also, I think I don’t quite understand when “initialSync” in the KVSListener is called, as I never saw it happen. Is this the point where I should set the values first to avoid overwriting them if they exist?
-
-
- EDIT
-
Just to confirm, iCloud was not the cause of the broken table, it was a very unlucky combination of tables overwriting each other, too long strings, bad WiFi and my inability to understand initialSync.
Have you tried to use iCloud.delete() to delete the key first?
Also “initialSync” isn’t called unless there was an error writing the data. It’s a message stating that the data couldn’t be written due to the initial sync not being completed.
I didn’t delete the key first, I just overwrote it, that has lead to problems with the tables, because they had a different length. I just left out the KVSListener, now it works fine. It wasn’t a bug though, just a fault on my side.