Godot Version
godot 4
Question
i need help trying to fix this error code i keep getting Invalid assignment of property or key ‘damage’ with value of type ‘int’ on a base object of type ‘Nil’.
i don’t understand why i get this error code am trying to make hitbox for my combat system.
here is the player code:
extends CharacterBody2D
@export var speed: float = 100
@onready var animation = $PlayerAnimation
@onready var weapon = $WeaponFX
@onready var hitbox : $Hitbox
@export var current_item : Item:
set(value):
current_item = value
if current_item != null:
if current_item.animation in ["blade"]:
set_damage(current_item.damage)
else:
set_damage(1)
func _ready():
get_node(“HitBox”)
pass
var lastAnimDirection : String = “down”
var time : float = 0
var can_move : bool = true:
set(value):
can_move = value
if value == false:
speed = 0
else:
speed = 100
func handleInput():
var moveDirection = Input.get_vector(“left”, “right”, “up”, “down”)
velocity = moveDirection*speed
if Input.is_action_just_pressed("attack") and time <= 0:
Attack()
func Attack():
can_move = false
time = 0.6
if current_item == null:
animation.play(“fist” + lastAnimDirection)
else:
$Weapon.visible = true
$Weapon.texture = current_item.texture
weapon.play(current_item.animation + lastAnimDirection)
animation.play(current_item.weapon_animation + lastAnimDirection)
func updateAnimation():
if can_move:
if velocity.length() == 0:
animation.play(“idle” + lastAnimDirection)
else:
var direction = “down”
if velocity.x < 0: direction = “left”
elif velocity.x > 0: direction = “right”
elif velocity.y < 0: direction = “up”
animation.play("walk" + direction)
lastAnimDirection = direction
func _physics_process(delta):
if time > 0:
time -= delta
handleInput()
move_and_slide()
updateAnimation()
func set_damage(amount):
hitbox.damage = amount
func _on_player_animation_animation_finished(anim_name: StringName) → void:
can_move = true
here is my hitbox code:
extends Area2D
@export var damage : float = 1
func _on_body_entered(body: Node2D) → void:
if body.has_method(“take_damage”):
body.take_damage(damage)
any help would be appreciated.