Why is my code not properly apending data to an array?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fij707

So here I’m appending some data to ‘to_hit’ in a loop. The function ‘game._get_stats_snapshot()’ from a singleton.
But the snapshot returns don’t seem to be written properly somehow?

			var snapshot = [] + game._get_stats_snapshot()
			print(snapshot)
			to_hit.append([game.objects[i.x][i.y],0,map_compute_pass,Vector2(i.x,i.y),snapshot]) 
			game.objects[i.x][i.y] = 0

for i in to_hit: print(i)

snapshot:
[50, 0, [74, 1, 1, 1, 1], [0, 0, 0, 0, 0]]
[50, 0, [73, 1, 1, 1, 1], [0, 0, 0, 0, 0]]
[50, 0, [72, 1, 1, 1, 1], [0, 0, 0, 0, 0]]
to_hit:
[1, 0, 0, (4, 3), [50, 0, [72, 1, 1, 1, 1], [0, 0, 0, 0, 0]]]
[1, 0, 0, (4, 5), [50, 0, [72, 1, 1, 1, 1], [0, 0, 0, 0, 0]]]
[1, 0, 0, (4, 4), [50, 0, [72, 1, 1, 1, 1], [0, 0, 0, 0, 0]]]

As you can see the sequence there should be 74>73>72 but just ends up as 72>72>72

Any help much appreciated <3

Can you put your singleton script on here? We need more info. to help, put all functions you referenced in your code snippet on your post please. Thanks.

Moldor2 | 2020-11-11 18:13

What Moldor2 said. Also, you claim to add data in a loop, but there is no loop (other than the one for printing the data). And if there was a loop, the loop variable (i?) should probably also be added as index for the snapshot (snapshot[i]).

Thomas Karcher | 2020-11-11 22:51