Skip to content

Instantly share code, notes, and snippets.

@Luca0208
Created July 28, 2016 20:19
Show Gist options
  • Save Luca0208/47e4629572e2bf2cdf8545bd8bc056ca to your computer and use it in GitHub Desktop.
Save Luca0208/47e4629572e2bf2cdf8545bd8bc056ca to your computer and use it in GitHub Desktop.
--Please remember this is out of context
--at the beginning of your program
local ids = {1,2,3,4}
local function isAllowed(id)
for i = 1,#ids do
if id == ids[i] then return true end
end
return false
end
--when you want to check for id and message
if isAllowed(id) and message == "blah" then
--code
end
--If you have multiple messages, but the same ids do this:
if isAllowed(id) then
if message == "blah" then
--code for blah
elseif message == "something" then
--code for something
end
end
--this way you are not iterating over the table multiple times
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment