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

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
}
}

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.

1 Like

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

Created ticket DEF-3826 for this

2 Likes

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

1 Like

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:

1 Like

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:

2 Likes

I’m back! This is still a bug.
Any chance it will be fixed?

1 Like

I’ve added it to the current sprint. I know we promised to look into it but other things came in between. I hope to get a chance to look at it while working on 1.2.166.

1 Like

Thanks

Solved in 1.2.166

2 Likes