Ar DeepEquals

From GECK
Jump to: navigation, search


A function added by the New Vegas Script Extender version 6.2.1.

Description

Compares the contents of two arrays, including key/element pairs from nested sub-arrays (though the arrays do not need to have sub-arrays). Returns 1 (true) if the arrays have the same contents in the same order, 0 (false) otherwise. If both arrays are null, also returns 1.

In xNVSE v6.2.1, with NVSE Expressions enabled via Let, Eval, etc, the Equality/Inequality operators (==/!=) can be used to compare the surface contents of two arrays. However, any sub-arrays are compared via checking their numeric IDs only, and not by checking their contents, so this function is made for comparing potentially multidimensional arrays in an extensive manner.

Syntax

[help]
(isEqual:bool) Ar_DeepEquals array1:array_var array2:array_var 

Or:

(isEqual:bool) Ar_DeepCompare array1:array_var array2:array_var 

Example

array_var arr1
array_var arr2
let arr1 := ar_List 1, 2
let arr2 := ar_List 1, 2
print $(Ar_DeepEquals arr1, arr2)

Prints "1" (true), since both arrays are equal.

let arr1 := ar_List 1, 2
let arr2 := ar_List 1, 100
print $(Ar_DeepEquals arr1, arr2)

Prints "0" (false), since both arrays have different elements.

let arr1 := ar_List 1, 2, (ar_list SunnyREF, 1, (ar_list 2, (ar_list 5, (Ar_Map 2::ArmorLeather, 10::CowboyHat05))))
let arr2 := ar_List 1, 2, (ar_list SunnyREF, 1 (ar_list 2, (ar_list 5, (Ar_Map 2::ArmorLeather, 10::CowboyHat05))))
print $(Ar_DeepEquals arr1, arr2)

This prints "1" (true), since both arrays have identical key/element pairs in the same order.

let arr1 := ar_List 1, 2, (ar_list SunnyREF, 1, (ar_list 2, (ar_list 5, (Ar_Map 2::ArmorLeather, 10::CowboyHat05))))
let arr2 := ar_List 1, 2, (ar_list SunnyREF, 1 (ar_list 2, (ar_list 5, (Ar_Map 2000::ArmorLeather, 10::CowboyHat05))))
print $(Ar_DeepEquals arr1, arr2)

This prints "0" (false), since the second array has a different key for the ArmorLeather element.

See Also