Extending script files

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

I’m using a script to extend the capabilities of the “AnimatedSprite” node so I can do things like choose special durations to specific frames, or signal when a certain frame of a certain animation is reached. I’ll refer to the scripts that defines those methods and signals “Sprite.gd”. I also would like to implement in a script attached to the AnimatedSprite node the animations for each individual sprite (player, enemy1, enemy2, etc.), using the methods defined in Sprite.gd.

How can I make so that some AnimatedSprite nodes inherit the methods from my Sprite.gd, while still having a specific script attached to them (e.g.: PlayerAnimation.gd, EnemyAnimation.gd, etc.)? Can I “extends Sprite.gd” or something like that? Or maybe define a new custom node that extends AnimatedSprite and adds my custom methods, and then extend my custom node on the individual sprites?

Thank you :slight_smile:

:bust_in_silhouette: Reply From: Ruckus T-Boom

Sure, you just extend by the path

// PlayerAnimation.gd
extends "res://path/to/Sprite.gd"

func _ready():
    pass

KidsCanCode did a tutorial on inheritance in Godot 3.0 earlier this year.