The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

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:

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

in Engine by (100 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:
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:

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.

by (3,370 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.