Source path seems to be off..

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.
Post Reply
sam
Prole
Posts: 32
Joined: Sat Nov 10, 2012 2:18 am

Source path seems to be off..

Post by sam »

As I was programming, I attempted to load in text files from a folder inside of my source. Upon testing, it seems to be looking for files in the folder where I ran the game, not where the main source files are.

Image

The first printed path is my working directory, where it's looking for files. This should be set to my directory where I have my main.lua/conf.lua (my source folder), but is instead set to the directory where I've ran the love file. "res/dat/test.txt" is located inside of my game's source folder, which is where I would like to require files from.

Hopefully I didn't explain it too terribly, as I won't have access to the .love file for a while. If anyone could point me in the right direction, that would be great!

Edit: On further inspection, the source folder seems to be set to whatever directory I run my game from. Is there a way to only look for files inside the source directory?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Source path seems to be off..

Post by Robin »

How did you run LÖVE? And could you upload a .love that shows this problem for you?
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Source path seems to be off..

Post by bartbes »

That is because that is the working directory. If you're using love.filesystem, though, that shouldn't be a problem, since it doesn't care about the working directory.
sam
Prole
Posts: 32
Joined: Sat Nov 10, 2012 2:18 am

Re: Source path seems to be off..

Post by sam »

bartbes wrote:That is because that is the working directory. If you're using love.filesystem, though, that shouldn't be a problem, since it doesn't care about the working directory.
I was simply trying to load in a text file from a path using dofile(). The same error occurs when I try to load in an image from a path as well, as it's trying to look in my love directory for a res folder when the res folder is actually inside of my .love file.
Robin wrote:How did you run LÖVE? And could you upload a .love that shows this problem for you?
I'll be able to upload a .love file when I get home from work, but I ran it by simply dragging a properly structured .love file onto love.exe. The same error occurs when I drag the folder on top of love.exe as well.
sam
Prole
Posts: 32
Joined: Sat Nov 10, 2012 2:18 am

Re: Source path seems to be off..

Post by sam »

Finally was able to upload a .love file. Beware, super non-commented moonscript generated code ahead. This was made to be a test of a quick framework I'm making for myself for jam games, so that's why there's a ton of stuff in the lib folder that's not being used.
What you should probably be looking at is the reg.lua file, which has the paths that I concatenate along with the file names, as well as the loadLevel function that is throwing the error. You should be able to see the directories I'm trying to locate as well.
Attachments
frameworktest.love
(5.83 MiB) Downloaded 130 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Source path seems to be off..

Post by Robin »

reg.lua, line 13. Try replacing dofile(fn) with [wiki]love.filesystem.load[/wiki](fn)().

Fun fact: the love filesystem only affects require, not dofile or the io.* functions. (This is because require is extensible, while dofile etc. aren't, and LÖVE never overwrites the standard library)
Help us help you: attach a .love.
sam
Prole
Posts: 32
Joined: Sat Nov 10, 2012 2:18 am

Re: Source path seems to be off..

Post by sam »

Robin wrote:reg.lua, line 13. Try replacing dofile(fn) with [wiki]love.filesystem.load[/wiki](fn)().

Fun fact: the love filesystem only affects require, not dofile or the io.* functions. (This is because require is extensible, while dofile etc. aren't, and LÖVE never overwrites the standard library)
Thanks, this worked! Need to get this thing in working order for a local jam on Saturday, and that was stumping me. I'll be sure to use love.filesystem for these situations in the future.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests