[SOLVED] How do I import files from specific folder in the 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.
Post Reply
User avatar
YounYokel
Prole
Posts: 33
Joined: Thu Oct 03, 2019 5:57 pm
Location: Kazakhstan

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

Post by YounYokel » Wed Oct 09, 2019 3:45 pm

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?
Last edited by YounYokel on Thu Oct 10, 2019 4:37 pm, edited 1 time in total.


User avatar
YounYokel
Prole
Posts: 33
Joined: Thu Oct 03, 2019 5:57 pm
Location: Kazakhstan

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

Post by YounYokel » Thu Oct 10, 2019 4:36 pm

pgimeno wrote:
Wed Oct 09, 2019 6:23 pm
Use / instead of \
Oops. That was silly :P

User avatar
HDPLocust
Citizen
Posts: 64
Joined: Thu Feb 19, 2015 10:56 pm
Location: Swamp
Contact:

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

Post by HDPLocust » Tue Jan 07, 2020 7:57 am

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.
Science and violence

User avatar
pgimeno
Party member
Posts: 2313
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno » Tue Jan 07, 2020 9:44 am

It's not advisable to use \ for paths anyway if you want your code to run in multiple platforms.

User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

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

Post by raidho36 » Tue Jan 07, 2020 3:48 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests