17.6 C
New York
Monday, April 28, 2025

godot – Error calling operate from script utilizing class_name


I am making a desktop mockup for a sandbox recreation. I’ve a script, by which I outlined a ObjContainer class that expands the Management class (the Container class has some behaviors that I do not need). I hooked up stated script to the “ObjContainer” node. After I test it within the Native tab of the scene tree, it reveals that the node “ObjContainer” is of kind ObjContainer as deliberate, as proven in picture 1. After I ran the scene, I observed that the “ObjContainer” has now out of the blue change into a Management node, proven in picture 2.*

*Edit: All nodes with customized class appear to have this conduct. The distant tree at all times reveals the native node varieties I lengthen from. The true downside is that this:

Vocation ObjContainer-Unique capabilities reveals an error that claims:

Invalid name. Non-existent operate ‘request_select’ in base ‘Management (ObjContainer)’.

"containerobject" node with type Control

Why does he do this? Every customized class unique name labored completely superb beforehand. I even commented on the request_select() line and labored with out issues. What’s fallacious with me ObjContainer?

The next is the node script that calls the operate:

class_name FileObject
extends MarginContainer


@onready var texture_rect:TextureRect = $VBoxContainer/Icon
@onready var label:Label = $VBoxContainer/Title
@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:
    go


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/elements/window/xethos_window.tscn").instantiate()
    
    w.init
    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().measurement - intended_size)

And the ObjContainer class script:

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