SharedTable Iteration

Hey there!

I am currently trying to implement a priority queue system using sharedTables in studio.
I have encountered the problem that sharedTables are not iterable (atleast I do not think they are). I am trying to find a work around.

The main goal of what I am trying to do is to make another thread (a worker thread), that can iterate over a queue constantly executing tasks in sequential order. I am using a sharedTable to communicate the status and content of the queue across threads. This is to stop a dupe glitch that has been happening in my game. I would love some help/advice on this issue. Thanks!

Ps: The code below is just for testing iteration and also cuz I dont want to stick the 400 lines of code I have in here. The code below throws an error.

local mySharedTable = SharedTable.new({
	item1 = "Hello",
	item2 = "World",
	item3 = 123
})

local table2 = SharedTable.clone(mySharedTable, false)
-- Iterate over the SharedTable like a regular table
for key, value in pairs(table2) do
	print(key, value)
end

Switch it to this:

for key, value in table2 do
	print(key, value)
end
1 Like

I can’t believe I didn’t see that. Thank you!

1 Like