I have a bunch of different data that needs to be saved, and I stuff it into pdata <- {}; pdata.count<- 0; pdata.table <-{}; pdata.pstatus <- 0; pdata.non_utr <-0; pdata.utr <-0; pdata.location <-"";
then when the code hits this local err = 0; local test = server.load(); if (test.len() == 0) //if nothing has been saved, then save it now { // Saved updated settings table to permanent storage err = server.save(pdata); if (err == 0) { server.log("Settings saved"); } else { server.error("Settings not saved. Error: " + err.tostring()); } }
Is this a problem with my pdata initialization? Can I put a table into pdata? Is pdata.location <-"" the null that is the problem?
The ‘skipping unserialisable key’ error suggests to me that one of your keys is wrong. I suspect it’s pdata.table - Squirrel will interpret this as you asking to set the slot’s key to a table object, which can’t be done.
However, @peter is the expert on this and can hopefully point you in the right direction?
I am initializing pdata.table before it gets to server.save like this. function tab_init(){ //setup the table first time if (pdata.table.len() == 0) { //preset the table to 0 in all slots for (local x = 0; x<336; x +=1) { pdata.table.rawset(x, 0); } } }
it seems like the errors only occur when the agent is first initializing everything. Once that error is thrown it is never thrown again when its populated with operating data.
It only seems like one of the three proto’s are doing it
Oh wait, on thinking about it a bit more: https://electricimp.com/docs/resources/serialisablesquirrel/ says that a table is serialisable if its keys are all safe strings. Your table has keys which are integers, and that’s not going to work. Really, use an array instead.
yes that makes sense. I really need the table functions to make the backend of this work. Is it worth trying to save the data as a string into the table?