Page 1 of 2

Could not open external file. Does not exist.

Posted: Wed Jun 05, 2013 10:01 pm
by AleVerDes
Hello.

I use the first day Love2D, but the engine already very much is pleasant to me. I carried out all evening behind documentation, but didn't find the answer to the question. So, I want to use the external folder for storage of graphics and sounds. That is, at me is game.exe and the data folder where there are game images.

I tried to write such code:
function love.load ()
dirwork = love.filesystem.getWorkingDirectory ()
hamster = love.graphics.newImage (dirwork. "/data/hamster.png")
end

But to me write that: Could not open file D:/Game/data/hamster.png. Does not exist.

Whether can load Love2D the graphic file from the outside or I should push everything in game.exe?

Re: Could not open external file. Does not exist.

Posted: Wed Jun 05, 2013 10:31 pm
by Boolsheet
The love.filesystem page has information on this. It does not take absolute paths and it can only read from the save directory and the game directory/archive. Yes, the idea is that you pack everything into the archive. If you really have to go outside of these directories, you have to use the Lua IO library (not recommended because of portability issues) or some Lua module that provides file system access.

Also note that the working directory can point anywhere on the file system. This does not have to be the path of the executable.

Re: Could not open external file. Does not exist.

Posted: Wed Jun 05, 2013 10:33 pm
by Plu
Once you convert the game to a .exe all the image files and such should be inside the .exe (you first make a .love file; a zipped folder with everything in it except .dll and such and then merge that into the love.exe)

But during development, you can keep them stored outside as long as they are in the same folder, and you won't need to add the getWorkingDirectory() part when including files. You can just include "love.graphics.newImage( "path/hamster.png" )

Re: Could not open external file. Does not exist.

Posted: Wed Jun 05, 2013 10:44 pm
by AleVerDes
I would like to give the user the ability to modify the game without opening its source. Actually, that interests me OPEN game resources.

If there is any way to load an image from the outside - can I get it? You said something about Lua IO - even if I can use it if I can upload an image in Love? Or is there any other solutions? Besides LoveFS - annoying flash terminals at startup.

Re: Could not open external file. Does not exist.

Posted: Wed Jun 05, 2013 11:02 pm
by Plu
If you want to allow modding, the best solution might be to simply not pack everything into a .exe file, but instead leave everything unpacked. You can change the arguments passed to love.exe when it runs so that it opens the game when you doubleclick it and then rename the file to the name of your game. That way all the files are available for users to edit, including pictures and such.

Re: Could not open external file. Does not exist.

Posted: Wed Jun 05, 2013 11:03 pm
by Boolsheet
You could also write your resources to the save directory and let the users modify that. Like the love.filesystem page says, it has precedence over the game directory and it will load the things from there if the file names match. Sadly, the different operating systems make it a bit tricky for the average user to get to the application data specific directories (they mark them as hidden).

If you use the Lua IO (or another module) you would have to go over FileData to get an Image or one of the other things out of it.
AleVerDes wrote:Or is there any other solutions? Besides LoveFS - annoying flash terminals at startup.
I was thinking LuaFileSystem instead of a massive abuse of os.execute and io.popen. ;) Then again, loading binary modules with the official LÖVE 0.8.0 Windows binary is a bit cumbersome because it linked Lua statically. Just placing a different Lua DLL into the executable directory works, but is really not a clean approach.

Re: Could not open external file. Does not exist.

Posted: Fri Jun 07, 2013 2:34 pm
by T-Bone
Boolsheet wrote:You could also write your resources to the save directory and let the users modify that. Like the love.filesystem page says, it has precedence over the game directory and it will load the things from there if the file names match. Sadly, the different operating systems make it a bit tricky for the average user to get to the application data specific directories (they mark them as hidden).

This. Then all you have to do is to help your users find the files. Alternatively, you can create the files from within LÖVE and save them with love.filesystem.

My game has a level editor that allows you to create and modify levels. The levels you make or modify are placed in the love.filesystem directory and will automatically be loaded instead of the built in levels.

Re: Could not open external file. Does not exist.

Posted: Sun Jun 09, 2013 11:10 pm
by quacktical
Is there any possibility that this restriction might be removed in the future? It seems quite obnoxious to not be able to have a resources or data folder inside your project folder, as I would really like to be able to use a file structure for organization, especially when projects get large. Having everything just lumped in one folder seems like it has a lot of potential for really tough problems later on in projects, especially mine, where I will have lots and lots of images used for animations.

Re: Could not open external file. Does not exist.

Posted: Mon Jun 10, 2013 3:26 pm
by bartbes
You do know you can have subdirectories.. right?

Re: Could not open external file. Does not exist.

Posted: Mon Jun 10, 2013 6:23 pm
by quacktical
Ah yes, I do. I was having what turned out to be an unrelated problem, which I have now fixed. I feel dumb. :P