How to call child function on parent?

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

I am trying to reorganize my code using inheritance and I can’t seem to call the child function.
My project has a class Weapon with basic information about mundane weapons and each weapon has a separete scene that extends from Weapon, so when the Player fires, the Weapon class should call the child.function() but “Attempt to call function ‘shoot’ in base ‘null instance’ on a null instance.” appears. Anyway, here is some of the code:

extends Spatial
class_name Weapon
var current_weapon = 1

onready var ruffian_revolver_s = get_tree().get_root().find_node("Ruffian_Revolver_S")
onready var hunting_shotgun_s = get_tree().get_root().find_node("Hunting_Shotgun_S")

func _ready():
func _process(_delta):
if Input.is_action_just_pressed("primary_fire"):
	if current_weapon == 1:
            elif current_weapon == 2:

My custom gun scene code:

extends Weapon
class_name Ruffian_Revolver_S
func _ready():
weapon_name = "Ruffian_Revolver"
weapon_type = "Revolver"
recoil = 0.2
weapon_damage = 50
fire_rate = 0.32
clip_size = 6
reload_rate = 3
current_ammo = clip_size

func _physics_process(delta):
func shoot():
if current_ammo > 0 and not reloading:"Ruffian_Revolver_Shoot")
	can_fire = false
	current_ammo -= 1
	can_fire = true
elif not reloading:

Attempt to call function ‘shoot’ in base ‘null instance’ on a null instance.

This means that whatever variable should be pointing to the Weapon, is pointing to nothing. The error lies in the code that’s creating the Weapon.

exuin | 2022-03-09 03:45