Passing a table through a remote event erases all indexes less than 1...?

I’m trying to make my own voxel terrain in Roblox, sort of like in Minecraft. Blocks are stored based on their X Y Z position within a chunk (a chunk being just a 3D table with 16x128x16 blocks).

For example, Chunk.Blocks[0][64][8] would get a block at X = 0, Y = 64, Z = 8 within chunk.

When I send a chunk to a player through a remote event, all blocks with an X Y or Z index of 0 or below disappear completely, just completely gone. ALL other indexes are 100% OK, but no matter what index 0 of everything just gets erased.

I thought maybe something was wrong with my code, so I tried sending an even simpler table through a remote event. But even a completely normal table with only numbered indexes (no dictionaries, not 3D or anything fancy) will still lose all indexes less than 0.

My coordinates system relies on 0 being a valid block coordinate, I don’t think I can use 1 as the starting number for everything as it will shift all coordinates up by one block. And shifting millions of blocks an index over when sending chunk data to the player, only to undo the shift after the player receives the data, also seems incredibly inefficient.

Is this a bug? What can I do about this?

1 Like

Try stringifying the index as keys instead and then turning them back into indexes on the other side.

2 Likes

It is by design unfortunately. The developer site explains it. Details are here, towards the end.

I think that would require me to iterate through thousands and thousands of indexes while converting them from numeric to string…

Generating and sending chunks already takes a lot of CPU and memory, so I don’t think I can add format conversions on top of that. If it weren’t for the potential performance impact though I would likely already be doing this.

I don’t see anything on that page relating to numbered indexes, or any explanation for why 0 and below wouldn’t be fine. Which section do you mean?

All documentation assumes that arrays use positive indices from 1 to n. There is no assurance that 0 or negative indices are supported. (edit: now mentions 0 as unsupported too)

If you’re pushing large amounts of chunk data over the network, I’d advise using the buffer library to compress and optimize all those values and implement a more viable data structure that supports negative coordinates.

If you absolutely want to stick with 3D arrays, you could provide an initial index value with each dimension to indicate that the array entries’ indices should be interpreted as numbers that can be less than 1.

0 isn’t negative though, so I find it weird that there’s issues with it.

Buffer is interesting, but I know nothing of how to use it or how to create my own data formats.

I should probably stop directly reading/editing chunkdata and come up with a new object or functions to do it and handle whatever offsets automatically… It feels like I am going to lose my sanity regardless.

Sorry, I forgot to mention that zero also isn’t explicitly supported. Lua table indices are 1-based. It’s not so much a matter of an index being negative than it is the index being out of the range that array-compatible logic expects array indices to be in.

Chunk systems are quite tricky so I sympathize with your due insanity.

Roblox index starts at 1 and not 0 like most other languages do.

My recommendation would to just take the index and minus one to get the correct block position.