Sys.load tables with negative indexes (DEF-3826)


#1

I have an issue when loading a table that has negative indexes, they get screwed after load

                local table = {board={}}
		table.board[-1] = 1
		table.board[0] = 2
		table.board[1] = 3
		print("table contents")
		pprint(table)
		local filename = sys.get_save_file("paragonredux", "game")
		sys.save(filename, table)
		local loadedTable = sys.load(filename)
		print("table contents after load")
		pprint(loadedTable)

the output is

DEBUG:SCRIPT:
{ --[[000000001626D8E0]]
board = { --[[000000001626D910]]
0 = 2,
1 = 3,
-1 = 1
}
}
DEBUG:SCRIPT: table contents after load
DEBUG:SCRIPT:
{ --[[000000001626DAB0]]
board = { --[[000000001626DAE0]]
0 = 2,
1 = 3,
4294967295 = 1
}
}


#2

There are certain limitations to keys and the number of keys, but the documentation doesn’t mention anything about negative keys: https://www.defold.com/ref/sys/#sys.save:filename-table

I’ll check this with the team and get back to you.


#3

Test stuffing a single dummy string into the table as a key?


#4

Created ticket DEF-3826 for this


#5

doesn’t work

board = { --[[000000003711C8F0]]
0 = 2,
1 = 3,
dummy = 0,
-1 = 1
}

board = { --[[000000003711CD60]]
0 = 2,
1 = 3,
dummy = 0,
4294967295 = 1
}

there’s a wide variety of workarounds i can put in though in case the ticket takes too much time to settle… i’ll focus on some other feature for the moment


#6

Thanks for doing the science!

I think I might have had this problem before in a grid based game and used strings for keys. You could probably serialize the table yourself and put it in a table as a string before saving it. Although you’re probably aware of both of these and it looks like it might be getting fixed. :slight_smile:


#7

Yes it will. We’ll look into it for the next release (1.2.150). It’s surprising that these kind of limitations still exist in something like sys.save/load which has been around for ages. :slight_smile: