# Help using an array

**URL:** <https://forum.kirupa.com/t/help-using-an-array/257691>\
**Category:** flash\
**Created:** [April 16, 2008, 11:55am UTC](https://forum.kirupa.com/t/help-using-an-array/257691 "2008-04-16T11:55:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Callum87](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@Callum87](https://forum.kirupa.com/u/Callum87)\
**Post date:** [April 16, 2008, 11:55am UTC](https://forum.kirupa.com/t/help-using-an-array/257691/1 "2008-04-16T11:55:40Z")

</div>

Hi all,

I have created a snakes and ladders board game which uses an array to produce the board (10x10) and to randomly assign ‘snakes’ and ‘ladders’. These details are numerical for example the trace for a typical game is as follows:

```auto
Square 34 goes to 25.
Square 61 goes to 59.
Square 62 goes to 68.

```

What I want to happen is to somehow show the snakes and ladders visually on the array grid. I’ve created the grid and that displays a 10x10 board with each square numbered. If the number is greater than the first then its a ladder if its less it’s a snake. I’m lost as to how to visually show the snakes and ladders on the board.

```auto

//Create the game board
for (t=0; t<100; t++) { //Create 100 tiles
    if (random(100)<90) { //Generate number of special tiles
        gameBoard.push(t);
    } else {
        gameBoard.push(Math.max((Math.min((t+random(25)-14), 99)), 0)); //Generate random lengths of snakes and ladders
    }
}

var sqX:Number = 290; //Position of board
var sqY:Number = 320;
var sqNum:Number = 1;

for (j=1; j<=10; j++) {
    for (i=1; i<=10; i++) {
        duplicateMovieClip(square, "square"+j+i, 100+sqNum);
        _root["square"+j+i].gotoAndStop(gameBoard[sqNum-1]);
        _root["square"+j+i].sqNum.text = sqNum;
        _root["square"+j+i]._x = sqX;
        if ((int(j/2)*2) == j) {
            if (i != 10) {
                sqX -= 30;
            }
        } else {
            if (i != 10) {
                sqX += 30;
            }
        }
        _root["square"+j+t]._y = sqY;
        sqNum++;
    }
    sqY -= 30;
}

//Display random special tiles
for (t=0; t<gameBoard.length; t++) {
    trace("Square "+(t+1)+" goes to "+(gameBoard[t]+1)+".");
    if (gameBoard[t] != t) {
    }
}

```

Any help would be great, thanks.
