So this is just quick question. What is not modulus operator, like ~% or smth, cuz not seems to give error, here this code give error:
while not math.round(formulaLevel) % requiredLevel do
formulaLevel -= 1
end
Code gives this error:
So this is just quick question. What is not modulus operator, like ~% or smth, cuz not seems to give error, here this code give error:
while not math.round(formulaLevel) % requiredLevel do
formulaLevel -= 1
end
Code gives this error:
Use parentheses
while not (math.round(formulaLevel) % requiredLevel) do
formulaLevel -= 1
end
But what exactly are you trying to achieve here? The modulus operation will always evaluate to true
since it will always return a number. I assume you mean to do this:
while math.round(formulaLevel) % requiredLevel ~= 0 do
formulaLevel -= 1
task.wait() -- prevent Script Exhaustion
end
The modulus operator returns a number; therefore, you need to compare it with a number to return a bool (for the if
statement, that only evaluates booleans).
Well cuz i’m earlier checking if FormulaLevel > RequiredLevel, so i lower this value to modulus them and increase upgrade exponent. And when it do 8(for example) % 5 it just gives me false answer and skips this part of code:
while formulaLevel > 0 and math.round(formulaLevel) % requiredLevel >= 0 and math.round(formulaLevel) % requiredLevel <= 0.5 do
--code
end
EDIT: OK seems i don’t really need this weird check. This line works properly as i see:
while formulaLevel > 0 and math.round(formulaLevel) % requiredLevel >= 0 do
--code
end
The modulus operator returns the remainder of an Euclidean division (division by integer numbers).
So, for example, 11 % 2
results in 1
, because the 2
goes into 11
five times, and 1 is left over. Or, another example, would be 14 % 3
: it results in 2
, because 3
goes into 14
four times and 2
is left over.
So, naturally, if the result of the modulus is 0
, then there’s no remainder. if you want to make a ~%
operator, you need to invert the comparison operator implemented.
For instance, if this next code represents “%
”:
if a % b == 0 then
This next code represents ~%
:
if a % b ~= 0 then
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.