How to load a file from game directory

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.
luaz
Citizen
Posts: 83
Joined: Sun Sep 16, 2012 2:55 pm

Re: How to load a file from game directory

Post by luaz »

Sounds complicated, and yet very cool. I'm excited. :emo:
If you're going to reply to my post, consider posting an (preferably working) example - 99.7% of time time, I already know how to implement the feature theoretically! ;) I don't learn very well from references, etc....
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How to load a file from game directory

Post by Robin »

Przemator wrote:What if I want to distribute the game as EXE, but would like users to create custom maps/levels/mods and share them? Then they would be forced to put the mod inside the save folder?
"Forced" is a bit strong, but basically yes. Note that you (as lover) don't have to do anything for the save directory (except setting identity, and I believe LÖVE will use a reasonable default based on the file name of the .love or whatever if it's not given), so you could have regular maps, levels and whatever in the .love and folks can use the save directory to put their own maps, levels and mods and it will work automatically. (Although for mods you will usually want to provide some sort of framework or API to your game to make modding easier.)
Help us help you: attach a .love.
User avatar
Przemator
Party member
Posts: 107
Joined: Fri Sep 28, 2012 6:59 pm

Re: How to load a file from game directory

Post by Przemator »

Robin wrote:"Forced" is a bit strong, but basically yes. Note that you (as lover) don't have to do anything for the save directory (except setting identity, and I believe LÖVE will use a reasonable default based on the file name of the .love or whatever if it's not given), so you could have regular maps, levels and whatever in the .love and folks can use the save directory to put their own maps, levels and mods and it will work automatically. (Although for mods you will usually want to provide some sort of framework or API to your game to make modding easier.)
This sounds reasonable. It's a shame though, that LOVE does not allow to write inside the game folder, where the EXE resides.

I just ran a quick test and this is what LOVE returns using the following functions:

Code: Select all

getAppdataDirectory: C:/Users/Przemek/AppData/Roaming
getSaveDirectory:    C:/Users/Przemek/AppData/Roaming/LOVE/test
getUserDirectory:    C:\Users\Przemek\
getWorkingDirectory: C:/Program Files (x86)/LOVE
So I guess the custom data goes to C:/Users/Przemek/AppData/Roaming/LOVE/test. I put main.lua inside a "test" folder, and LOVE used this name to create the save folder. Wonder if this can be changed, or does always game folder name = save folder name?
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: How to load a file from game directory

Post by Roland_Yonaba »

Przemator wrote: So I guess the custom data goes to C:/Users/Przemek/AppData/Roaming/LOVE/test. I put main.lua inside a "test" folder, and LOVE used this name to create the save folder. Wonder if this can be changed, or does always game folder name = save folder name?
Nope.
The name of the folder inside the AppData directory comes from what you have set in love.conf:

Code: Select all

function love.conf(t)
  t.identity = 'MyGame'
end
With this, the save directory will be C:/Users/Przemek/AppData/Roaming/LOVE/MyGame, even if your project directory is titled "FooBlaBla".
Side note, you can have the same result using love.filesystem.setIdentity().
User avatar
Przemator
Party member
Posts: 107
Joined: Fri Sep 28, 2012 6:59 pm

Re: How to load a file from game directory

Post by Przemator »

Roland_Yonaba wrote:The name of the folder inside the AppData directory comes from what you have set in love.conf:
Cheers, that's what I wanted :)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: How to load a file from game directory

Post by bartbes »

Przemator wrote:It's a shame though, that LOVE does not allow to write inside the game folder, where the EXE resides.
I've seen people complaing about this before, but you assume that this is good practice. Let's see, oh yeah, not everyone has their binaries next to their data (see linux). Barely anyone has write access to the directory programs are usually installed in (see windows, linux).

Let's also illustrate the "badness" of this by looking at windows, and its wonderful ProgramData directory, showing off that everybody writing to Program Files is Doing It Wrong.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: How to load a file from game directory

Post by Lafolie »

I agree with bartbes. I keep my applications in /Applications and would prefer this directory not to be cluttered with save files and folders. Plus, I'm quite keen on seLöve and the security and peace of mind it has to offer, and wish to provide support for those that use it.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
slime
Solid Snayke
Posts: 3163
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How to load a file from game directory

Post by slime »

Lafolie wrote:I agree with bartbes. I keep my applications in /Applications and would prefer this directory not to be cluttered with save files and folders. Plus, I'm quite keen on seLöve and the security and peace of mind it has to offer, and wish to provide support for those that use it.
In the case of OSX apps, everything is contained inside the .app, including the executable and all of the media and resources for most games. Save and settings information is stored in the usual places (Application Support or Documents).

Bartbes: write access probably isn't a good idea, but read access definitely is in my opinion.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: How to load a file from game directory

Post by Lafolie »

Of course I knew this slime, but perhaps you're setting the scene for others too.

I don't see this being a problem so much anyway. If you would like to play it safe, use love.filesystem. If you prefer to have access to more locations and aren't afraid of any problems that may arise, use lua io. I'm not sure what drawbacks there may be with using standard io with löve though.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: How to load a file from game directory

Post by Positive07 »

Maybe in a future release the appdata folder could be changed to the game folder or maybe use both so if I ran MyGame.love with the t.indentity set to MYGAMEFOLDER I would have

AppData/Roaming/LOVE/MYGAMEFOLDER

and

%Folder where my game is%/MYGAMEFOLDER

and I could select between both of them
Just an idea thought.
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 2 guests