|Attention||Topic was automatically imported from the old Question2Answer platform.|
|Old Version||Published before Godot 3 was released.|
How do I compare one array with another?
var array1 = [0,1,0]
var array2 = [0,1,0]
if (array1 == array2):
Can someone help me please?!
your example should work, do you have any issues with that?
eons | 2017-05-17 17:51
var a1 = [0,1,0] var a2 = [0,1,0] print(a1 == a2) # prints True
volzhs | 2017-05-17 19:05
I’ve just stumbled with this ‘equality by value’ behavior.
Even though for most cases this is just what is needed, there are some scenarios where one would like to actually compare arrays by reference instead. I haven’t yet found a builtint way to do this, so I resorted to create a Wrapper script in order to wrap values that ‘compare by value’, so that you can compare (the wrapper) by reference instead. Here it is in case anyone needs it
extends Reference class_name Wrapper var value setget set_value, get_value func set_value(v): value=v func get_value(): return value func _init(v=null): value = v
gnumaru | 2021-12-21 15:19