Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Schwender.exe
Prole
Posts: 21
Joined: Mon Oct 16, 2017 6:07 pm
Contact:

so I made a small level editor which I've been working on for quite some time, it does everything you'd expect one to do, lets you save/load has commands to edit things, etc. However, when trying to make a demo for my game so others could play it, I ran into an issue, when exporting it into a zip and then renaming it a .love, when I launched it, it didn't load a level like it normally does, aka it couldn't find the level. I save/load levels by using the lua file functions with tserial (lets me save tables so I don't have to manually save everything), I then load it by opening the file of levels, finding the level with the matching string/name and having it spawn all of the tiles how they were when I saved. it worked fine, however it seems that when in a .love file, it forgets how to load a level. is there a way I could save/load levels without having to have the levels file be external from the .love?

source for my save:

Code: Select all

function Editor:savelevel(filename)
local drop = {}
if filename == nil then
filename = self.roomname
else
self.roomname = filename
end
filename = self.savePath.."Levels/"..filename..".lvl"
local tiles = {}
local doors = {}
for i=1,#Tiles do
if Tiles[i].args.door then
table.insert(doors,Tiles[i])
else
table.insert(tiles,Tiles[i])
end
end
local f = io.open(filename,"w")
local saveString = "{"..self.roomw..","..self.roomh.."}\n"..Tserial.pack(tiles,drop,false).."\n"..Tserial.pack(doors,drop,false)
f:write(filename,saveString)
f:close()
self.console_errtxt = "level \""..filename.."\" saved!"
end


Code: Select all

function Editor:loadlevel(filename)
filename = string.lower(filename)
self.roomname = filename
filename = self.savePath.."Levels/"..filename..".lvl"
local line = {}
if file_check(filename) then
self:clearlevel()
local f = io.open(filename)
for lines in f:lines() do
table.insert(line,lines)
end
f:close()
self.roomw,self.roomh = string.match(tostring(line[1]),'{(%d+),(%d+)}')
self.roomw,self.roomh = tonumber(self.roomw),tonumber(self.roomh)
Tiles = Tserial.unpack(tostring(line[2]),true)
if line[3] ~= nil then
local doors = Tserial.unpack(tostring(line[3]),true)
for d=1,#doors do
table.insert(Tiles,doors[d])
end
end
cam:setWorld(-32,-32,self.roomw+64,self.roomh+64)
for i,v in ipairs(Tiles) do
if v.args.playerSpawn then
player.spawnx = v.x+8
player.spawny = v.y+8
player.x = player.spawnx
player.y = player.spawny
end
end
else
self.console_errtxt = "level \""..filename.."\" doesn't exist!"
end
end

Last edited by Schwender.exe on Sat Jun 23, 2018 2:35 pm, edited 1 time in total.
¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯
¯\_(ツ)_/¯ just.... trying ¯\_(ツ)_/¯
¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯

grump
Party member
Posts: 509
Joined: Sat Jul 22, 2017 7:43 pm

Schwender.exe
Prole
Posts: 21
Joined: Mon Oct 16, 2017 6:07 pm
Contact:

grump wrote:
Fri Jun 22, 2018 6:35 pm
I re-wrote it using love.filesystem.read and it still won't load levels when it's within a .love
¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯
¯\_(ツ)_/¯ just.... trying ¯\_(ツ)_/¯
¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯

grump
Party member
Posts: 509
Joined: Sat Jul 22, 2017 7:43 pm

Then there's another issue in your code. Post an error message. If there is none, reduce your code to a minimal example that reproduces the problem, then post that code.

You probably want to use love.filesystem.lines, not love.filesystem.read.

Code: Select all

for line in assert(love.filesystem.lines(filename)) do
...

Schwender.exe
Prole
Posts: 21
Joined: Mon Oct 16, 2017 6:07 pm
Contact:

grump wrote:
Fri Jun 22, 2018 6:55 pm
Then there's another issue in your code. Post an error message. If there is none, reduce your code to a minimal example that reproduces the problem, then post that code.

You probably want to use love.filesystem.lines, not love.filesystem.read.

Code: Select all

for line in assert(love.filesystem.lines(filename)) do
...
interestingly, I found no errors, it just loaded a blank level (as it usually does) which makes no sense, usually if it finds no level it displays a message, but it didn't this time either.interesting though, when trying to save a level it would crash on file:write() unless the Levels file was present in the same folder, but I want to keep the level files within the .love
¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯
¯\_(ツ)_/¯ just.... trying ¯\_(ツ)_/¯
¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯

pgimeno
Party member
Posts: 1502
Joined: Sun Oct 18, 2015 2:58 pm

You can't *save* to a file inside a .love file.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

Schwender.exe
Prole
Posts: 21
Joined: Mon Oct 16, 2017 6:07 pm
Contact:

pgimeno wrote:
Sat Jun 23, 2018 12:44 am
You can't *save* to a file inside a .love file.
there's go to be some way, it can get the textures fine using love.graphics.newImage(), so it is possible, I just need to figure out how
¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯
¯\_(ツ)_/¯ just.... trying ¯\_(ツ)_/¯
¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯

zorg
Party member
Posts: 2510
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Schwender.exe wrote:
Sat Jun 23, 2018 1:11 am
pgimeno wrote:
Sat Jun 23, 2018 12:44 am
You can't *save* to a file inside a .love file.
there's got to be some way, it can get the textures fine using love.graphics.newImage(), so it is possible, I just need to figure out how
newImage, like any other constructor reads data; that is indeed possible. the fact that it can access parts of a zip archive (which is what löve files are) is one thing, but to modify it, you'd need to modify the code "from under" itself, and that's not happening. (As long as the code is running, the file is locked, which is an assumption on my end; you can't overwrite/edit the archive.)
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Schwender.exe
Prole
Posts: 21
Joined: Mon Oct 16, 2017 6:07 pm
Contact:

zorg wrote:
Sat Jun 23, 2018 4:48 am
Schwender.exe wrote:
Sat Jun 23, 2018 1:11 am
pgimeno wrote:
Sat Jun 23, 2018 12:44 am
You can't *save* to a file inside a .love file.
there's got to be some way, it can get the textures fine using love.graphics.newImage(), so it is possible, I just need to figure out how
newImage, like any other constructor reads data; that is indeed possible. the fact that it can access parts of a zip archive (which is what löve files are) is one thing, but to modify it, you'd need to modify the code "from under" itself, and that's not happening. (As long as the code is running, the file is locked, which is an assumption on my end; you can't overwrite/edit the archive.)
ah ok, well I talked with a few other devs and I fixed the loading part after figuring out it was the "file_check(path)" function because it used io.open() to check if the file existed instead of love.filesystem.getInfo(), after changing that and changing the load functions to love.filesystem it worked like normal even when in the .love! saving levels isn't 100% required because it's a platformer game, although I could eventually release a version where the level editor is usable, all I'd have to change is the game having to access player-created files from outside the .love/.exe
¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯
¯\_(ツ)_/¯ just.... trying ¯\_(ツ)_/¯
¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯ _ ¯\_(ツ)_/¯

Nixola
Inner party member
Posts: 1940
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

zorg wrote:
Sat Jun 23, 2018 4:48 am
Schwender.exe wrote:
Sat Jun 23, 2018 1:11 am
pgimeno wrote:
Sat Jun 23, 2018 12:44 am
You can't *save* to a file inside a .love file.
there's got to be some way, it can get the textures fine using love.graphics.newImage(), so it is possible, I just need to figure out how
newImage, like any other constructor reads data; that is indeed possible. the fact that it can access parts of a zip archive (which is what löve files are) is one thing, but to modify it, you'd need to modify the code "from under" itself, and that's not happening. (As long as the code is running, the file is locked, which is an assumption on my end; you can't overwrite/edit the archive.)
It's true you can't write inside a .love file, but not for that reason. Code files aren't locked once they're loaded, you can even delete them and it'll keep running just fine; you'd have to manually reload the file for any change to apply. The reason you can't is because LÖVE simply doesn't support editing zip files, which means it can't change the .love file contents.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics