gc8 971 Posted June 25, 2019 Hi I'm writing this group replenishment script where I have one array that holds the groups starting roster (_startingRoster) and one array that holds the groups current roster (_curRoster). And I am pushing to the _curRoster the unit types missing from there. The problem I'm having is how do I sort the _curRoster so that the items in there are in same order as in _startingRoster? _startingRoster = ["B_APC_Wheeled_01_cannon_F", "B_Soldier_SL_F", "B_Soldier_TL_F", "B_soldier_repair_F", "B_soldier_repair_F", "B_medic_F"]; _curRoster = ["B_Soldier_SL_F","B_Soldier_TL_F","B_soldier_repair_F"]; _curRoster pushback _unitType; // Push back the items missing from _curRoster thx! Share this post Link to post Share on other sites
mrcurry 478 Posted June 25, 2019 (edited) 30 minutes ago, gc8 said: Hi I'm writing this group replenishment script where I have one array that holds the groups starting roster (_startingRoster) and one array that holds the groups current roster (_curRoster). And I am pushing to the _curRoster the unit types missing from there. The problem I'm having is how do I sort the _curRoster so that the items in there are in same order as in _startingRoster? _startingRoster = ["B_APC_Wheeled_01_cannon_F", "B_Soldier_SL_F", "B_Soldier_TL_F", "B_soldier_repair_F", "B_soldier_repair_F", "B_medic_F"]; _curRoster = ["B_Soldier_SL_F","B_Soldier_TL_F","B_soldier_repair_F"]; _curRoster pushback _unitType; // Push back the items missing from _curRoster thx! Well since you're asking here I assume you have considered just dropping the data in _curRoster and do _curRoster = +_startingRoster? Unless you have to input elements over time the above should be enough. Edited June 25, 2019 by mrcurry Share this post Link to post Share on other sites
gc8 971 Posted June 25, 2019 Just now, mrcurry said: Well since you're asking here I assume you have considered just dropping the data in _curRoster and do _curRoster = +_startingRoster? Unless you have to input one at the time then the above should be enough. Can't do that. I'm filling the _curRoster one item at a time. And it should be sorted correctly after each new item. Share this post Link to post Share on other sites
mrcurry 478 Posted June 25, 2019 4 minutes ago, gc8 said: Can't do that. I'm filling the _curRoster one item at a time. And it should be sorted correctly after each new item. How is _cur filled? units _grp apply {typeOf _x}? Edit, what I mean is: where does the initial state of the group come from? Do you manage that on your own or just rely on an engine check? Share this post Link to post Share on other sites
gc8 971 Posted June 25, 2019 1 minute ago, mrcurry said: How is _cur filled? units _grp apply {typeOf _x}? _curRoster pushback _unitType; Share this post Link to post Share on other sites
Schatten 268 Posted June 25, 2019 @gc8, try this function: params [ ["_startingRoster", [], [[]]], ["_currentRoster", [], [[]]] ]; if ((_startingRoster isEqualTo []) or { _currentRoster isEqualTo [] }) exitWith { [] }; private ["_currentRosterOrdered", "_index"]; _currentRosterOrdered = []; { _index = _currentRoster find _x; if (_index >= 0) then { _currentRoster deleteAt _index; _currentRosterOrdered pushBack _x; }; } forEach _startingRoster; _currentRosterOrdered + _currentRoster; 1 1 Share this post Link to post Share on other sites
mrcurry 478 Posted June 25, 2019 9 minutes ago, gc8 said: _curRoster pushback _unitType; You're gonna have to give us something more to work with. What's the initial setup and what exactly needs to be done? Edit: scratch that, unless you're leaving something important out the pushback should be enough since the item is always added last. 2 Share this post Link to post Share on other sites
gc8 971 Posted June 25, 2019 @Schatten Thx, tried that but it makes _curRoster empty array Share this post Link to post Share on other sites
Schatten 268 Posted June 25, 2019 @gc8, just assign new value: _curRoster = [_startingRoster, _curRoster] call fnc; Share this post Link to post Share on other sites
gc8 971 Posted June 25, 2019 11 minutes ago, mrcurry said: You're gonna have to give us something more to work with. What's the initial setup and what exactly needs to be done? Alright, I'll post my code here was thinking of saving you from this at first but here you go 🙂 It's not in any regard final script but a prototype _startingRoster = ["B_APC_Wheeled_01_cannon_F", "B_Soldier_SL_F", "B_Soldier_TL_F", "B_soldier_repair_F", "B_soldier_repair_F", "B_medic_F"]; _curRoster = ["B_Soldier_SL_F","B_Soldier_TL_F","B_soldier_repair_F"]; replenishGroup = { _numVehsTotal = { !(_x isKindOf "man") } count _startingRoster; _numMenTotal = (count _startingRoster) - _numVehsTotal; _vehRepTime = -1; _menRepTime = -1; _repCheck = { params ["_numCur","_numTotal","_repTime"]; if(_numCur < _numTotal) then { if(_repTime < 0) then { _repTime = time; }; if( (time - _repTime) > 3 ) then { scopename "replenishCheck"; _repTime = -1; // Reset timer // Replenish { _unitType = _x; _numTypeShouldBe = { _x == _unitType } count _startingRoster; _numTypeIs = { _x == _unitType } count _curRoster; if(_numTypeIs < _numTypeShouldBe) then { systemchat format["rep one %1" , _unitType]; _curRoster pushback _unitType; // Replenish breakOut "replenishCheck"; }; } forEach _startingRoster; }; }; _repTime }; sleep 0.1; while { true } do { if(true) then { _numVehsCur = { !(_x isKindOf "man") } count _curRoster; _numMenCur = (count _curRoster) - _numVehsCur; _vehRepTime = [_numVehsCur,_numVehsTotal,_vehRepTime] call _repCheck; _menRepTime = [_numMenCur,_numMenTotal,_menRepTime] call _repCheck; systemchat format["Cur roster: %1 %2", count _curRoster, _curRoster]; } else { _vehRepTimes = -1; _menRepTime = -1; }; sleep 3.5; }; }; to call: call replenishGroup; Share this post Link to post Share on other sites
gc8 971 Posted June 25, 2019 2 minutes ago, Schatten said: @gc8, just assign new value: _curRoster = [_startingRoster, _curRoster] call fnc; works now, thx! 🙂 Share this post Link to post Share on other sites
gc8 971 Posted June 25, 2019 @Schatten Can I use that function in my mission? Share this post Link to post Share on other sites
pierremgi 4753 Posted June 25, 2019 _startingRoster = ["B_APC_Wheeled_01_cannon_F","B_Soldier_SL_F","B_Soldier_TL_F","B_soldier_repair_F","B_soldier_repair_F","B_medic_F"]; _cloningRoster = +_startingRoster; _curRoster = ["B_Soldier_SL_F","B_Soldier_TL_F","B_soldier_repair_F"]; {_curr = _x; _cloningRoster deleteAt (_cloningRoster findIf {_x == _curr})} forEach _curRoster; // the true difference of arrays: here ["B_APC_Wheeled_01_cannon_F","B_soldier_repair_F","B_medic_F"] {_missing = _x; _curRoster = [_curRoster,[_x],_startingRoster findIf {_x == _missing}] call BIS_fnc_arrayInsert} forEach _cloningRoster; // you recover the _startingRoster in _curRoster 1 Share this post Link to post Share on other sites