`func _process(delta):
if has_overlapping_bodies() and Input.is_action_just_pressed(“Left”):
var body = get_overlapping_bodies().find(Number)
var ToDestroy = node.get_child(body)
while not ToDestroy.is_in_group(“Left”):
Number += 1
ToDestroy = node.get_child(body)
ToDestroy.queue_free()
bf_act_1.animation = “Left”
Question
So Im trying to get my code to destroy an object and it is checking to make sure it is in the right group(THIS IS NECCESSARY) and it keeps breaking at the while loop that is readjusting it to the right place the and the Number Variable is in the code but idk why it is Breaking SOMEONE PLS HELP
It didnt work it gave me an error Invalid type in function ‘get_child’ in base Node(main.gd). Cannot convert arguement 1 from to int
The whole script:
extends Area2D @onready var bf_act_1 = $“…/…/BF Act 1” @onready var node = $“…/…”
var Number = 0
Called when the node enters the scene tree for the first time.
func _ready():
pass
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _process(delta):
if has_overlapping_bodies() and Input.is_action_just_pressed(“Left”):
var body = get_overlapping_bodies()[Number]
var ToDestroy = node.get_child(body)
while not ToDestroy.is_in_group(“Left”):
Number += 1
ToDestroy = node.get_child(body)
ToDestroy.queue_free()
bf_act_1.animation = “Left”
I’ll give you a tip hold Ctrl key and click on the functions you are using. It will take you to the documentation of the functions.
When you use find(Number) it looks for a number in the array. But this array doesn’t have numbers it is an Array[Node2D]. Find I’ll not throw an error but will return -1. Get_child will accept a negative number. But it will give you a node at the end of the child list.
But again you don’t need to use get_child because you already have the node in the get_overlapping_bodies(), as it returns an array[node2d]