I am trying to upload a table to iCloud. When I download it again, it is broken, I have absolutely no idea why that happens. It always cuts the table where the first “false” is. I have tried that with several options, booleans and strings, it is always the same.
theTable = {true, true, true, false, false} iCloud.set("theTable", json.encode(theTable)) --- theTableDownload = iCloud.get("theTable") theTableDownload = json.decode(theTableDownload) -- this is the remaining table: {true, true true}
Yes, and also with strings. 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?
Edit:
I have to make a new project, it could be that I am just overwriting the table so often that I am confused with what it should look like. I will write as soon as I find out something new
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?"
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.
Yes, and also with strings. 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?
Edit:
I have to make a new project, it could be that I am just overwriting the table so often that I am confused with what it should look like. I will write as soon as I find out something new