Hey there! I have a problem with adding values into my dictionary.
See the following code
local venuesClaimed = {
--Each entry's index is a column
[1] = {
--Each entry stands for a row and whether it is occupied ({}) or not (Instance)
[1] = Instance
[2] = {};
[3] = Instance;
...
[50] = {};
};
[2] = {
[1] = {};
[2] = Instance;
[3] = {};
...
[50] = {}
};
...
[50] = {
...
};
}
local allColumnsToOccupy = {24,25,26,27,28,29}
local allRowsToOccupy = {47}
local testInstance = part
for i, column in pairs(allColumnsToOccupy) do
for j, row in pairs(allRowsToOccupy) do
if venuesClaimed[column] then
venuesClaimed[column][row] = testInstance
end
end
end
I would expect the code to set the value of each row in the allRowsToOccupy table to testInstance (only in the row dictionaries which index is in the allColumnsToOccupy table).
The result that I get is that every row dictionary from all of the columns in venuesClaimed are set. Why is this happening? I’ve spent hours trying to figure this out but I can’t seem to understand why this is happening… Btw, if I explained this too vague, please let me know!
So this is what I get: (every single column’s row dictionary gets the new value)