-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Added Node name to print() of all Nodes by making to_string() in Object virtual, so it can be overriden in C++. #38819
Added Node name to print() of all Nodes by making to_string() in Object virtual, so it can be overriden in C++. #38819
Conversation
01a3df1
to
f746455
Compare
IMO all string log about the object must be inside the brackets |
I like that idea. I'll make the change when I get up in about 9 hours 😁 |
All languages that I know of that have this feature let the programmer completely override the output. I.e. if I only want it to print If we do this, we should IMO allow that freedom, and not do this halfway and constrain the output. Java works that way, C# works that way etc. Forcing the overriden output to be surrounded by the current output makes this unnecessarily less flexible and useful, IMO. |
@mhilbrunner That's how it works already AFAIK. If you have a script instance, it will return the result from its See |
Yes, I was talking about the other comments :) but maybe I misunderstood them. |
Well the discussion is about what the default representation of a Node should be:
|
Then I indeed misunderstood. :) I don't personally care much, both are fine as default for me. |
Hmm on second thought this morning, I think I will leave it at Additionally, doing it this way would not allow me to just use the |
I got surprised that I'm currently implementing some data structures in a C++ module which I'd like to expose to scripting, having this feature built-in would solve a lot of hacks. See goostengine/goost#14 and goostengine/goost#12 to justify this change. |
This probably needs rebase after #42093 was merged. I'm not sure about the string format. When you print a node as a part of longer string separated by spaces, it's less obvious that |
f746455
to
4d3075a
Compare
print(self)
# CoolNode:[SpinBox:28454159399] |
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.
There's a comment to amend but otherwise it seems good to me.
4d3075a
to
3ca25ff
Compare
Is the |
Node must have a name when in the Scene Tree, but outside it they can be unnamed: var node = Node.new()
print(node.name)
add_child(node)
print(node.name) Prints:
|
Thanks! |
Cherry-picked for 3.4. |
For the sake of compatibility, this should be made optional. Also, to reduce amount of printed text when necessary. |
Closes godotengine/godot-proposals#693
Outputs
I did not add position to Node2D/3D/Control as I wasn't sure if it was really need. Some people won't need it, and there is the question of whether to return local/global position (or other info).