function module._Compare(a: number, b: number, mode: number): boolean
-- checks if a is greater than b (mode = 0)
-- checks if a is smaller than b (mode = 1)
mode = mode or 0
if mode == 0 then
return a > b
else
return a < b
end
end
I want the function to expect mode only to be 1 or 0. I tried number: (1 | 0) but that didn’t work. What’s the correct syntax?
Just assert if the number is greater than 1, example:
function module._Compare(a: number, b: number, mode: number): boolean
mode = mode or 0
assert(mode <= 1, ("%s cannot be more than 1"):format(tostring(mode))) --if you want add math.abs(mode) to prevent the injection of negative numbers
if mode == 0 then
return a > b
else
return a < b
end
end
If I misunderstood you please tell me, hope this helps anyway!