I want to know how I can tell if an object is in a table. I have no clue where to start trying to figure this out, so I ask, is there any good way to do this?
There are a few ways with dictionaries.
local myTable = {['object'] = true} -- Version 1 local function findMy1(object) if myTable[object] then return true end return false end --[[ or shortened with local function findMy1(object) return myTable[object] -- > returns the value or nil if there isn't one end or using ternary operators local function findMy1(object) return myTable[object] and true or false --> returns a bool end --]] -- Version 2 - For loop local function findMy2(object) for i,v in pairs(myTable) do if i == object then return true end end return false end -- Version 3 Using a metatable and the metamethod __index to -- give the table some function setmetatable(myTable, { __index = function(self, key) print( string.format("%s was not found", key)) return rawget(self, key) end }) print ( findMy1('object'), findMy2('object'), findMy1('nilObject') )