Is it possible to add a dictionary to an array using code?

In a building based game that I am working on, I need to check surrounding bricks to remove unnecessary textures. I am currently using FindPartsInRegion3WithWhitelist to accomplish this, but with a high quantity of bricks, it is too slow to keep up with what I need. I have been wanting to represent the bricks in arrays to see if it could be a more viable option, but I have run into a problem of not knowing how to implement what I need, pushing dictionaries into an array.

What I’m starting out with is this:

blocks = {}

and I need to end up with this:

blocks = {
chunk0_0_0 = {…},
chunk1_-1_2 = {…}

}

I’ve looked on the wiki and all they don’t have anything on pushing dictionaries into arrays, so I’m not sure if it is even possible. Any response would be helpful.

1 Like

Something like this:

blocks[chunkName] = {...}


print(blocks[chunkName]) - - > table
4 Likes

Yes, you can, of course. Any valid data type is fair game to be pushed into a table.

local blocks = {}

blocks[chunkId] = {...}

The point is that you’re assigning a value to a key in your table.

Alternatively, if you don’t need the key and only a table (the value), you can enter it into the table with table.insert.

local blocks = {}

table.insert(blocks, {...})
8 Likes

For future reference, tables can store pretty much anything which is useful to store.

7 Likes

With how you’re naming your indices (chunk0_0_0 , chunk1_-1_2 ), you probably want to use a multi-dimensional array instead.

2 Likes