-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation note on Object's boolean context #99091
Add documentation note on Object's boolean context #99091
Conversation
@@ -22,6 +22,7 @@ | |||
Lastly, every object can also contain metadata (data about data). [method set_meta] can be useful to store information that the object itself does not depend on. To keep your code clean, making excessive use of metadata is discouraged. | |||
[b]Note:[/b] Unlike references to a [RefCounted], references to an object stored in a variable can become invalid without being set to [code]null[/code]. To check if an object has been deleted, do [i]not[/i] compare it against [code]null[/code]. Instead, use [method @GlobalScope.is_instance_valid]. It's also recommended to inherit from [RefCounted] for classes storing data instead of [Object]. | |||
[b]Note:[/b] The [code]script[/code] is not exposed like most properties. To set or get an object's [Script] in code, use [method set_script] and [method get_script], respectively. | |||
[b]Note:[/b] In a boolean context, an [Object] will evaluate to [code]false[/code] if it is equal to [code]null[/code] or it has been freed. Otherwise, an [Object] will always evaluate to [code]true[/code]. See also [method @GlobalScope.is_instance_valid]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[b]Note:[/b] In a boolean context, an [Object] will evaluate to [code]false[/code] if it is equal to [code]null[/code] or it has been freed. Otherwise, an [Object] will always evaluate to [code]true[/code]. See also [method @GlobalScope.is_instance_valid]. | |
[b]Note:[/b] In a boolean context, an [Object] will evaluate to [code]false[/code] if it is equal to [code]null[/code] or it is an invalid object (e.g. it has been deleted from memory). Otherwise, an [Object] will always evaluate to [code]true[/code]. See also [method @GlobalScope.is_instance_valid]. |
Since there is Object#null
and for symmetry with is_instance_valid()
docs:
godot/doc/classes/@GlobalScope.xml
Line 575 in ec6a1c0
Returns [code]true[/code] if [param instance] is a valid Object (e.g. has not been deleted from memory). |
Also, it's worth adding a note to the is_instance_valid()
docs that since 4.4 this function is mostly optional in GDScript, you get the same result whether you explicitly or implicitly cast an object to bool
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once more there's an ambiguous "e.g." here. Just for clarity, it means less "That would mean" and more "Here's one example of invalid object"? I assume the latter. Either way, I may come up with another way to word it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for clarity, it means less "That would mean" and more "Here's one example of invalid object"? I assume the latter.
Yes, "invalid object" = Object#null
| Freed Object
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, pending @dalexeev's suggestion
EDIT: Actually nah, I'll just merge it now. We can worry about the wording in a followup, but this functionality being specified period takes priority
Thanks! |
Sorry, I got caught up in other things! |
Futuristic awesome version of #93896
Self-explanatory. This note is present in some other Variant types and here it's particularly worth explaining here due of the change in #93885
See:
Freed Object
booleanization #93885