+1 vote

I'll try to explain what I mean as best I can:
I have a preloaded script (from Project Settings) that contains all my global classes.
THAT works--the base classes, I can make new objects in any script anywhere on a snap.
But how do I create subclasses inside that same script?
So for example I have this:

class Actor:
variables
functions()

And I want to do something like this (like in C# or something)

class Actor:
variables
functions()

class Battler : Actor
variables
functions()

It doesn't seem to work. Because when I go construct a 'Battler' object, and I define a variable which should be an inherited property of the Actor class, I get 'invalid index error' or something.

So is there a way to write subclasses in the same script, OR
Do I have to write every subclass on their own script, attach each script to their own node, and then have all nodes under the base node (which has the base classes script attached)?

The second way seems extremely convoluted which I find drives me absolutely insane (especially if I have to mess around with sending signals and crap), or maybe I'm just doing it wrong.

in Engine by (13 points)

Please log in or register to answer this question.

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.