Posted 17 March 2014 - 05:20 AM
Im looking for a way to compare a value to all of the contents of a table and return true if the Item is in the table. I know the simple solution to it is simply the following:
the issue I am having is the reference manual on lua meta tables (link) stats in the are that talks about the "eq" ("==" operation) that it also looks to see if they are the same type, and I am lost when they talk about "getcomphandler", and making sure they are the same type.
a = {"this","is","just","a","test"}
function tableCompare(with)
for key, value in pairs(a) do
if value == with then
return true -- if it reaches this its in table a
end
end
return false -- If it reaches this it is not in table a
end
if tableCompare("test") then
-- if true code
else
-- if false code
end
but when done I want it to be as simple as to compare:if a == "test" then
-- if true code
else
-- if false code
end
the issue I am having is the reference manual on lua meta tables (link) stats in the are that talks about the "eq" ("==" operation) that it also looks to see if they are the same type, and I am lost when they talk about "getcomphandler", and making sure they are the same type.