Skip to content
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

Printing node should contain its name #693

Closed
KoBeWi opened this issue Apr 10, 2020 · 3 comments · Fixed by godotengine/godot#38819
Closed

Printing node should contain its name #693

KoBeWi opened this issue Apr 10, 2020 · 3 comments · Fixed by godotengine/godot#38819
Milestone

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Apr 10, 2020

Describe the project you are working on:
A game.

Describe the problem or limitation you are having in your project:
Sometimes it happens that I have to print a node to see if a proper node is where I want it. My problem is that print(some_node) doesn't give really useful information. It gives node type and... instance ID. I don't need the ID, I'd like the name. Most often I can't just do print(some_node.name) because some_node can be null too (safe navigation operator would help here actually...).

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Doing print on node should display its type and name, not type and ID.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
We should either make to_string virtual and override it in node or add an if checking if the Object is a node. The latter is quite simple to do actually.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Printing nodes is rather frequent operation IMO.

Is there a reason why this should be core and not an add-on in the asset library?:
It's core thing.

@Calinou
Copy link
Member

Calinou commented Apr 11, 2020

Could we also print a node's position if it extends from Node2D, Node3D or Control? This may give some additional context when debugging. I'm not sure how far we should go about this to ease debugging.

Also, I'd still print the instance ID so you can distinguish unique instanced nodes with the same name. Like this: MyCoolNode [Node3D] (#<instance ID>)

@tengkuizdihar
Copy link

Is there already an implementation for python str in godot?

@Calinou
Copy link
Member

Calinou commented Apr 21, 2020

@balenol Yes, you can override _to_string() in any script since Godot 3.2. (It should return a String.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants