# How do I use MODULO in programing or eventing?

Get help using Construct 2

### » Fri May 27, 2016 8:46 pm

Hi,

A while back I saw a use of modulo where it was placed at the end of equation like this: % 4. where it was suppose to return some other number if random number would be bigger then 4. But I don't exactly get it, so if anyone could give me some tips on how to use it, that would be appreciated. Thanks!
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203

### » Fri May 27, 2016 8:57 pm

B
28
S
17
G
157
Posts: 894
Reputation: 81,761

### » Fri May 27, 2016 9:07 pm

Modulo gives you the rest that occurs when dividing numbers.

e.g.
17 % 3 = 2 (17 = 5*3 + 2)
3 can be inside of 17 5 times, what is left is 2 (since its not divisible by 3 for putting out natural numbers).

Modulo will always give you that "rest" number. In case the number on the left is lower, you will always get the number on the left back.
1 % 4 = 1
2 % 4 = 2
3 % 4 = 3
4 % 4 = 0
5 % 4 = 1

You could (just an example) use it for determining every so and so number of elements in a loop.
Imagine having 12 enemys that you want to split to the left and right via a loop every 3 enemies changing the side. (yes i know, quite made up that example).
You would go check for each loop index + 1 % 3 equals 0 and change the sides.

edit: sorry guess you knew what modulo is about. Go by MadSpys examples on how to use it.
Guess that really depends on what logic you want to do, just sometimes modulos might be the answer you need.
B
23
S
7
G
4
Posts: 154
Reputation: 3,754

### » Fri May 27, 2016 9:32 pm

Thanks guys!
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203