Is there a way to use dictionarys with two numbers for an index? for example d[1,30] = workspace.part

So, I was wondering if you could use two numbers in a table to refer to a value.
This would be very helpful for a grid system i am trying to make.

No, but I suppose you can store data in a table in such a way to make it seem like you’re doing that. E.x.:

local across = 3
local up = 3

local grid = {}
for x = 1, across do
	grid[x] = {}
	for y = 1, up do
		grid[x][y] = "Empty Slot" -- or whatever data
	end
end

Which makes this table:
Screenshot 2024-01-07 at 10.17.10 pm

Then just make functions to retrieve/set the data in that specific slot

local function GetPosition(x, y)
	return grid[x][y]
end

print(GetPosition(2, 3))

tysm! I found out just now that you could also use d[1…30] = workspace.part, which would be just a worse solution to this problem. TY!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.