Parser Error: Could not resolve class "class_name".

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

Hello. I have this Inventory System from Godot 3.x that I’m trying to convert to Godot 4.0, but I’m having some problems here and there. Most have been somewhat easy to figure out how to fix, but I’m quite stuck on this problem.

This is the file which receives the error “Parser Error: Could not resolve class “Inventory_Slot_Node”.”:

class_name Hotbar_Slot_Node extends Inventory_Slot_Node

@onready var lbl_key : Label = $lbl_key

func set_slot( value ):
	super.set_slot( value )

# If you press this slot's key, activate the item if possible.
func _input( event ):
	if event.is_action_pressed( "hotbar_" + slot.key ) and slot.item and slot.item.components.has( "usable" ):
		print( "Used hotbar slot: ", slot.key )

# Set the key to be pressed to activate this slot.
func set_key():
	if lbl_key is Label:
		lbl_key.text = slot.key

This is the Inventory_Slot_Node gdscript:

class_name Inventory_Slot_Node extends TextureRect

@onready var item_container : CenterContainer = $item_container

var slot : set = set_slot

# When the slot resource is set, draw it and connect the signals.
func set_slot( value ):
	slot = value
	if slot and slot.item:
		var item_node = ResourceManager.get_item_node( slot.item )
		item_container.add_child( item_node )
	if not is_connected("mouse_entered",Callable(InventoryManager,"_on_mouse_entered_slot")):
		connect("mouse_entered",Callable(InventoryManager,"_on_mouse_entered_slot").bind( self ))
		connect("gui_input",Callable(InventoryManager,"_on_gui_input_slot").bind( self ))

# When the slot is shown or hidden, cause a mouse exited signal so the item info hides.
func _on_item_container_visibility_changed():
	emit_signal( "mouse_exited" )

# When the item change, update the visual.
func _on_item_changed():
	for c in item_container.get_children():
	if slot.item:
		item_container.add_child( ResourceManager.get_item_node( slot.item ) )

Please feel free to throw in more questions or try to give an answer to how I might fix this problem!


:bust_in_silhouette: Reply From: zhyrin

Copying your code and commenting out sections of Inventory_Slot_Node that yielded unresolved symbols worked fine for me, the derived class doesn’t give the parse error.

This might be a moot question, but did you try reloading the project?
Also, are there any errors in the base class? If it can’t be parsed, your derived class might not be able to inherit from it.
For me, the lines where you reference ResourceManager and InventoryManager gave errors, but I guess those are globals.

I figured the first thing I should try was reloading the project… Man, the amount of time I’ve spent trying to fix a problem that doesn’t exist, hahahhhsh.

What did you comment out?

KSHolmes | 2023-02-09 18:56

All the lines referencing ResourceManager and InventoryManager, these are of course not defined in my project.

zhyrin | 2023-02-09 20:44