Currently if you want to compare one value to multiple other values, you need to either group if statements or iterate over an array. This is a very common thing to do so optimizing could be worth it. Making it possible to compare a value to multiple other values in a single comparison would mean less code to write and more readable code imo
When comparing a value, you can put multiple values inside brackets []
and would return true if the comparison is true for all values. The second =
in the if x == y
would use AND, having ~
be the second character in the comparison would use OR
local otherValue = 3
-- Current solution
if (self.SomeValueName == 1 or self.SomeValueName == 2 or self.SomeValueName == otherValue) then
end
-- New solution
if (self.SomeValueName == [1, 2, otherValue]) then -- x == 1 and x == 2 and x == otherValue
end
if (self.SomeValueName ~= [1, 2, otherValue]) then -- x ~= 1 and x ~= 2 and x ~= otherValue
end
if (self.SomeValueName =~ [1, 2, otherValue]) then -- x == 1 or x == 2 or x == otherValue
end
if (self.SomeValueName ~~ [1, 2, otherValue]) then -- x ~= 1 or x ~= 2 or x ~= otherValue
end
if (self.SomeValueName <~ [1, 2, otherValue]) then -- x <= 1 or x <= 2 or x <= otherValue
end
if ([1, 2, otherValue] >= self.SomeValueName) then
end
if ([1, 2, otherValue] >= [3, 5, 6]) then
end