generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How to check if a number is odd with if statement?

Previous Thread :: Next Thread 
CrimsonSparkleTime is not online. CrimsonSparkleTime
Joined: 25 Feb 2016
Total Posts: 2161
17 Apr 2017 12:37 AM
player.leaderstats.Level.Changed:connect(function()
if --[[ code here ]] then
local items = {player.leaderstats.Level.Value, player.leaderstats.Gold.Value}
local key = "user-" .. player.userId
datastore:SetAsync(key, items)
end
end)


R$5,090
Report Abuse
NilLogic is not online. NilLogic
Joined: 08 Apr 2016
Total Posts: 1369
17 Apr 2017 12:37 AM
The link below should answer your question, I hope I helped you.

http://wiki.roblox.com/index.php/Finding_if_a_number_is_even_or_odd

I'm just a friendly bot, please dont hate.
Report Abuse
CrimsonSparkleTime is not online. CrimsonSparkleTime
Joined: 25 Feb 2016
Total Posts: 2161
17 Apr 2017 12:45 AM
I'm not good at math


R$5,090
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
17 Apr 2017 12:47 AM
IT GIVES YOU AN EXAMPLE


Report Abuse
LordDracius is online. LordDracius
Joined: 22 Oct 2011
Total Posts: 1056
17 Apr 2017 12:48 AM
this is the code i use:

if numberIsEven(143) then
print('This function isn't real')
end
Report Abuse
samy22 is not online. samy22
Joined: 28 Sep 2008
Total Posts: 2181
17 Apr 2017 12:50 AM
number = 3

if math.floor((number+1)/2) == (number+1)/2 then
print("Its odd!")
end
Report Abuse
samy22 is not online. samy22
Joined: 28 Sep 2008
Total Posts: 2181
17 Apr 2017 12:51 AM
Oh, modulo ¬.¬
Report Abuse
CrimsonSparkleTime is not online. CrimsonSparkleTime
Joined: 25 Feb 2016
Total Posts: 2161
17 Apr 2017 01:15 AM
How does it work?


R$5,090
Report Abuse
KeiRoMultiverse is not online. KeiRoMultiverse
Joined: 16 Aug 2013
Total Posts: 1896
17 Apr 2017 01:34 AM
@CrimsonSparkleTime I think you're asking for a more detailed explanation of how finding the parity of a number works, right? If so, basically all even numbers are divisible by ## ## #### ###### it by two, and if it's a whole number it's even, otherwise odd. What samy22 posted works really well. Altohugh, I don't understand why adding 1 would help. I doubt you need to do that. math.floor() rounds what's in the parentheses down to the lower whole number. If it is a whole number, it'll return without changes. So comparing a math.floor() function with the same equation not in math.floor() will show if the number is whole or not. local num = 3 if math.floor(num/2) ~= num/2 then print("ODD") end
Report Abuse
KeiRoMultiverse is not online. KeiRoMultiverse
Joined: 16 Aug 2013
Total Posts: 1896
17 Apr 2017 01:37 AM
^^ Sorry gotta repost because ROBLOX filtering is crap.


I think you're asking for a more detailed explanation of how finding the parity of a number works, right?

If so, basically all even numbers are divisible by 2. All you gotta do is just it by two, and if it's a whole number it's even, otherwise odd.

What samy22 posted works really well. Altohugh, I don't understand why adding 1 would help. I doubt you need to do that.

math.floor() rounds what's in the parentheses down to the lower whole number. If it is a whole number, it'll return without changes. So comparing a math.floor() function with the same equation not in math.floor() will show if the number is whole or not.

local num = 3 if math.floor(num/2) ~= num/2 then print("ODD") end
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
17 Apr 2017 01:44 AM
can't you just

if num%2 == 1 then
print("odd")
end


Report Abuse
KeiRoMultiverse is not online. KeiRoMultiverse
Joined: 16 Aug 2013
Total Posts: 1896
17 Apr 2017 01:48 AM
@Lord_Narwhal

Oh wow! I forgot all about that, and I actually used that excessively to find parity in one of my programs.
Report Abuse
JoshRBX is not online. JoshRBX
Joined: 19 May 2012
Total Posts: 8778
17 Apr 2017 03:15 AM
x%2==0
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
17 Apr 2017 03:19 AM
@Josh you do realize a bot beat you to it


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image