Discuss Scratch

razze_w
Scratcher
3 posts

The mod block

I have never used the mod block and i don't understand it
(here is how it looks btw)
(() mod (0))
can someone explain it to me?

Thanks )
semmiesem9
Scratcher
100+ posts

The mod block

If it gets higher than the second number, it gets cut down. I don't know the technicalities of it, but here's some examples:

((2) mod (3))//2
((3) mod (3))//0
((4) mod (3))//1
((6) mod (3))//0
((23) mod (5))//3

It's useful for swapping through costumes in a walking animation and stuff.
AHypnoman
Scratcher
1000+ posts

The mod block

It gives the remainder of a division. ‘Mod’ is short for ‘Modulo’

Example:
9 divided by 4 = 2 remainder 1
Mod gets the 1, or the remainder.

This is useful in odd number checkers because you can do this:

if <((Number to check) mod [2]) = [1]> then
set [is number odd? v] to [yes]
else
set [is number odd? v] to [no]
end

Last edited by AHypnoman (March 12, 2021 13:26:07)

The_Imaginarium
Scratcher
1000+ posts

The mod block

It means the remainder of the number divided by the other number, which allows you to count in a circle.
Like so:
((6) mod (5))//equals 1, because 5 can go once into six, and has one left over
((9) mod (4))//also equals 1, because 4 can go twice into 9, with one left over
//You can use it for walking animations like this:
switch costume to [(((frame) mod (10)) + (1)) v]

//Apparently Scratch 2.0 didn't support number values in the costume block. :/

Last edited by The_Imaginarium (March 12, 2021 13:23:23)

AHypnoman
Scratcher
1000+ posts

The mod block

The_Imaginarium wrote:

switch costume to [(((frame) mod (10)) + (1)) v]
Fixed
switch costume to (((frame) mod (10)) + (1))
goldenlion06
Scratcher
500+ posts

The mod block

hi, the mod block is the first number divided by the second giving the remainder. so 7 divided by 3 in that block it is 2 remainder 1.
so the return is 1

Last edited by goldenlion06 (March 12, 2021 15:46:04)

SUPERCAT627
Scratcher
9 posts

The mod block

I still don't understand this block: (() mod (0))
sashimiricedev
Scratcher
100+ posts

The mod block

Basically it's the remainder of the division. For example,
((5) mod (2))
would be 1 because 5 divided by 2 = 2 and R1

Example 2
((6) mod (3))
is 0 because 6 divides perfectly into 3; there is no remainder or ones left over.

Example 3 -
((10) mod (4))
would be 2 because 10 divided by 4 = 2 R2, or 2 and 2 left over.

Try these examples on paper and you'll get what I mean.

I wish I could give you a visual example, but it's the best I can do with Scratch Forums.

Also greatest apologies for necroposting; didn't see the date.

Last edited by sashimiricedev (Feb. 23, 2024 21:55:54)

SUPERCAT627
Scratcher
9 posts

The mod block

Im only nine. I don't understand one bit! Hee hee hee
sashimiricedev
Scratcher
100+ posts

The mod block

4th grade should help you with that
SUPERCAT627
Scratcher
9 posts

The mod block

ok thanks cuz I am trynna animate my mlp characters but it won't work! I watched tutorials and everything!

Powered by DjangoBB