How to write a subclass in the same script as the base class?

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

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.