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

Disallow script that inherit from a type be assigned to something else #615

Open
Shadowblitz16 opened this issue Mar 21, 2020 · 9 comments

Comments

@Shadowblitz16
Copy link

Describe the project you are working on:
spaceship project

Describe the problem or limitation you are having in your project:
I can't remeber what type a script is without opening and looking at what it inherits
I keep getting crashes due to accidentally accessing something that doesn't exist

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
basically nodes would only accept a script that inherit from them or a child node.
this would solve some crashes and would overall improve workflow

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
for example this could be assigned to a TextureRect but not a Node...

extends TextureRect

however this could be assigned to a TextureRect and a Node...

extends Node

If this enhancement will not be used often, can it be worked around with a few lines of script?:
this would be used whenever assigning scripts to nodes so very often and I don't know if this can be worked around using a script

Is there a reason why this should be core and not an add-on in the asset library?:
this should be added because who would want to assign a script to something it doesn't derive from?.

@Shadowblitz16
Copy link
Author

this would be made obsolete by this

@Zireael07
Copy link

Your proposal is much faster to implement, though.

@Shadowblitz16
Copy link
Author

@Zireael07 this one would be faster and easier to implement but the one I linked uses script OPP for custom nodes there since nodes and scenes would basically be script

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented May 8, 2020

I'm reopening this due to the unlikely hood of the script and node combination being added.
it would also be nice to have in 4.0 until then.

@DriNeo
Copy link

DriNeo commented Apr 16, 2021

It might be cool to simply remove the first "extends" statement and get a dynamic inheritance based on the attached node.

@YuriSizov
Copy link
Contributor

@DriNeo Scripts can be attached to multiple nodes of different types, so it would make any type assumptions impossible. Also, no extends statement already has a special meaning: it automatically extends Reference.

@DriNeo
Copy link

DriNeo commented Apr 16, 2021

Attaching a script to a node would be exactly like adding the "extends" statement on top. Errors can be raised as usual.

@YuriSizov
Copy link
Contributor

YuriSizov commented Apr 16, 2021

@DriNeo What I'm saying is that the same script can be attached to any number of nodes, including nodes of different types. Therefore making any assumptions about scripts base type would be impossible inside of the script itself. Scripts don't know to which nodes they are attached.

And like I've said, having no extends specified at the top automatically extends Reference, so what you propose conflicts with existing behavior unrelated to nodes.

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Apr 16, 2021

@DriNeo also specifying what a script extends allows static typing.
so you can make sure your script has the functionality it needs to run.

Although now that I think of it we could also use something like @requires(nodepath) for even more script safety

#2618

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

6 participants