11.6 C
New York
Friday, March 14, 2025

godot – Error when calling perform from script utilizing class_name


I am making a mockup desktop for a sandbox recreation. I’ve a script, through which I outlined a ObjContainer class that extends the Management class (the Container class has some behaviours that I do not need). I hooked up mentioned script to the node “ObjContainer”. After I test it within the Native tab of the Scene Tree, it reveals that the “ObjContainer” node is of sort ObjContainer as supposed, proven in image 1. After I ran the scene, I seen that the “ObjContainer” has now abruptly changed into a Management node, proven in image 2.*

* Edit: All nodes with {custom} class appear to have this behaviour. The distant tree all the time present native node varieties that I lengthen from. The true challenge is as follows:

Calling ObjContainer-exclusive capabilities brings up an error that claims:

Invalid name. Nonexistent perform ‘request_select’ in base ‘Management (ObjContainer)’.

"ObjContainer" node with the type Control

Why does it try this? Each single custom-class-exclusive name labored completely nice beforehand. I even commented out the request_select() line and it ran easily. What’s up with my ObjContainer?

The next is the script from the node calling the perform:

class_name FileObject
extends MarginContainer


@onready var texture_rect:TextureRect = $VBoxContainer/Icon
@onready var label:Label = $VBoxContainer/Identify
@onready var obj_container:ObjContainer = ObjContainer.new()
@onready var desktop = $/root/Desktop

@export var file_icon:Texture2D = preload("res://xeth_os/icons/assortment.png")
@export var file_name:String = "" 
@export var target_scene:PackedScene = null

var intended_size:Vector2 = Vector2(74, 126)

# Customized constructor.
func init(i:Texture2D, n:String, t:PackedScene) -> void:
    file_icon = i
    file_name = n
    target_scene = t


# Referred to as when the node enters the scene tree for the primary time.
func _ready() -> void:
    texture_rect.texture = file_icon
    label.textual content = file_name
    if get_parent() is ObjContainer:
        obj_container = get_parent()


# Referred to as each body. 'delta' is the elapsed time for the reason that earlier body.
func _process(delta: float) -> void:
    cross


func choose() -> void:
    modulate = Colour.BLUE
    label.text_overrun_behavior = TextServer.OVERRUN_NO_TRIMMING

func unselect() -> void:
    modulate = Colour.WHITE
    label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS


func open_file() -> void:
    var t:PackedScene = target_scene
    var w:XeWindow = preload("res://xeth_os/parts/window/xethos_window.tscn").instantiate()
    
    w.init(t)
    desktop.add_child(w)


func _on_gui_input(occasion: InputEvent) -> void:
    if occasion is InputEventMouseButton:
        if occasion.pressed:
            obj_container.request_select(self)
            
        if occasion.button_mask == 1 and occasion.double_click:
            open_file()
    
    if occasion is InputEventMouseMotion :
        if occasion.button_mask == 1: #left mouse buton is pressed
            global_position += occasion.relative
            global_position = global_position.clamp(desktop.top_bar_offset, get_viewport_rect().dimension - intended_size)

And the script from the ObjContainer class:

class_name ObjContainer
extends Management


func request_selection(f:FileObject) -> void:
    var l:Array[FileObject] = get_file_objects()
    l.erase(f)
    for i in l:
        i.unselect()
    f.choose()


func get_file_objects() -> Array[FileObject]:
    var c:Array[Node] = get_children()
    var f:Array[FileObject] = []
    for i in c:
        if i is FileObject:
            f.push_front(i as FileObject)
    return f


func _on_gui_input(occasion: InputEvent) -> void:
    if occasion is InputEventMouseButton:
        for i in get_file_objects():
            i.unselect()

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles