Can an extended script use its extensions' variables?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By John97

I have a script with many other scripts being an extension of it. The parent script has a function that requires a variable which all of the child scripts should have, but at different values. Another, separate script receives the packed scene which contains one of those child script, makes an instance of that packed scene, and calls this function from the parent script. I want the function to use the variable that is in the extension(child). How can I do that?

Sorry, when you say “parent” do you mean parent node in the node hierarchy or the superclass?

exuin | 2021-04-15 20:03

No, I mean the script that is being extended. Parent is probably not the appropriate word, but I don’t know a better one for this.

John97 | 2021-04-15 21:12

Use “superclass”

exuin | 2021-04-15 21:45

I’ve kind of solved the problem with singletons. Would using superclass be preferable to that?

John97 | 2021-04-15 21:49

It really depends on what the specific problem is.

exuin | 2021-04-15 21:49

:bust_in_silhouette: Reply From: exuin

The subclass (extending script) should be able to use all methods of the superclass. So it should use the value of itself and not the superclass’ value by default.