Hi, decide to reply, I had 2-3 posts before but ive deleted other 2, and this one is because i needed and still need help, exact help with understanding what can i add or change in my advanced system
no
sorry, i dont know
i made it for help
Hi, decide to reply, I had 2-3 posts before but ive deleted other 2, and this one is because i needed and still need help, exact help with understanding what can i add or change in my advanced system
no
sorry, i dont know
i made it for help
this isn’t even a “help” topic anymore, you’ve continued to expand your… “optimised” code despite the amount of solutions ranging from simple, complex, light, heavy. pls move this topic to #resources:community-resources
there is a-lot of red flags which turn this entire topic over to something called “ragebait”, content that’s made to make people annoyed or irritated on purpose for clout.
if math.round(n/2) == n/2 then
--is even
else
--is odd
end
is it simple enough?
ummm i don’t understand the hate!!! clearly better programmer and you’re just mad smh…
I’m student, now outside in different country thats why probably
no idea how to move topic
please explain, i have no clude whats “math.round(n/2)”
thanks!!!
If you don’t understand them we can help you understand those methods.
that basically rounds the number in the bracket. round means making the number have no decimal .
thats what i asked for, someone who can explain me how it works step by step, not already made scripts, im n ew to thiks and i really jsut wanned an explain on how to do it and how it works
im studying outside country
how?
It amazes me how many people don’t understand jokes lmao
That’s because this post shouldn’t be here if it really was satire.
that will return odd if the number is a decimal
Ok, then let me explain the methods that are been proposed in the first posts, let’s take the example of @2112Jay which was one of the fastest ones.
function isOdd(number)
return number %2~=0
end
function isEven(number)
return number %2==0
end
What this 2 function do is just to see if the number you inputted into the function parameter is divisible by “2”.
If it is it’s going to return 0 it means there is no rest and the number is divisible by 2.
If it isn’t going to return 0 it means there is rest and the number is not divisible by 2.
(the returning is true or false depending if the number is does not have rest or does have rest).
If you want to check if the number inputted is really a number you can just do:
function isOdd(number)
assert(type(number) == "number")
return number %2~=0
end
function isEven(number)
assert(type(number) == "number")
return number %2==0
end
amazing things? well surely of with optimalized
but whats “assert”, “type”?
So, “%2” means devisible by 2 okay, == is equeals and ~= not equeals.
I kind of get it but what is assert and type?
Ok, type
is just to check the variable type.
Example:
print(type(1)) --it will print "number" as "1" is a number
print(type("hello world")) --it will print "string" as "hello world" is a string
And so on, in the Roblox Docs this is all specified.
About assert
it’s just a function that checks if the value inputted is nil or false if it is nil or false it’s going to error else it’s not going to do anything.
Example:
assert(1 == 2, "Math isn't broken!") --this is going to error as 1 == 2 is false
assert(type(1) == type(2), "types are broken :skull:") --this is not going to error as both types are a "number"
Hope you understood now!
you know i’m really starting to wonder if this is actual ragebait or not
I thought it was simple!!
The 100 million version works well in my game. Can’t wait for the 1 billion update.
LOL I see what you’re trying to do but that’s extremely unoptimized and just calling the function once will probably crash the whole server. Instead, you could easily detect even numbers by using math.round(), then divided whatever you have by 2, and then check if the remainder is < 1 (less than = odd). This is the easiest solution and it wont turn your device into a oven
I appreciate your dedication in learning how to script and you’re doing well so far because functionally this does work, its just very very very inefficient especially when you can do the same thing in like 3 lines
edit: woops, nevermind lol that wont work either… I don’t know what i was thinking but you could do something like this that uses the same principle
function is_even(number)
return math.floor(number / 2) * 2 == number
end
if is_even(number) then
print(number .. " is even")
else
print(number .. " is odd")
end