3.5.3 Godot Version
I’m making a match 3 game (like candy crush) and I’m doing a hint, but I have had many errors, Mostly with “Invalid get index ‘0’ (on base: ‘Array’)” and “Invalid get index ‘6’ (on base: ‘Array’)”
I’m using those videos: https://www.youtube.com/watch?v=LwtyLSCbTt4&list=PL4vbr3u7UKWqwQlvwvgNcgDL1p_3hcNn2&index=51
The part of the code that the error marks is:
func find_all_matches():
var hint_holder = []
clone_array = copy_array(all_pieces)
for i in width:
for j in height:
if clone_array[i][j] != null:
if switch_and_check(Vector2(i, j), Vector2(1, 0), clone_array):
#add the piede i,j to the hint holder
if hint_color != "":
if hint_color == clone_array[i][j].color:
hint_holder.append(clone_array[i][j])
else:
hint_holder.append(clone_array[i + 1][j])
if switch_and_check(Vector2(i, j), Vector2(0, 1), clone_array):
#add the piede i,j to the hint holder
if hint_color != "":
if hint_color == clone_array[i][j].color:
hint_holder.append(clone_array[i][j])
else:
hint_holder.append(clone_array[i][j + 1])
return hint_holder
func generate_hint():
if hint:
hint.call_deferred("free")
var hints = find_all_matches()
if hints != null:
var rand = floor(rand_range(0, hints.size()))
hint = hint_effect.instance()
add_child(hint)
hint.position = hints[rand].position
hint.set_up(hints[rand].get_node("Sprite").texture)
Please, help.