0 votes

I need this in order to implement proper file saving in a little app I am making in godot 2.3

I havent upgraded it to 3*, because the task is too huge.
I need to do this in gdscript, and have no idea how to do it in a clean way:
https://nodejs.org/api/path.html#path_path_relative_from_to

then of course convert the relative paths back to absolute paths. How does one do it in godot?

asked Feb 5, 2019 in Engine by blurymind (90 points)

1 Answer

+1 vote

I am still unsure if you search the answer for Godot 3.x oder 2.x. Also some example paths would be helpful. Also why the paths would be relative and why there would be the need to convert them. I am also unsure if you mean relative paths in term of "res://" and "user://" or in terms of "../fileinparentdir.txt".

Helpful for path management (i put Godot 3.x links in here) is the File class:
https://docs.godotengine.org/en/latest/classes/class_file.html?highlight=absolute
It has the methods: get_path and get_path_absolute
The caveat is that a file has to be opened for read to be able to use these methods. (I see no other way here at least)

Another helpful class is the String class:
https://docs.godotengine.org/en/latest/classes/class_string.html?highlight=path

It has some methods to split up a path to directory/filename/extension and also the methods : bool is_abs_path ( ) and bool is_rel_path ( )

Then there's also the OS class which gives paths to some directory used in the operating system. You can get these together with string functions to i.e. move paths between user:// and the absolute OS path.

Be aware that there might not always be a resource data dir in a released app. Resources (images, 3d, sound) might as well be into some package. Also ressources which you import/copy into a godot 3 project might not be present in the release as they may be converted and moved into another directory.

answered Feb 6, 2019 by wombatstampede (3,123 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.