Replies: 2 comments 3 replies
-
I think overall, the suggestion feels overly-engineered, as most languages, APIs, or similar make no distinction. But, I do find a Path Variant type interesting... if NodePath didn't exist... |
Beta Was this translation helpful? Give feedback.
-
I like the idea, I don't know if it can be implemented fully right now, so it might be for the next major version (in particular if this a new type, which would be used from resource loading to inspector integration, making it a huge change). So, for our current version of Godot, I like the idea of Also, I believe it is possible (albeit more tricky) to have Godot could emit an actual check (with runtime error) if it is not possible to validate during parsing, and emit nothing if the validation happens entirely during parsing. I know it is not the same as an actual type: mainly you won't be able to specify that a variable must be a path (e.g. a method cannot have a parameter typed as a path), but at least the |
Beta Was this translation helpful? Give feedback.
-
Basically, add a type, or class, or global function that can check if the input
String
is an accurate path inside the project folder.Path
will have the most functions fromString
that specially used for path, OR they can just check the value, and then return the value asString
. They will also show code completion hint just like howload()/preload()
does for project files path.The benefits I can think of if this is implemented:
String
doesn't show the path hint from code completion or errors for wrong path.load()/preload()
only shows the path list once, and doesn't do the checking afterwards.load("string_unchecked")
that doesn't trigger an error during coding.@export_path
or similar can be introduced, which can resolve some of the exportedPackedScene
issues.String
. (Although user will still not be able to get written data from that path)@export_path
can automatically update when file is renamed or moved (but not deleted).String
doesn't because it accounts for generalString
value, butPath
only does for file path in the system.Extra thoughts:
Do we need siblings
res()
anduser_path()
?We could also use
res()
as the main name, so that we can skip theres://
when using it, e.g.res("folder/file.gd")
. That being said, usingpath()
would be consistent, and user can easily replace the function withload()/preload()
and vice versa.However, only
res://
is possible to be validated,user://
and absolute path aren't supported, as they might introduce user issues. And in that case, a better name might be needed instead ofPath
.On the other hand, there might be a reason why
load()/preload()
doesn't do validation on the inserted value. And the reason may be crucial to the proposal.I'd think that the engine can have a special case to push an error for
load()/preload()
functions to validate path (not sure if it'd work with external editors), otherwise, this proposal would require a new typePath
to handle the error validation.I believe a path validation is possible, as I did with my own custom script editor plugin, but not sure if doing that to the core engine is an OK thing or not.
Edited: I realized a critical issue with this proposal, as user can combine
String
andvariable
e.g.var path = path("folder/" + file_name)
. Either we find a way to circumvent, or we reduce down to@export_path
that doesn't involve combination of values.Beta Was this translation helpful? Give feedback.
All reactions