Could not open external file. Does not exist.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
AleVerDes
Prole
Posts: 2
Joined: Wed Jun 05, 2013 9:53 pm

Could not open external file. Does not exist.

Post 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?
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

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

Post 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.
Shallow indentations.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

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

Post 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" )
AleVerDes
Prole
Posts: 2
Joined: Wed Jun 05, 2013 9:53 pm

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

Post 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.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

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

Post 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.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

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

Post 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.
Shallow indentations.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

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

Post 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.
quacktical
Prole
Posts: 2
Joined: Sun Jun 09, 2013 10:54 pm

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

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post by bartbes »

You do know you can have subdirectories.. right?
quacktical
Prole
Posts: 2
Joined: Sun Jun 09, 2013 10:54 pm

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

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Nikki and 5 guests