darve
January 14, 2024, 1:44pm
1
Hello everyone,
I’m making a weapon system and trying to make it modular but when I wrote one of the functions and called from a normal script to a super class the super class function suddenly returns “null” on it’s variables
Here is the code:
The script:
extends Sword_Base
var Sword
func _ready():
Sword = Sword_Base.new()
Sword.Test()
func _physics_process(delta):
Sword.Rotate_Weapon(self)
The super class:
extends Weapon_Base
class_name Sword_Base
The super super class:
extends Node2D
class_name Weapon_Base
@onready var Root = get_node("/root/World_Root")
func Rotate_Weapon(Weapon):
print(Root)
Weapon.look_at(get_global_mouse_position())
Tldr: the “Root” variable on the super super class returns nill even though I already defined it in a previous line
usually it’s class_name then extends, iirc
about this:
the world_root is a node in main world scene?
darve
January 14, 2024, 2:08pm
3
I believe this is optional but not sure honestly
Yes and it prints correctly if I run the super super script on it’s own
so the error is at
func _physics_process(delta):
Sword.Rotate_Weapon(self)
?
darve
January 14, 2024, 2:20pm
5
No it’s on this line:
The error in question:
Invalid call. Nonexistent function '.get_global_mouse_position' in base 'Nil'
ok, so you dont need to send “self” as parameter there, just look_at will do
darve
January 14, 2024, 2:28pm
7
Edited it as you suggested and now this error appears:
Rotate_Weapon(): Paramter "get_viewport()" is null
weapon_base.gd
class_name WeaponBase
extends Node2D
func Rotate_Weapon():
look_at(get_global_mouse_position())
rotation+=PI/2
the intermeditate
class_name SwordBase
extends WeaponBase
func Rotate_Weapon():
super.Rotate_Weapon()
the a_sword.gd :
extends SwordBase
var Sword
func _ready():
pass
func _physics_process(delta):
super.Rotate_Weapon()
darve
January 14, 2024, 2:45pm
9
oh there was a keyword for super lol I didn’t really know that , Thanks it works now
1 Like
system
Closed
February 13, 2024, 2:46pm
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.