I would use tables, I think they would be more efficient in my opinion. Depending on if collectionservice uses hashtables or arrays internally. Plus they’re more fliexable cause you can have anything passed by reference in a custom one such as tables not just instances. And it’s pretty easy to impelement to, here would be a CollectionEngine, I just wrote just now
-- this collectionENGINE works for any thing which is passed by reference
-- for eg: TABLES, INSTANCES, USERDATA, FUNCTIONS, THREADS
local TagEngine = {}
TagEngine.TagsOfItemTable = {} -- basically one table has item and its tags
TagEngine.ItemsOfTagTable = {} -- other has TAGS and it's items -- both tables made to not having looping
TagEngine.TotalTags = 0
TagEngine.TotalItems = 0
TagEngine.ItemAdded = function(Item, Tag) end
TagEngine.ItemRemoved = function(Item, Tag) end
function TagEngine:AddTag(Item, Tag)
if TagEngine.ItemsOfTagTable[Tag] == nil then TagEngine.ItemsOfTagTable[Tag] = {} TagEngine.TotalTags +=1 end
if TagEngine.TagsOfItemTable[Item] == nil then TagEngine.TagsOfItemTable[Item] = {} TagEngine.TotalItems +=1 end
TagEngine.TagsOfItemTable[Item][Tag] = Tag
TagEngine.ItemsOfTagTable[Tag][Item] = Item
TagEngine.ItemAdded(Item, Tag)
end
function TagEngine:RemoveTag(Item, Tag)
TagEngine.TagsOfItemTable[Item][Tag] = nil
TagEngine.ItemsOfTagTable[Tag][Item] = nil
TagEngine.ItemRemoved(Item, Tag)
end
function TagEngine:GetTags(Item)
local TagTable = {}
local Incrementor = 0
for _,v in pairs(TagEngine.TagsOfItemTable) do
Incrementor+=1
TagTable[Incrementor] = v
end
return TagTable
end
function TagEngine:HasTag(Item, Tag)
return TagEngine.TagsOfItemTable[Item][Tag] ~= nil
end
function TagEngine:GetItemsOfTag(Tag)
local ItemTable = {}
local Incrementor = 0
for _,Item in pairs(TagEngine.ItemsOfTagTable[Tag]) do
Incrementor+=1
ItemTable[Incrementor] = Item
end
return ItemTable
end
return TagEngine
— EXAMPLE USAGE
local CollectionEngine = require(script.Parent.CollectionEngine)
local m = {'as', 'as'}
local z = workspace.Baseplate
CollectionEngine.ItemAdded = function(Item, Tag) -- yah callbacks are neater then events
if Tag == 'deadTables' then
table.remove(Item,1)
elseif Tag == 'yo' then
if typeof(Item) == 'Instance' then
Item.Transparency = 1
end
end
end
local MyTable = {'helo', 'lol'}
CollectionEngine:AddTag(MyTable, 'deadTables')
CollectionEngine:AddTag(workspace.Baseplate, 'yo')
print(CollectionEngine:HasTag(workspace.Baseplate, 'yo'))
for i,v in pairs(CollectionEngine:GetItemsOfTag('yo')) do
print (v)
end
CollectionEngine:RemoveTag(workspace.Baseplate, 'yo')
print(CollectionEngine:HasTag(workspace.Baseplate, 'yo'))
for i,v in pairs(CollectionEngine:GetItemsOfTag('yo')) do
print (v)
end
print '-------------------------------'
print 'These are the items in MyTable'
for i,v in pairs(MyTable) do
print(v)
end
print '---------------------------------'
print('total amount of items in tag engine is '.. CollectionEngine.TotalItems)
Oh yah and:
https://gyazo.com/c6153d2a4e68a81e3c7cd22f8bc8219a
So yah I think it’s more flexible, and efficient to make a custom collectionservice using tables (Last one is a maybe not sure if it’s more efficient). Since the above one I showed you has .ItemRemoved, but in roblox’s collectionservice it’s depreicated.
This alllows object pooling systems with custom classes to.
Hard thing to do would be replication, collection service tagging replicates to clients instantly.