✓ Accepted answer
You could use the or operator like so:
local numb = math.random(1,7)
if numb == 1 or numb == 2 or numb == 3 then
print("it is a number between 1 and 3 - "..numb)
elseif numb == 4 or numb == 5 or numb == 6 or numb == 7 then
print("it is a number between 4 and 7 - "..numb)
end
Or you could use a table, and the table.find function (recommended):
local numbTable = {
oneToThree = {1,2,3},
fourToSeven = {4,5,6,7}
}
local numb = math.random(1,7)
if table.find(numbTable["oneToThree"],numb) then
print("it is is a number between 1 and 3 - "..numb)
elseif table.find(numbTable["fourToSeven"],numb) then
print("it is is a number between 4 and 7 - "..numb)
end
Hope this helped!
1 comment
I do like this answer.