0 votes

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?

in Engine by (44 points)

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

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.

Use "superclass"

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

It really depends on what the specific problem is.

1 Answer

+2 votes

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.

by (8,528 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.