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: Modulus %

Previous Thread :: Next Thread 
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
30 Jan 2015 09:32 AM
11 % 3 = 2

Found this in the Wiki.

Anyone mind telling me, wat exactly does this do???
I'm confused...
I tried millions of things and it's like the Numbers are just Randomly Picked and Printed :/
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
30 Jan 2015 09:35 AM
It returns the remainder when A is divided by B
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
30 Jan 2015 09:45 AM
oh...

print(5 % 2)
>1

???
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
30 Jan 2015 09:53 AM
You know, like in primary school when you first learn to divide without knowing what decimals are. '2 goes into 5 two times, and there is one left over!'
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
30 Jan 2015 10:05 AM
5 % 2

well, it is what's left of 5/2.

5/2 is 2 and 1 in rest. Or 2.5 but we won't do decimals unless the rest is decimals.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
30 Jan 2015 10:36 AM
% is the remainder.

print(5/2)
--> 2.5

print(5%2)
-->1


So if their both division what the heck is the difference?

Let me show you:

print(5/2)
--script is asked what 5 divided by 2 is, 2.5 * 2 is 5, so it returns 2.5

print(5%2)
--script is asked how much is left over after putting 2 into 5 as many possibles
--2*1 is less than 5
--2*2 is less than 5
--2*3 is more than 5
--5-(2*2) is 1, return 1
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
30 Jan 2015 10:39 AM
yes i get it now, thnx guys
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
30 Jan 2015 10:48 AM
If you need a script to understand, I can replicate it for you:

function Modulus(n, n2)
local remainder = n
while remainder - n2 < 1 do
remainder = remainder - n2
end
return remainder
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
30 Jan 2015 10:49 AM
Please note my example only works with positives.
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
30 Jan 2015 11:41 AM
thnx warspy, I get it
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
30 Jan 2015 01:27 PM
Glad I could help :D
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
30 Jan 2015 02:16 PM
warspy, u practicly always have a good answer
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
30 Jan 2015 02:20 PM
Thanks, I try my best.
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