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 » Scripting Helpers
Home Search
 

Re: for loops and odd numbers

Previous Thread :: Next Thread 
THEeric is not online. THEeric
Joined: 08 May 2008
Total Posts: 6185
16 Feb 2012 10:10 AM
Say I have this for loop:

for i=1,11 do
something
blah
something
end

and I want to put in an if statement making a certain part of the script only run when 'i' is an odd number, what do I need to do? Is there a built in function for that?
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
16 Feb 2012 11:00 AM
No, there isn't a function to check whether a number is odd or even. But, seeing as all even numbers are divisible by 2, you can use the modulus operator % to check if the remainder is 0.

if number % 2 == 0 --checks if 'number' divided by 2 has a remainder of 0 (all even numbers would)
Report Abuse
THEeric is not online. THEeric
Joined: 08 May 2008
Total Posts: 6185
16 Feb 2012 11:05 AM
Huh, ok, thanks. That would be much better than having to write out a bunch of odd numbers in a table or do anything messy like that.
Report Abuse
TheMaleScripter is not online. TheMaleScripter
Joined: 08 Nov 2009
Total Posts: 164
16 Feb 2012 11:06 AM
Yeah, And you could do something like

function isOdd(number)
if (number % 2 ~= 0) then
return true
else
return false
end
end
Report Abuse
THEeric is not online. THEeric
Joined: 08 May 2008
Total Posts: 6185
16 Feb 2012 11:07 AM
Just messed around wit hit in command, ok I see how it works. Thanks!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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