Arrays question!
#5

I think the easiest way to think of them is to think of them as pockets.

pawn Code:
new arr[2];
You have 2 pockets where you can store 1 number in each.

pawn Code:
new arr[2][2];
You have 2 pockets where you can store 2 numbers in each.

pawn Code:
new arr[5][10];
You have 5 pockets where you can store 10 numbers in each.


If you want to put numbers in those pockets when declaring the array, simply do this:
pawn Code:
new arr[5][10] =
{
    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, // 1. pocket with 10 numbers
    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, // 2. pocket with 10 numbers
    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, // 3. pocket with 10 numbers
    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, // 4. pocket with 10 numbers
    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } // 5. pocket with 10 numbers
};
If you want to edit the array after declaring it, simply do this:
pawn Code:
arr[0][0] = 10;
arr[0][1] = 11;
arr[0][2] = 12;
arr[0][3] = 13;
arr[0][4] = 14;
arr[0][5] = 15;
arr[0][6] = 16;
arr[0][7] = 17;
arr[0][8] = 18;
arr[0][9] = 19;

arr[1][0] = 10;
arr[1][1] = 11;
arr[1][2] = 12;
arr[1][3] = 13;
arr[1][4] = 14;
arr[1][5] = 15;
arr[1][6] = 16;
arr[1][7] = 17;
arr[1][8] = 18;
arr[1][9] = 19;

etc.
Also, wrong section.
Reply


Messages In This Thread
Arrays question! - by Kush - 09.09.2012, 17:43
Re: Arrays question! - by leonardo1434 - 09.09.2012, 17:50
Re: Arrays question! - by Larceny - 09.09.2012, 18:02
Re: Arrays question! - by Vince - 09.09.2012, 18:24
Re: Arrays question! - by Finn - 09.09.2012, 19:10

Forum Jump:


Users browsing this thread: 1 Guest(s)