Hide "private" properties with an underscore from users by default. #33
Replies: 4 comments
-
Beta Was this translation helpful? Give feedback.
-
Yeah, I could see this being in the ProjectSettings or something.
Perhaps. But there is precedent in other languages though, for example, Dart.
Yes, as in, having private properties and methods that are accessible within the class, but which are not visible to logic outside of the class.
If have GDScript does not yet have a way of indicating whether something is private or public. I could imagine a scenario where underscore-prefixed methods, properties, and constants are inaccessible outside of the class. Although, it definitely gets tricky since signal callbacks are regularly underscore-prefixed as well. A full
The first is a virtual engine callback. You return an Array of Dictionaries with specific key-value pairs and it will build corresponding PropertyInfo structs in the C++ engine to be appended to the property list for the class. This enables users to procedurally generate properties based on logical processes rather than declaring them statically. The second is the actual Object method to request and get back the full list of properties (again, as an Array of Dictionaries). With it, you can get a list of all properties defined by an Object instance. This will include all PropertyInfo Dictionaries from the inherited classes, the underlying Object, AND the Script + its
These methods have to do with the way Objects in Godot track and define their reflection data. The engine defines A PropertyInfo contains
|
Beta Was this translation helpful? Give feedback.
-
I have a passing familiarity with Python syntax, so seeing dunders in code isn't too shocking, personally. But I imagine someone trying to learn GDScript as a first language from the docs would be wondering why The GDScript style guide explains the use of underscores, but it's hard to find if you don't know what you're looking for: Prepend a single underscore (_) to virtual methods functions the user must override, private functions, and private variables:
Learning first time scripting from the docs is sketchy. Good documentation should be terse and accurate, if not a bit dry. You're much better off using books + videos + forums that are more hand-holdy. GDScript is getting a refactor. Maybe it'll open up some possibilities. |
Beta Was this translation helpful? Give feedback.
-
@frogonics Yes, with the GDScript rewrite, we are getting preliminary annotation support. With that, it will likely be possible to add a |
Beta Was this translation helpful? Give feedback.
-
Writing this quick idea down so that I can write a more detailed proposal later.
Context
Using properties in scripts from different object types.
Problem
Users can often times directly see and access "private" properties and data in other types.
Suggestion
Filter properties with
PROPERTY_USAGE_SCRIPT_VARIABLE
and a leading underscore in their name OUT of theget_property_list()
method's results. This will prevent autocompletion from functioning properly. Need to figure out how to make the basic idea work in more contexts though, e.g. the Inspector may still want to expose a property with a leading underscore and we need to make that painless.Solution
Not sure yet.
Beta Was this translation helpful? Give feedback.
All reactions