Page 1 of 1

[SOLVED] How do I import files from specific folder in the game directory?

Posted: Wed Oct 09, 2019 3:45 pm
by YounYokel
Hello! It's quite weird for me, but when I'm setting the new font but I cannot import the font from a folder, I need to type the name only. If that file doesn't exists in the project folder, game will crash.

Code: Select all

local myFont = love.graphics.newFont( "fonts\opensans.ttf", 14 )
What should I do to allow the folders in my project?

Re: How do I import files from specific folder in the game directory?

Posted: Wed Oct 09, 2019 6:23 pm
by pgimeno
Use / instead of \

Re: How do I import files from specific folder in the game directory?

Posted: Thu Oct 10, 2019 4:36 pm
by YounYokel
pgimeno wrote:
Wed Oct 09, 2019 6:23 pm
Use / instead of \
Oops. That was silly :P

Re: [SOLVED] How do I import files from specific folder in the game directory?

Posted: Tue Jan 07, 2020 7:57 am
by HDPLocust
You sould use [\\] (it's regular backslash character). Backslash is the escape character in lua strings:

Code: Select all

print("Backslash is here \\") --> Backslash is here \ 
Also multiline/unescaped strings can be achived with [[]] syntax:

Code: Select all

 print([[Backslash is here \]]) --> Backslash is here \ 
Backslash is used for some tasks, like using different types of quotes in string, or using special symbols:

Code: Select all

print("\33") --> !, 33-byte is "!" symbol
print("'singlequoted text' \"doublequoted text\"") -->'singlequoted text' "doublequoted text"
So it's just lua syntax.

Re: [SOLVED] How do I import files from specific folder in the game directory?

Posted: Tue Jan 07, 2020 9:44 am
by pgimeno
It's not advisable to use \ for paths anyway if you want your code to run in multiple platforms.

Re: [SOLVED] How do I import files from specific folder in the game directory?

Posted: Tue Jan 07, 2020 3:48 pm
by raidho36
Also backslash will not work for zipped archives and by extension for fused games. In general you should just always use forward slash for file paths.

On a tangent, the "require" function doesn't work on file paths, it works on module names. So I recommend using dot notation there, just to avoid confusion.