Two-dimensional array initialization

Hi!
How to insert value to Two-dimensional array?

1
2
3
a = 
{0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1}

not understanding your question then array given above is not 2d
are you asking how to make it 2d or how to insert a new value to the array

This will create a multi-dimensional array of 10 x 10 with every value set to zero:

1
2
3
4
5
6
7
myarray = {}
for f=1, 10 do
    myarray[f] = {}
    for g=1, 10 do
        myarray[f][g] = 0
    end
end

In cpp it's look like:

1
2
3
4
tab[][] = {
{0,0,0},
{1,1,1}
};

1
2
3
4
5
6
7
8
9
10
a = {}
a[1] = {1,2,3}
a[2] = {4,5,6}
a[3] = {7,8,9}
 
for y = 1, 3 do
    for x = 1, 3 do
         print(a[y][x])
    end
end

Thanks for help

views:1699 update:2012/2/9 11:37:26
corona forums © 2003-2011