Page 1 of 1

Why is this file path invalid?

Posted: Sat Dec 05, 2020 6:53 pm
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?

Re: Why is this file path invalid?

Posted: Sat Dec 05, 2020 8:27 pm
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.

Re: Why is this file path invalid?

Posted: Sat Dec 05, 2020 10:10 pm
by miguelito
Yup, seems like I'll have to find a way to fix those paths. Thanks :)

Re: Why is this file path invalid?

Posted: Sun Dec 06, 2020 11:39 am
by pgimeno
Maybe something like this?

Code: Select all

path = path:gsub("[^/]+/%.%./", "")

Re: Why is this file path invalid?

Posted: Sun Dec 06, 2020 3:22 pm
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.