mod

Usage

-- Lingo syntax 
integerExpression1 mod integerExpression2 
 
// JavaScript syntax 
integerExpression1 % 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:

-- Lingo syntax 
put(7 mod 4) 
 
// JavaScript syntax 
put(7 % 4);

The result is 3.

The following 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.

-- Lingo syntax 
on setInk 
    repeat with mySprite = 1 to _movie.lastChannel 
        if (mySprite mod 2) = 1 then 
            sprite(mySprite).ink = 0 
        else 
            sprite(mySprite).ink = 8 
        end if 
    end repeat 
end setInk 
 
// JavaScript syntax 
function setInk() { 
    for (mySprite=1; mySprite<=_movie.lastChannel; mySprite++) { 
        if ((mySprite % 2) == 1) { 
            sprite(mySprite).ink = 0; 
        } else { 
            sprite(mySprite).ink = 8; 
        } 
    } 
}

This handler regularly cycles a sprite’s cast member among a number of bitmaps:

-- Lingo syntax 
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] 
    _movie.go(_movie.frame) 
end 
 
// JavaScript syntax 
function exitFrame() { 
    // these are sample values for bitmap cast member numbers 
    theBitmaps = new Array(2,3,4,5,6,7); 
    // specify which sprite channel is affected 
    theChannel = 1; 
    // this cycles through the list 
    _global.gCounter = 1 + (_global.gCounter % theBitmaps.length); 
    sprite(theChannel).memberNum = theBitmaps[_global.gCounter]; 
    _movie.go(_movie.frame); 
}