I've created a level editor so I can make levels for my game, but I can't get it to write to a file.
All the data are in forms of tables, and I want to store them as tables in a .lua file, because that's how my game loads levels.
I don't have efficiency in mind right now, because I want to get it to work first. But it doesn't seem to be able to either create a file or write to it.
Here is my current code:
Code: Select all
function save()
love.filesystem.setIdentity("Dropbox/LuaTest/Level editor/Levels/")
love.filesystem.newFile("level.lua")
love.filesystem.write("level.lua", "object.X = {")
for i = 1, table.getn(object.X), 1 do
if object.D[i] ~= 1 then
str = string.format("%s, ", object.X[i])
love.filesystem.write("level.lua", str)
end
end
love.filesystem.write("level.lua", "}\n\n")
love.filesystem.write("level.lua", "object.Y = {")
for i = 1, table.getn(object.Y), 1 do
if object.D[i] ~= 1 then
str = string.format("%s, ", object.Y[i])
love.filesystem.write("level.lua", str)
end
end
love.filesystem.write("level.lua", "}\n\n")
love.filesystem.write("level.lua", "object.W = {")
for i = 1, table.getn(object.W), 1 do
if object.D[i] ~= 1 then
str = string.format("%s, ", object.W[i])
love.filesystem.write("level.lua", str)
end
end
love.filesystem.write("level.lua", "}\n\n")
love.filesystem.write("level.lua", "object.H = {")
for i = 1, table.getn(object.H), 1 do
if object.D[i] ~= 1 then
str = string.format("%s, ", object.H[i])
love.filesystem.write("level.lua", str)
end
end
love.filesystem.write("level.lua", "}\n\n")
love.filesystem.write("level.lua", "object.F = {")
for i = 1, table.getn(object.F), 1 do
if object.D[i] ~= 1 then
str = string.format("%s, ", object.F[i])
love.filesystem.write("level.lua", str)
end
end
love.filesystem.write("level.lua", "}\n\n")
love.filesystem.write("level.lua", "object.R = {")
for i = 1, table.getn(object.R), 1 do
if object.D[i] ~= 1 then
str = string.format("%s, ", object.R[i])
love.filesystem.write("level.lua", str)
end
end
love.filesystem.write("level.lua", "}\n\n")
love.filesystem.write("level.lua", "object.G = {")
for i = 1, table.getn(object.G), 1 do
if object.D[i] ~= 1 then
str = string.format("%s, ", object.G[i])
love.filesystem.write("level.lua", str)
end
end
love.filesystem.write("level.lua", "}\n\n")
love.filesystem.write("level.lua", "object.B = {")
for i = 1, table.getn(object.B), 1 do
if object.D[i] ~= 1 then
str = string.format("%s, ", object.B[i])
love.filesystem.write("level.lua", str)
end
end
love.filesystem.write("level.lua", "}")
end