File lines to table (lua question)
Posted: Wed Jul 31, 2013 3:54 pm
I'd like to know who to load the lines of a file into a table or an array.
Here's an exemple file:
And I would like to put those lines into a bidimensional array or table like so:
I already found this on the web:
But whenever I do print(unpack(line_data[1])) I get an empty output, I've also tried print(line_data[1][1]) and I get nil.
print(line_data[1]) gives me table: 00xxxxxx
So can someone please help me on loading lines into arrays (bidimensional)
Thanks for reading
Here's an exemple file:
Code: Select all
0,0,0,0
1,0,1,1
0,1,0,0
0,0,0,0
Code: Select all
line[1][1]=0
...
line[1][4]=0
line[2][1]=1
line[2][2]=0
...
line[2][4]=1
line[3][1]=0
...
line[3][4]=0
.
.
.
Code: Select all
map_file = assert(io.open('map.txt'))
local line_data = {}
for line in map_file:lines() do
local character_array = {}
for i = 1, #line do
character_array[#character_array + 1] = line[i];
end
line_data[#line_data + 1] = character_array
end
print(line_data[1]) gives me table: 00xxxxxx
So can someone please help me on loading lines into arrays (bidimensional)
Thanks for reading