Topic was automatically imported from the old Question2Answer platform.
Asked By
Mostafa Saeed
func _ready():
player = get_tree().get_first_node_in_group("player")
if player != null:
player.global_position = start.get_spawn_pos()
#this is the for loop
var watch = get_tree().get_nodes_in_group("watch")
for watches in watch:
watches.connect("more_time" ,_on_watch_more_time )
var traps = get_tree().get_nodes_in_group("traps")
for trap in traps:
trap.trap_touched.connect(_on_trap_touched)
exit.connect("body_entered" , _on_body_entered)
death_zone.connect("body_entered" ,_on_death_zone_body_entered )
timer_hud()
# the problem is here i cant put remove_at() while having .size() function
#i want to delete the first node of the array
**func _on_watch_more_time():
time_left += time_increase
var watches_kids = watches.get_children().size()
watches_kids.remove_at(0)**
1. List item
This line var watches_kids = watches.get_children().size() assigns an integer to the variable watches_kids. Then you are trying to call the remove_at function of the variable watches_kids (an int). Integers don’t have such a function, hence the error.
According to the documentation, remove_at will remove an element at the given index from an array, so you need to make sure watches_kids is an array for the error to be remove. You may want to careful think about your logic to fix this, since naively making watches_kids an array may not achieve what your goal is. For example, if you want to remove a child node from the watches node, removing an element from an array won’t achieve that.