Script inherits bug

Godot Version

4.2.2

Question

it keeps saying: script inherits from native type ‘control’ so it can t be assigned to an object of type ‘node2d’

what can i do?

my code:

extends Control

@onready var name_input = $NameInput
@onready var class_option = $ClassOption
@onready var attribute_slider = $AttributeSlider
@onready var attribute_label = $AttributeLabel
@onready var character_preview = $CharacterPreview

var character = {
“name”: “”,
“character_class”: “”,
“strength”: 10,
“dexterity”: 10,
“intelligence”: 10
}

var current_attribute = “strength”

func _ready():
print(“Skript wird geladen”)
print(“Node-Struktur:”, get_children())

if name_input:
	print("NameInput gefunden")
	name_input.text_changed.connect(_on_name_changed)
else:
	print("NameInput nicht gefunden!")

if class_option:
	print("ClassOption gefunden")
	class_option.item_selected.connect(_on_class_selected)
else:
	print("ClassOption nicht gefunden!")

if attribute_slider:
	print("AttributeSlider gefunden")
	attribute_slider.value_changed.connect(_on_attribute_changed)
else:
	print("AttributeSlider nicht gefunden!")

func _on_name_changed(new_name):
character.name = new_name
update_preview()

func _on_class_selected(index):
character.character_class = class_option.get_item_text(index)
update_preview()

func _on_attribute_changed(value):
character[current_attribute] = value
update_preview()

func update_preview():
var preview_text = “”"
Name: {name}
Klasse: {character_class}
Stärke: {strength}
Geschicklichkeit: {dexterity}
Intelligenz: {intelligence}
“”".format(character)
character_preview.text = preview_text

Is this script attached to a node2d?

i dont think so. im new to gdscript. how do i find out if a node2d script is attached?

change type?

you have a scene called “node2d”. Check if this one has the script attached to it

i deleted it and attached to the script. now it works. thanks :slight_smile:

1 Like