/ tech-note

How to check if an element is in the table in Lua?

This is NOT supported in Lua. So you must write your own function manually.

In Python, you can write the following:

if i in yourList:

In Lua, write the following:

local function has_value(tab, val)
    for index, value in ipairs(tab) do
        if value == val then
            return true
        end
    end

    return false
end

And then, use the function to check if the element is in the table:

pokemon = {"Bulbasaur", "Charmander", "Squirtle"}
if has_value(pokemon, "Pikachu") then
    print("You have Pikachu!")
else
    print("You should get your Pikachu...")
end

Source: https://stackoverflow.com/a/33511182/2360798