Page 1 of 1

Source path seems to be off..

Posted: Thu May 28, 2015 3:52 am
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?

Re: Source path seems to be off..

Posted: Thu May 28, 2015 6:41 am
by Robin
How did you run LÖVE? And could you upload a .love that shows this problem for you?

Re: Source path seems to be off..

Posted: Thu May 28, 2015 8:02 am
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.

Re: Source path seems to be off..

Posted: Thu May 28, 2015 8:25 pm
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.

Re: Source path seems to be off..

Posted: Thu May 28, 2015 11:21 pm
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.

Re: Source path seems to be off..

Posted: Fri May 29, 2015 1:17 am
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)

Re: Source path seems to be off..

Posted: Fri May 29, 2015 1:34 am
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.