godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.17k stars 98 forks source link

Auto-complete the exported variable function for other scenes/scripts #9810

Open mddm1 opened 6 months ago

mddm1 commented 6 months ago

Describe the project you are working on

normal 3d game

Describe the problem or limitation you are having in your project

i want to simply call a function from an exported variable that exists in the game but when I use the variable, the function does not autocomplete.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

some sort of search algorithm that takes the variable that already has the scene i want to call the function from and provide the intel needed.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

i have a main scene that has a script attached and inside I export a variable, a node3d for example. this node3d is another scene that has a script that has a function "revived" for example. when i call the variable and write the dot "variable." i want godot to show me all the functions i can call - in this case the function "revived" => variable.revived()

If this enhancement will not be used often, can it be worked around with a few lines of script?

no script. you just have to remember what name the function has in order to correctly call it. if you have multiple scripts from multiple scenes you go back and forth to do check work

Is there a reason why this should be core and not an add-on in the asset library?

i don't know

AThousandShips commented 6 months ago

What feature are you suggesting? This all sounds something you can do in scripting

mddm1 commented 6 months ago

there are at least 2 scripts and I have to go back and forth to see if the function I want to use in one matches the one that exists in the other. godot does not suggest the function I want to call from the other script.

AThousandShips commented 6 months ago

Are you suggesting a feature or asking for support or ideas? You can just call another node or without anything extra, and the suggestion requires you to add type hints first or it won't show up

KoBeWi commented 6 months ago

That sounds more like a bug report.

AThousandShips commented 6 months ago

So to clarify:

mddm1 commented 6 months ago

I am suggesting a feature. Yes. not using get_node.

I'm really bad with explanations so I made an image. vvv

mddm1 commented 6 months ago

basically I want godot to parse the script from scene 2 that is already loaded in the scene1 script so that I can use the intel from it as a autocomplete.

AThousandShips commented 6 months ago

You need to static type it with the class of the other node, it won't get anything else otherwise, it's just a Node3D

But please explain what the feature is, what is it you want to happen

Because if you want to have auto compete you just need to use the right type, not Node3D but your class

theraot commented 6 months ago

Currently, in your scene2 variable, you can set any Node3D, including any Node3D that does not have the scene2.gd script and does not have a function_inside_scene2 available. And I remeind you that you can change to what that scene2 variable points to at any moment, which might leave your code not working.

Instead give a custom class_name to the scene2.gd script (or preload the scene2.gd into a const in scene_1.gd), and define your scene2 variable to be of that class. Then, it will only be possible to set the scene2 variable to an instance of scene2.gd which has function_inside_scene2. And autocomplete should work (if it doe snot, you have a bug to report).

You might also want to check if the variable has a valid refrence with is_instance_valid.


The feature you seem to be asking for would be to have autocompletion - based on the current way configured values of the variables in the inspector - without the guarantee of the variable refering to an object that would have the members you are getting autocompleted.

At least personally, I don't like the idea.

KoBeWi commented 6 months ago

I think it would work similar to $ autocompletion. The editor is able to determine the target node type based on path. Here it would take it from an exported Node variable, which doesn't sound unreasonable.

mddm1 commented 6 months ago

basically I want godot to parse the script from scene 2 that is already loaded in the scene1 script so that I can use the intel from it as a autocomplete.

Currently, in your scene2 variable, you can set any Node3D, including any Node3D that does not have the scene2.gd script and does not have a function_inside_scene2 available. And I remeind you that you can change to what that scene2 variable points to at any moment, which might leave your code not working.

Instead give a custom class_name to the scene2.gd script (or preload the scene2.gd into a const in scene_1.gd), and define your scene2 variable to be of that class. Then, it will only be possible to set the scene2 variable to an instance of scene2.gd which has function_inside_scene2. And autocomplete should work (if it doe snot, you have a bug to report).

_You might also want to check if the variable has a valid refrence with is_instance_valid._

The feature you seem to be asking for would be to have autocompletion - based on the current way configured values of the variables in the inspector - without the guarantee of the variable refering to an object that would have the members you are getting autocompleted.

At least personally, I don't like the idea.

I know about the making of a class_name but this would, in this case, be a workaround. This would be just a quality of life feature, I know that some scene would not even have a script to parse or the script might not have functions and so on. In this case Godot would not do anything. It would be nice for the engine to show what options are there, especially when one can have many scripts and forgets which one has the desired function.

Zireael07 commented 6 months ago

Issue name completely unrelated to content IMO - it should be "autocomplete across files" or something similar

AThousandShips commented 6 months ago

I know about the making of a class_name but this would, in this case, be a workaround

I don't think it's a workaround to use the relevant feature for this, I think autocomplete for nodes in the current scene is fragile as it is, adding more to it with fetching data from other scenes not currently open would make it even harder to keep working well, static typing is there to solve these issues

huwpascoe commented 6 months ago

This feature could be summarised as "include currently open script files as an autocompletion source".

Calinou commented 6 months ago

This feature could be summarised as "include currently open script files as an autocompletion source".

This is already the case – it's based on the currently open scene in the 2D/3D editor. This is why you can still see the list of scene tabs while on the script editor, as the currently selected tab is used to infer type information from the scene's nodes.