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

Add a tool keyword for functions #729

Open
MarianoGnu opened this issue Apr 18, 2020 · 3 comments
Open

Add a tool keyword for functions #729

MarianoGnu opened this issue Apr 18, 2020 · 3 comments

Comments

@MarianoGnu
Copy link

Describe the project you are working on:
Nothing particular

Describe the problem or limitation you are having in your project:
When tagging an script as tool, every single function inside of it will run in the editor, so if we want to have a single function to work in the Editor we need to put barriers on every other function at the start
if get_tree().is_editor_hint(): return

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
The proposal is to allow to put the tool keyword in front of functions which you want to allow execution during the editor

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

tool func set_texture(p_texture):
    # Only this function runs in editor
    if has_node("icon"):
        $icon.texture = p_texture

If this enhancement will not be used often, can it be worked around with a few lines of script?:
The workaround is make the entire script a tool script and add barriers in functions you don´t want to use, or implement only the editor functions in a separate script and then inherit that script with a no tool script. This is not possible if you already need to extend a different script (as multiple inheritance is forbidden (and for good reasons)

Is there a reason why this should be core and not an add-on in the asset library?:
It requiere changes on core (Script class) and GdScript module

@Error7Studios
Copy link

Additionally, tool_only would be a useful keyword.

tool func foo() would run in the editor and the running scene.

tool_only func bar() would run only in the editor.

@bojidar-bg
Copy link

Consider also the old proposal in godotengine/godot#8735 (comment).

@Calinou Calinou changed the title tool keyword for functions Add a tool keyword for functions Jan 31, 2021
@dalexeev
Copy link
Member

This would be especially useful for the _init() function of scripts inherited from Node.

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

No branches or pull requests

5 participants