The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

-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,

TBCK

in Engine by (381 points)

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]

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

1 Answer

+1 vote
Best answer

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):
        original_array.push_back(v)
by (1,024 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.