I know three ways to do this.
- Multiple
orin a single statement
if (variable == "a") or (variable == "b") or ... then
code
- Define a table and iterate over it with ipairs:
x = {"a", "b"...}
for i, var in ipairs(x) do
if variable == var then
code
- Define a table with the possible values as keys instead
x = {["a"] = true, ["b"] = true...}
if x[variable] then
code
I have been using 3 since it seemed like the most efficient in terms of execution, but writing every key as true seems so cumbersome. Surely there's a more elegant way to do something this simple?