This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DaKillerBear1's profile picture

How to add tolerance in coding

Started by DaKillerBear1, 26 November 2015 - 08:21 AM
DaKillerBear1 #1
Posted 26 November 2015 - 09:21 AM
I need to add tolerance in coding, but I don't know how.
For example something like "if x == 1 +-5 then bla bla bla end"

Please help! I'll try and explain it better if ye don't understand me.
Creator #2
Posted 26 November 2015 - 09:29 AM
So you're looking for a range. Like if x is between 1+5 and 1-5 do something?

If that's the case you have to have two checks. One that verifies x is above the lower border and another verifying x below the upper border, like this:

if x >= 1-5 and x<= 1+5 then
   --do stuff
end
KingofGamesYami #3
Posted 26 November 2015 - 01:06 PM

if x >= -4 and x <= 6 then
  ...
end
DaKillerBear1 #4
Posted 26 November 2015 - 05:33 PM
Cool! Thanks! I love the ask a pro section!