--v is the value, m is the value that v should be the multiple of and dir says if v should be subtracted by one or if one should be added to it
function roundToMultiple(v, m, dir)
local v = v
local m = m
local dir = dir
math.floor(v)
while(v%m < 0 or v%m > 0) do
v = v + dir
end
return v
end
And this is the function in wich i use the seen above function.
function Player:placeBlock(key)
if key == "b" then
if self.x%50 == 0 and self.y%50 == 0 then
obj = Object.new(self.x, self.y,50, 50)
table.insert(Bdraw, obj)
else
local x = roundToMultiple(self.x, 50, -1)
local y = roundToMultiple(self.y, 50, -1)
obj = Object.new(x, y,50, 50)
table.insert(Bdraw, obj)
end
end
end
But it crashes
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
If it crashes, post the error and traceback you get; if it hangs, then you just learned why arithmetic with floating point numbers equaling a specific number might not ever work unless you keep your numbers whole.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
zorg wrote: ↑Mon Mar 28, 2022 1:58 pm
If it crashes, post the error and traceback you get; if it hangs, then you just learned why arithmetic with floating point numbers equaling a specific number might not ever work unless you keep your numbers whole.
It just hangs
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle