Godot Version
4.8.dev5
Question
I’m trying to have the code cycle through mobs that enter the range of the orb. The range of the orb is shown in the screenshot below:
However, I keep getting an error. The nodes are arraigned in the screenshot below:
The code of Line2D is below:
extends Line2D
var firing_status: bool = false
var shot_duration: float = 0.05var shot_delay: float = 0.3
@onreadyonready var shot_sound: AudioStreamPlayer = $“../../../Shot_@onreadyound”
@onready var balance: Label = $“../../../Main_CanvasLayer/VBoxContainer/HBoxContainer/Balance”func _process(_delta: float):
#Updates the balance in the label
balance.text = str(Globals.balance)
for mobs in Globals.mobs_in_range:
shooting_mob()func _on_orb_area_shape_entered(_area_rid: RID, area: Area2D, _area_shape_index: int, _local_shape_index: int):
Globals.mobs_in_range.append(area) #<-----I’m not sure what the correct variable here is.func shooting_mob():
add_point(Vector2(0,0))
add_point(to_local(Globals.mobs_in_range[0].position))
#add_point(to_local(Globals.mobs_array[0].position))
await get_tree().create_timer(shot_duration).timeout
clear_points()
await get_tree().create_timer(shot_delay).timeout
Globals.shoot_counter -= 1
print(str(Globals.shoot_counter) + " shots left")
Globals.mobs_in_range[0].when_attacked() #<------Nonexistent function ‘when_attacked’ in base ‘Area2D’. error happens here
Globals.mobs_in_range.erase(Globals.mobs_in_range[0])
shot_sound.play()
The screenshot below are the nodes of the mob scene:
Code of the mob scene below:
extends @onreadyaracterBody2D
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
var SPEED: int
const DIRECTION = -1
var hit_points: int = 1func _ready():
$AnimatedSprite2D.play()
SPEED = Globals.mob_speedfunc _physics_process(_delta: float):
velocity.x = SPEED * DIRECTION
if velocity.length() > 0:
$AnimatedSprite2D.play(“run”)
move_and_slide()func _on_area_2d_body_entered(_body: Node2D):
SPEED = 0
attacking_mode()func attacking_mode():
while Globals.wizard_tower_health > 0:
$AnimatedSprite2D.play(“attack”)
await $AnimatedSprite2D.animation_finished
Globals.attacked_signal.emit()func when_attacked():
hit_points -= 1
if hit_points < 1:
SPEED = 0
$AnimatedSprite2D.play(“death”)
Globals.balance += 1
await $AnimatedSprite2D.animation_finished
call_deferred(“queue_free”)


