[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: 39
Joined: Thu Oct 03, 2019 5:57 pm

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

Post 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?
Last edited by YounYokel on Thu Oct 10, 2019 4:37 pm, edited 1 time in total.
User avatar
YounYokel
Prole
Posts: 39
Joined: Thu Oct 03, 2019 5:57 pm

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

Post by YounYokel »

pgimeno wrote: Wed Oct 09, 2019 6:23 pm Use / instead of \
Oops. That was silly :P
User avatar
HDPLocust
Citizen
Posts: 65
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 »

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: 3548
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 »

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 »

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: Bing [Bot], dusoft, Semrush [Bot] and 85 guests