Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | jimmyc |
why is godot randomly giving me an Invalid get index “0”(on base: array)?
I am trying to implement collisions for a fighting game. The script is supposed to turn hitboxes on and off using functions.
extends Node2D
var p1_fight_coll = []
var disable_coll = true
func _process(delta):
if(Input.is_action_just_pressed("ui_left")):
disable_coll = !disable_coll
_Handle_All_Collider_disabling(disable_coll)
if(Input.is_action_just_pressed("ui_left")):
disable_coll = !disable_coll
_Handle_Specific_Collider_Disabling(disable_coll, 0)
func _on_RightHand_body_entered(body):
pass # Replace with function body.
func _on_LeftHand_body_entered(body):
pass # Replace with function body.
func _on_RightFoot_body_entered(body):
pass # Replace with function body.
func _on_LeftFoot_body_entered(body):
pass # Replace with function body.
func _Handle_All_Collider_disabling(var is_disabled):
for colliders in get_tree().get_nodes_in_group("p1 hands feet collision"):
var h = 0
p1_fight_coll.insert(h, colliders)
p1_fight_coll[h].set_disabled(is_disabled)
if (p1_fight_coll[h].is_disabled()):
print(p1_fight_coll[h].name + " is disabled")
elif (!p1_fight_coll[h].is_disabled()):
print(p1_fight_coll[h].name + " is not disabled")#
print("")
h+= 1
func _Handle_Specific_Collider_Disabling(var is_disabled, var picked_coll):
p1_fight_coll[picked_coll].set_disabled(is_disabled)
if (p1_fight_coll[picked_coll].is_disabled()):
print(p1_fight_coll[picked_coll].name + " has been enabled")
if (!p1_fight_coll[picked_coll].is_disabled()):
print(p1_fight_coll[picked_coll].name + " has been DIS abled")
however, there is a problem with the lines:
p1_fight_coll[picked_coll].set_disabled(is_disabled)
and
_Handle_Specific_Collider_Disabling(disable_coll, 0)
though I am not sure why.
the error message given is
Invalid get index “0”(on base: array), even though changing the array number gives the same error.