Jump to content
highhead

BIS_fnc_sortBy - broken

Recommended Posts

Seems like filter (select 4) in BIS_fnc_sortBy is broken :(

 

According to: https://community.bistudio.com/wiki/BIS_fnc_sortBy

_this select 4: filter (Code) [optional: default {true}]- code that needs to evaluate true for the array item to be sorted, otherwise item is removed
_test = ["a","b","c","d","e","f"];

        _test = [_test,[],{
    
            diag_log ("sorting: " + str(_x));
            
            _x
        },"DESCEND", {

        diag_log ("filtering: " + str(_x));

        _x == "a"
        }] call BIS_fnc_sortBy;

hint str(_test);

//result: ["e","c","a"]
//expected result: ["a"];

//Log:
//18:08:51 "filtering: "a""
//18:08:51 "filtering: "b""
//18:08:51 "filtering: "d""
//18:08:51 "filtering: "f""
//18:08:51 "sorting: "a""
//18:08:51 "sorting: "c""
//18:08:51 "sorting: "e""
//Totally wrong... _x not threadsave?

-------------------------------------------------

_test = ["a","b","c","d","e","f"];

        _test = [_test,[],{
    
            diag_log ("sorting: " + str(_x));
            
            _x
        },"DESCEND", {

        diag_log ("filtering: " + str(_x));

        _x == "a" || _x == "b"
        }] call BIS_fnc_sortBy;

hint str(_test);

//result: ["f","d","b","a"]
//expected result: ["b","a"];

//Log:
18:16:21 "filtering: "a""
18:16:21 "filtering: "b""
18:16:21 "filtering: "c""
18:16:21 "filtering: "e""
18:16:21 "sorting: "a""
18:16:21 "sorting: "b""
18:16:21 "sorting: "d""
18:16:21 "sorting: "f""

-------------------------------------------------

_test = [1,2,3,4,5,6];

        _test = [_test,[],{
    
            diag_log ("sorting: " + str(_x));
            
            _x
        },"DESCEND", {

        diag_log ("filtering: " + str(_x));

        _x <= 3
        }] call BIS_fnc_sortBy;

hint str(_test);

//result: [5,3,2,1];
//expected result: [3,2,1];

//Log
18:20:25 "filtering: 1"
18:20:25 "filtering: 2"
18:20:25 "filtering: 3"
18:20:25 "filtering: 5"
18:20:25 "sorting: 1"
18:20:25 "sorting: 2"
18:20:25 "sorting: 4"
18:20:25 "sorting: 6"

Acting totally weird, breaking every script that uses the filter!

No workaround within the function, only pre-filtering the array before using that function works... :(

Share this post


Link to post
Share on other sites

Confirm (1.56.134627).

Also, it does not raise error now if _this select 2: sorted algorithm (Code) returns non-scalar (like in first highhead's example).

Share this post


Link to post
Share on other sites

The problem is in lines

	// replace with select {}
	{if !(call _filterFnc) then {_inputArray deleteAt _forEachIndex}} forEach _inputArray;

Deleting from array being iterated. Every element following deleted element is not being checked at all.

 

Since BIS_fnc_sortBy now uses sort internally, requirement for _this select 2: sorted algorithm (Code) to return scalar is no longer actual. It can return strings, numbers and arrays (all what sort accepts).

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×