Hi!
How to insert value to Two-dimensional array?
[lua]a =
{0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1}[/lua]
Don’t give results.
Thanks for answers [import]uid: 117910 topic_id: 21221 reply_id: 321221[/import]
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 [import]uid: 7911 topic_id: 21221 reply_id: 84028[/import]
This will create a multi-dimensional array of 10 x 10 with every value set to zero:
myarray = {}
for f=1, 10 do
myarray[f] = {}
for g=1, 10 do
myarray[f][g] = 0
end
end
Hope that helps. [import]uid: 115159 topic_id: 21221 reply_id: 84029[/import]
In cpp it’s look like:
[cpp]
tab[][] = {
{0,0,0},
{1,1,1}
};
[/cpp]
I want this in lua [import]uid: 117910 topic_id: 21221 reply_id: 84031[/import]
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
in theory you should be able to:
a = {{1,2,3}, {4,5,6}, {7,8,9}}
[import]uid: 19626 topic_id: 21221 reply_id: 84032[/import]
Thanks for help [import]uid: 117910 topic_id: 21221 reply_id: 84077[/import]