Hello. I am currently writing a script for my vehicle which will enable cruise control. I have gotten to the point where the cruise is able to be set up and down, however, I have only been able to do it by a certain amount each time.
What I want to happen, is for the cruise control speed (let’s say that it’s set at 17 MPH) to go up to the next multiple of 5 (20 MPH in this case). Same thing when setting down. (15 MPH in this case).
You can use the % modulo operator, which gets the remainder of a number when dividing two numbers.
local multiple = 5
local function isMultiple(number)
return number % multiple == 0
end
print(isMultiple(5)) -- prints true
print(isMultiple(25)) -- prints true
print(isMultiple(14)) -- prints false