From 43ecd308eb48e7fd34d7d801356a54668ea5c37e Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Tue, 21 Jul 2015 20:00:09 +0100 Subject: [PATCH] Fix empty array error --- .../spectator/functions/fnc_cycleCamera.sqf | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/addons/spectator/functions/fnc_cycleCamera.sqf b/addons/spectator/functions/fnc_cycleCamera.sqf index 9f74214a56..474d25cd0c 100644 --- a/addons/spectator/functions/fnc_cycleCamera.sqf +++ b/addons/spectator/functions/fnc_cycleCamera.sqf @@ -26,28 +26,33 @@ _units = GVAR(unitList); _visions = GVAR(availableVisions); // Get current index -_iMode = abs(_modes find GVAR(camMode)); -_iUnit = abs(_units find GVAR(camUnit)); -_iVision = abs(_visions find GVAR(camVision)); +_iMode = (_modes find GVAR(camMode)) max 0; +_iUnit = (_units find GVAR(camUnit)) max 0; +_iVision = (_visions find GVAR(camVision)) max 0; _countModes = count _modes; _countUnits = count _units; _countVisions = count _visions; -// Step index by step number (lopp ends) -_iMode = (_iMode + _stepMode) % _countModes; -if (_iMode < 0) then { _iMode = _countModes + _iMode; }; +// Step index by step number (loop at ends) +if (_countModes != 0) then { + _iMode = (_iMode + _stepMode) % _countModes; + if (_iMode < 0) then { _iMode = _countModes + _iMode; }; +}; -_iUnit = (_iUnit + _stepUnit) % _countUnits; -if (_iUnit < 0) then { _iUnit = _countUnits + _iUnit; }; +if (_countUnits != 0) then { + _iUnit = (_iUnit + _stepUnit) % _countUnits; + if (_iUnit < 0) then { _iUnit = _countUnits + _iUnit; }; +}; -_iVision = (_iVision + _stepVision) % _countVisions; -if (_iVision < 0) then { _iVision = _countVisions + _iVision; }; +if (_countVisions != 0) then { + _iVision = (_iVision + _stepVision) % _countVisions; + if (_iVision < 0) then { _iVision = _countVisions + _iVision; }; +}; // Get value at new index _newMode = _modes select _iMode; _newUnit = _units select _iUnit; _newVision = _visions select _iVision; - [_newMode, _newUnit, _newVision] call FUNC(transitionCamera);