Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Joakim Wennergren |
Hi!
I have a simple question to a difficult problem: How do i delete an item from a 2D array?
if selectedHearts.size() > 0:
for x in range(8):
for y in range(10):
if selectedHearts.has(hearts[x][y].get_node("Sprite")):
hearts[x][y].queue_free()
I need to remove hearts[y] in the loop here. how do i do it?
Not sure what you want to achieve: Removing any element (e.g. with hearts.remove(y)) would break your loop, since now there would only be 9 y elements left for the given x, not 10. Moreover, its not clear which elements should fill the gap: Should y be reduced (like in my line above), or x? Do you have an example project?
Thomas Karcher | 2019-05-26 21:11
https://pastebin.com/0fUN2wSL
Here is all the code.
Everytime i queue_free() a node in hearts 2D array i get an error saying: “Attempt to call function ‘get_node’ in base ‘previously freed instance’ on a null instance.” in my find_neighbour() function.
what im trying to do is to that element from the 2D array and later refill it.
Joakim Wennergren | 2019-05-26 21:20