Lingo Dictionary > L-N > mod |
![]() ![]() ![]() |
mod
Syntax
integerExpression1
mod
integerExpression2
Description
Math operator; performs the arithmetic modulus operation on two integer expressions. In this operation, integerExpression1
is divided by integerExpression2
.
The resulting value of the entire expression is the integer remainder of the division. It always has the sign of integerExpression1
.
This is an arithmetic operator with a precedence level of 4.
Example
This statement divides 7 by 4 and then displays the remainder in the Message window:
put 7 mod 4
The result is 3.
Example
This handler sets the ink effect of all odd-numbered sprites to copy
, which is the ink effect specified by the number 0. First the handler checks whether the sprite in the variable mySprite
is an odd-numbered sprite by dividing the sprite number by 2 and then checking whether the remainder is 1. If the remainder is 1, the result for an odd-numbered number, the handler sets the ink effect to copy
.
on setInk repeat with mySprite = 1 to the lastChannel if (mySprite mod 2) = 1 then sprite(mySprite).ink = 0 else sprite(mySprite).ink = 8 end if end repeat end setInk
Example
This handler regularly cycles a sprite's cast member among a number of bitmaps:
on exitFrame global gCounter -- These are sample values for bitmap cast member numbers theBitmaps = [2,3,4,5,6,7] -- Specify which sprite channel is affected theChannel = 1 -- This cycles through the list gCounter = 1 + (gCounter mod theBitmaps.count) sprite(theChannel).memberNum = theBitmaps[gCounter] go the frame end
![]() ![]() ![]() |