This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-07-14 13:23:56

northmeister
Scratcher
Registered: 2011-07-12
Posts: 1000+

What does the mod command do?

Can anybody help me? I really want to know what the mod command means so i can use it in one of my games.


http://i48.tinypic.com/5a25g5.png

Offline

 

#2 2011-07-14 15:10:35

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: What does the mod command do?

"mod" is short for "modulo".  This function returns the remainder of division.  It's useful for a series of numbers that "wraps around". 

One example would be a clock.  Hours progress from 1 o 12, but there isn't "13 o'clock", it's just "1 o'clock" again. 

  13 mod 12 is 1, 14 mod 12 is 2, 31 mod 12 is 7.

(In military time, the clock counts up to 24, so you'd use "mod 24".)

I've seen mod used in scratch, but have to admit I've never used it.  I suspect I've needed it before, but figured out a way to do without it.  (I'm certain the workaround isn't as "elegant" as the proper use of it!)

Offline

 

#3 2011-07-14 16:04:00

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: What does the mod command do?

EdnaC explained it very well, but if you would like further explanation and examples, you may wish to read the Wiki page on the subject. I've used the mod block in many projects so if you would like to see those projects or have any questions, let me know.  smile


http://i48.tinypic.com/2z5pqad.png

Offline

 

Board footer