I don't understand "MOD" function.

BlitzMax Forums/BlitzMax Beginners Area/I don't understand "MOD" function.

Can someone explain it to me? The wikipedia explanation makes no sense to me.

MOD returns the remainder after a division.

So for example 2 goes into 10 5 times with a remainder of 0... 10 MOD 2 equals 0

2 goes into 11 5 times with a remainder of 1... 11 MOD 2 equals 1

[EDIT]
Some realworld examples,

Say for example you had a variable representing seconds, then MOD 60 would remove the whole minutes and return the remaining seconds...

182 MOD 60 would return 2 ( removing 3 minutes '3*60')

Say for example you had a variable representing an angle,

;increment the angle
angle=(angle+1) MOD 360

then MOD 360 would remove any 360 degree rotation and make the value appear to wrap around e.g. 358,359,0,1,2,3

Without MOD the above would be
angle=angle+1:If angle>360 Then angle=angle-360

Nice one Shambler Thanks :)

Now do you understand my solution to your block problem, Amon?

Now do you understand my solution to your block problem, Amon?


I think so. :)

Then again I may ask for more help because I was kindof wanting the block to move left/right-up/down according to what key I pressed.

Ah, then my solution won't help you. Though the solution you want would be equally simple.

i use the mod function for tiled maps
ie.

tx = (mousex() - (mousex() mod tilewidth)) / tilewidth
ty = (mousey() - (mousey() mod tileheight)) / tileheight

if mousehit(1) then map[tx, ty] = placetile


Integer division automatically discards the remainder. So you could use
tx = mousex() / tilewidth
ty = mousey() / tileheight
I'm assuming all those numbers are integers.

yeah.. but I think he wants the "coords" to jump in steps of tilesize, and then he can just insert them into his level array?!

(I think.. :P)