Class Extensions continuing innate functions that exist in the base class

Godot Version

4.1.1

Question

I’ve got a class called “Material” and a couple other scripts that each extend the “Material” class.

Material class script:

extends Control

class_name Mat

signal playSound(sound:String)
var stats = {}

func _drop_data(_pos, data):
  stats = data
  #Do a bunch of other that all variations of the class will do

and then there are a variety of unique scripts that extend these nodes

extends Mat

func _drop_data(_pos, data):
  emit_signal("playSound","uncommonMaterialSound")
  #Do a bunch of stuff unique to this version

This does not work as when “_drop_data” is called, it will only execute what is written in the extended script.

I’m trying to make it so that each class extension can play a unique sound when the “_drop_data” function is called. What would the best approach to this be?

Is there a way for a class extension to have a function that continues an innate function from the base class?

Note: The base class does not exist on any nodes in the Scene tree. Only the class extensions exist on the scene tree

Did you try using super()?

extends Mat

func _drop_data(_pos, data):
  super(_pos, data)
  emit_signal("playSound","uncommonMaterialSound")
  #Do a bunch of stuff unique to this version

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.