I would find it easier for me cause I was making this Repeat function so that x which is 1,gets +1 after the Repeat function.
When the Value of x turns to an even number,The Repeat function will stop.
I would find it easier for me cause I was making this Repeat function so that x which is 1,gets +1 after the Repeat function.
When the Value of x turns to an even number,The Repeat function will stop.
u can use the % sign to check if stuff is even or odd: like this
local number = 1
print(number % 2 == 0)
so, to put that in a repeat(i think) is to uhh:
local x = 1
repeat until x % 2 == 0
the % sign tells what the remainder of the division of 2 numbers is; so we check if the (number / 2)'s remainder is 0. if it is, then it is a even number. Else it is odd
What does the sign % do?
division
you're just checking if X is divisible by Y
wouldn't it be / ?
i think a x.Changed is more efficient here
wait
how would it work?
i dont understand the question rochel. how would what work.
im actually not sure the difference between % and /, hopefully someone can shed light on that.
ok look i editted it
u right banana. https://developer.roblox.com/articles/Math-Operators heres a link for further explaining on the difference.
xd
% is "modulus" which is a word that makes my brain hurt.
Basically,I'm making a "KeyPressed" function using UserInputService.When the player presses the key,it would make x +1 so when x == 1,it will constantly print something out with a wait(0.2).If the player presses the key again.It will make x +1 which equals to 2.When it reaches an even number,the repeat function will stop
if x % 2 ~= 0 then printstuff end
uhh what
cant u make a toggle
i can do the whole script but thats pretty much the jist of it. if its not even then do the thing.
when I tried x % 2 == 0,it printed false.So what does that mean?
also ya u can just do true/false as to whether or not the function is running. seems simpler?
it means x was not an even integer
yeah,i think so.
Oh.So false means odd,true means even.
uhh yes
yes, and if you did ~= instead of == it would be the opposite.
but again, a much simpler way like lua mentioned is to just toggle a bool back and forth.
thanks for explaining this!
lol
10 / 3 = 3.3333..., 10 // 3 = 3, 10 % 3 = 1. / is normal division. // gets you only the whole part of a division. % gets you only the remainder of the division.
The proper way to check if a number is an odd number or an even number is to use the modulo operator.
The modulo operator is simply a percentage sign (%).
To further understand what the modulo operator does, simply look at the code below:
function modulo(a, b)
return a - (math.floor(a/b)*b)
end
The way to use the modulo operator to determine if a number is odd or even is like this:
function checkNumber(num)
if type(num) ~= "number" then num = tonumber(num) end
return (num % 2 == 0 and "even" or "odd")
end
print(checkNumber(5))
Hope this helps! Let me know if you need any more explanation.
I'm confused
Fixed some issues with formatting. Basically, the modulo operator just returns the remainder of a / b. It's a bit more advanced, so there could be some difficulties attempting to understand it.
I think your answer should've been accepted. It provides a clearer understanding of what it is instead of just giving random code.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
i normally use something like "if X % 2 == 0 then" for even or "if X % 2 ~= 0 then" for odd, if you're using ints.