Hi, I'm currently creating a very general open source inventory system for everyone to use, but i've come across a problem. I've created a modulescript called ItemDB where I keep track of all items and their properties. It looks like this right now:
itemDB = {
["TestBrick"] = {
Image = "",
Properties = {"pickupable"},
Path = game.ReplicatedStorage.TestBrick,
hasProperty = function(self, property)
for i, p in pairs(itemDB["TestBrick"].Properties) do
if p == property then
return true
end
end
return false
end
};
}
return itemDB
So currently I can do
itemDB["TestBrick"]:hasProperty("pickupable")
which will return true, which is great! However this is only single function, which is several lines long, and every item will need access to several functions. ItemDB is gonna be very long with a minimal amount of items. I'd love to put the hasProperty function in the itemDB table itself, instead of putting it in every item's table. If I put the function in the ItemDB table and then call it on ["TestBrick"], i get the following error:
ReplicatedFirst.PickUpItems:9: attempt to call method 'hasProperty' (a nil value)
Which makes sense, since hasProperty is indeed not present in ["TestBrick"]. Is there any way to get this to work the way I want it? Like, a way to make ["TestBrick"] inherit all functions of ItemDB?

1 comment
Yeah, like @Epidemiology explained you could create a separate table with the functions and then use__index to link it.