I just have an if statement and I need it to check if a certain Value is not between the numbers 60 to 80. Here is the block of code I need help with it's simple, just how do I make it check between these two numbers?
if h.Health ~= 60,80 then pg.Hurt.Red.ImageTransparency = 0.8 end
I end up with "expected 'then' got ','" Any help is appreciated :)
A number is "between" 60 and 80 if it is greater than 60: 60 <= x
and it is less than 80: x <= 80
.
Thus,
if 60 <= x and x <= 80 then -- between else -- not between! end
You can use not
to negate the whole thing:
if not (60 <= x and x <= 80) then -- parenthesis matter! -- not between! else -- between end
You can use De Morgan's law to get rid of the not
. not (a and b)
is (not a) or (not b)
. The not
of a <=
is >
and the not
of >=
is <
(flipping when the things are true):
if 60 > x or x > 80 then -- not between! else -- between end
"Flipping" the >
to make them be in smallest to largest makes more sense:
if x < 60 or 80 < x then -- not between!
That is, x
is not between 60 and 80 if it is less than 60, OR it is greater than 80.