Is it possible to check if array has a weakref?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cardoso
:warning: Old Version Published before Godot 3 was released.

I’m trying to check if an array already has a weekref to a character/node before adding that character’s weak reference to the array.
Something like this:

if !array.has( weakref( char ) ):
   array.push_back( weakref( char )  )

But it always adds the new reference of the same character (so the array just gets many more weakrefs to the same character). I’m guessing that there can obviously be many different weakrefs to the same character/node.

Is there a way to compare 2 weakrefs?
If not, what can I do? (If instead of weakrefs I add the character itsself to the array, it might cause issues when that character is freeded/deleted.)

:bust_in_silhouette: Reply From: aozasori

Unfortunately, i think you’ll have to do something like this.

func char_in_array(array, char):
	for x in array:
		if char == x.get_ref():
			return true
	return false

if !char_in_array(array, char):
	array.push_back(weakref(char))