jazzisparis / JIP-LN-NVSE

An extension for the New Vegas Script Extender (NVSE)
GNU General Public License v3.0
50 stars 14 forks source link

Enhance RefMapArray(Get/Set)Value #24

Closed Demorome closed 1 year ago

Demorome commented 2 years ago

Instead of taking/giving a single-element array, they now take/give a value of any type, similar to how it's done for NVSE functions like Ar_List. This should make them more convenient to use.

Below is a unit test to verify that these functions are working. You could remove the script name line and paste this into a file in data\nvse\unit_tests, so that if you have the "run unit tests" option enabled in xNVSE's ini, this test will be automatically executed whenever you launch the game, to verify it doesn't break in the future. (That's with xNVSE 6.2.8)


begin Function { }

    array_var aBoxed

    float fExpected = 1.5
    player.RefMapArraySetValue "test" fExpected 
    aBoxed = &(player.RefMapArrayGetValue "test")
    assert (*aBoxed == fExpected )
    assert ((player.RefMapArrayGetValue "test") == fExpected)
    float fVal = player.RefMapArrayGetValue "test"
    assert (fVal == fExpected)

    ref rExpected = SunnyREF
    player.RefMapArraySetValue "test" rExpected 
    aBoxed = &(player.RefMapArrayGetValue "test")
    assert (*aBoxed == rExpected )
    assert ((player.RefMapArrayGetValue "test") == rExpected )
    ref rVal = player.RefMapArrayGetValue "test"
    assert (rVal == rExpected)

    string_var sExpected = "expect"
    player.RefMapArraySetValue "test" sExpected 
    aBoxed = &(player.RefMapArrayGetValue "test")
    assert (*aBoxed == sExpected )
    assert ((player.RefMapArrayGetValue "test") == sExpected )
    string_var sVal = player.RefMapArrayGetValue "test"
    assert (sVal == sExpected)

/* Arrays are NOT supported

    array_var aExpected = ar_list 1, 2
    player.RefMapArraySetValue "test" aExpected 
    aBoxed = &(player.RefMapArrayGetValue "test")
    printvar aBoxed  ; PRINTS GARBAGE!
    assert (*aBoxed == aExpected )
    ;assert ((player.RefMapArrayGetValue "test") == aExpected )
    array_var aVal = player.RefMapArrayGetValue "test"
    printvar aVal
    assert (aVal == aExpected )
*/

    print "Finished running JIP RefMapArray(Get/Set)Value tests." 

end