I don't understand "MOD" function.

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

Amon_old(Posted 2005) [#1]
Can someone explain it to me? The wikipedia explanation makes no sense to me.


Shambler(Posted 2005) [#2]
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


Amon_old(Posted 2005) [#3]
Nice one Shambler Thanks :)


Ryan Moody(Posted 2005) [#4]
Now do you understand my solution to your block problem, Amon?


Amon_old(Posted 2005) [#5]
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.


Ryan Moody(Posted 2005) [#6]
Ah, then my solution won't help you. Though the solution you want would be equally simple.


Diablo(Posted 2005) [#7]
i use the mod function for tiled maps
ie.




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


LarsG(Posted 2005) [#9]
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)