Yuck. That’s not going to cut it for me here. Is there any workaround to this? I’m inexperienced, and I don’t see the usefulness of comparing one Array to itself.
You just have to use the index to compare the values, like what Daniel said. Without the index you’re comparing the array objects, with the index you’re comparing the actual values at that location.
You have to compare every element individually. For instance like this:
// Put this in a file called ArrayUtil.js
static function CompareContents(a : Array, b : Array) {
// If both arguments point to the same object, return true:
if ( a == b )
return true;
// If the arrays are of different length then they can't have
// equal contents:
if ( a.length != b.length )
return false;
// Else loop through each element and return false if any
// of them differ:
for ( var i=0; i < a.length; i++ ) {
if( a[i] != b[i] )
return false;
}
// If we reach this point, then both arrays contain the same:
return true;
}
… and then use it like this:
private var stuff : Array;
function Start () {
stuff = ["1"];
}
function Update () {
print ( ArrayUtil.CompareContents(stuff, ["1"]) );
}