Why is this file path invalid?

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
miguelito
Prole
Posts: 3
Joined: Sat Dec 05, 2020 6:34 pm
Location: Portugal

Why is this file path invalid?

Post by miguelito »

Hi all, first time poster here.

I have the following file system:

Code: Select all

project
|_ engine
|  |_ images.lua
|
|_ tilemaps
|  |_ export
|  |_ textures
|  |  |_ tileset_0.png
|  |
|  |_ worlds
|
|_ main.lua
in line 14 of images.lua I have the line

Code: Select all

local img = lovae.graphics.newImage("tilemaps/worlds/../export/../export/../textures/tileset_0.png")
where the path ("tilemaps/worlds/../export/../export/../textures/tileset_0.png") is previously concatenated by the program itself.

im getting the error:

Code: Select all

Error: engine/images.lua:14: Could not open file tilemaps/worlds/../export/../export/../textures/tileset_0.png. Does not exist.
meanwhile writing the path as "tilemaps/textures/pokemon_emerald_tileset_0.png" load the image just fine.

I don't get it. What am I missing?
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Why is this file path invalid?

Post by zorg »

Hi and welcome to the forums.

You can't use .. in paths, as far as i know. also, all paths are relative to both where your main.lua is, and the root of your project's save folder.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
miguelito
Prole
Posts: 3
Joined: Sat Dec 05, 2020 6:34 pm
Location: Portugal

Re: Why is this file path invalid?

Post by miguelito »

Yup, seems like I'll have to find a way to fix those paths. Thanks :)
User avatar
pgimeno
Party member
Posts: 3684
Joined: Sun Oct 18, 2015 2:58 pm

Re: Why is this file path invalid?

Post by pgimeno »

Maybe something like this?

Code: Select all

path = path:gsub("[^/]+/%.%./", "")
User avatar
miguelito
Prole
Posts: 3
Joined: Sat Dec 05, 2020 6:34 pm
Location: Portugal

Re: Why is this file path invalid?

Post by miguelito »

That would definitely work. But instead, I made a lua script that I run before I launch love that replaces all relative paths by the project path. As Tiled exports the paths relative to the tilemap/tileset. This way I can actually be a little more efficient at runtime, as I don't need to do any concatenations/substitutions.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests