i'm trying to read seperated lines out of a txt-file, to insert them as a map into my main.lua
The txt-file looks like this:
Code: Select all
0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0
0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0
0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0
Code: Select all
main = {}
function love.load()
local map = {}
for line in love.filesystem.lines("test.txt") do
table.insert(map, line)
end
end
end
function love.draw()
for y=1, #map do
for x=1, #map[y] do
if map[y][x] == 1 then
love.graphics.setColor(79,78,20)
love.graphics.rectangle("fill", x * scale, y * scale, scale, scale)
else
love.graphics.setColor(245,243,135)
love.graphics.rectangle("fill", x * scale+1, y * scale+1, scale-2, scale-2)
end
end
end
end
It would be perfect, if i could get rid of the line breaks as well, because they would disturb the structure of the map, i am trying to create with the txt file.
Thanks in advance to everybody.