mod(a,b) returns a number which is the remainder, when a divided by b. The main result of the division is irrelevant.

For example:

mod(14,3) = 2, because 14/3 = 4 and the remainder is 2.

mod(32,4) = 0, because 32/4 = 8 and the remainder is 0.

mod(79,8) = 7, because 79/8 = 9 and the remainder is 7.

Where can you use mod(a,b)?

Imagine you would like to change the look every time an object moves. First we have to pick three different looks for our object. Then we can use the mod(a,b) in the function "Switch to look number mod( position x, 3) + 1".

If the position x = 0, mod( position x, 3) returns 0.

If the position x = 1, mod( position x, 3) returns 1.

If the position x = 2, mod( position x, 3) returns 2.

If the position x = 3, mod( position x, 3) returns 0.

If the position x = 4, mod( position x, 3) returns 1.

If the position x = 5, mod( position x, 3) returns 2.

If the position x = 6, mod( position x, 3) returns 0.

So the output is 0,1,2,0,1,2 and so on.

We add +1 to the function, this makes the output to 1,2,3,1,2,3 and so on.

Then we want to switch to look number of this whole function, so we switch to look number 1, then look number 2, then look number 3, then look number 1, and so on.

Example Code:

mod_english_bearbeitet.png