I have a custom class that represents a Player in a game world, with attributes and methods. This is initalized in through a load() call in a Class configured to function as an AutoLoad, so that character attributes set in one Scene persist to the multiple game world scenes.
What ends up happening is, the call to set the Player Name (a method extended from Player2) errors out, and the script fails. The error message is "Invalid call. Nonexistent function 'SetPlayerName' in base 'GDScript'."
Due to the incredibly poor introspection in regards to class and methods, I don't know if GDScript has loaded in the necessary methods, or if I'm missing something here in the Player2.gd class that I need to account for, when running a method in a non-Autoloaded class. This is really confusing me, especially since Godot has very poor debugging tools in regards to exploring what methods are in memory.
In essence, how I can get the method call Player.SetPlayerName(Name)
to work?
Below is the code for the PlayerInstance class which is run once the player has approved their attribute changes on a scene (not included).
# PlayerInstance.gd
# Singleton to track the player character (YOU) in the game world
extends KinematicBody
# Inherited Classes
var Player = load("res://scripts/Player2.gd");
# Fields
var PlayerObj
# Constants
const MAX_SLOPE_ANGLE = 45
# Event Methods
func _ready():
# Called every time the node is added to the scene.
# Initialization here
PlayerObj = Player.new()
# Methods
func InitNewPlayer(Name, Const, Str, Int, Per, Prov):
"""
TODO
"""
Player.SetPlayerName(Name)
Player.SetPrimaryStats(Const, Str, Int, Per, Prov)
# PlayerObj.SetPlayerName(Name)
# PlayerObj.SetPrimaryStats(Const, Str, Int, Per, Prov)
The Player2 class can be viewed on Pastebin here. It's literally too big for this field.