Godot Version
4.4.1.stable
Question
I’m getting an error saying Script inherits from native type ‘Area2D’, so it can’t be assigned to an object of type: ‘Node2D’, but it is an Area2D. I even deleted it and retried from scratch. Here’s the full script if that helps:
extends Area2D
@onready var confirmation_dialog: ConfirmationDialog = $ConfirmationDialog
var player_inside: bool = false
func _ready():
# Connect signals
body_entered.connect(_on_body_entered)
body_exited.connect(_on_body_exited)
confirmation_dialog.confirmed.connect(_on_save_confirmed)
confirmation_dialog.canceled.connect(_on_save_canceled)
# Configure dialog
confirmation_dialog.dialog_text = “Would you like to save your game?”
confirmation_dialog.get_ok_button().text = “Save”
confirmation_dialog.get_cancel_button().text = “Cancel”
confirmation_dialog.hide()
func _input(event):
# Check for “Action” key (E) when player is inside
if player_inside and event.is_action_pressed(“equip”):
confirmation_dialog.popup_centered()
func _on_body_entered(body: Node):
# Check if the body is the player
if body.is_in_group(“Player”):
player_inside = true
set_process_input(true) # Enable input processing
func _on_body_exited(body: Node):
# Disable input when player leaves
if body.is_in_group(“Player”):
player_inside = false
set_process_input(false)
confirmation_dialog.hide()
func _on_save_confirmed():
# Save game data when confirmed
var player = get_tree().get_first_node_in_group(“Player”)
if player:
GameManager.game_data[“player_position”] = player.position
GameManager.game_data[“health”] = player.health # Adjust if different
GameManager.game_data[“score”] = player.score # Adjust if different
GameManager.save_game()
print(“Saved at save point!”)
confirmation_dialog.hide()
func _on_save_canceled():
# Hide dialog on cancel
confirmation_dialog.hide()
