A method to Update a Array with only new values?

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

-using Godot 3.02

Anyone know a method to update an array with only new values? In other words, checking a array with another array maybe?

I am creating a list inventory, where each button is a item, and I would like to update this list of buttons with only new items from the inventory.

I am trying to do this with a custom update function, but how do I check a array to see if anything changed?

Though about deleting the list of buttons and create them from scratch everytime my update function is called, but that is not optmized. Maybe my though process is wrong?

Thank you for your assistance,


do you mean you want to insert to array only not existing items? e.g. [a,b,c] + [a,c,d] → [a,b,c,d]

Bartosz | 2018-03-21 16:37

Ahm, yea, never though it would be that simple… Thanks man, that helps a lot.

But how do I compare two arrays for their values?

Edit: Found out, woa it is really simple to use arrays and dictionaries.

var a1 = [0,1,0]
var a2 = [0,1,0]
print(a1 == a2) #Returns true

The_Black_Chess_King | 2018-03-21 20:11

:bust_in_silhouette: Reply From: Bartosz

If I’m understanding correctly you want to combine arrays like this:

func insert_to_array(original_array, new_array):
	for v in new_array:
      if not original_array.has(v):