From dafc3dcfc4bd3c2d266a0c9867b0aeb8463c7c72 Mon Sep 17 00:00:00 2001 From: Brett Mayson Date: Sat, 19 Oct 2024 01:36:25 +0000 Subject: [PATCH 1/5] don't use DEFAULT_PARAM, use different name for _this --- addons/ai/fnc_taskPatrol.sqf | 20 ++++++------- addons/common/fnc_getTerrainProfile.sqf | 4 +-- addons/diagnostic/XEH_preInit.sqf | 6 ++-- addons/diagnostic/fnc_test.sqf | 3 +- addons/diagnostic/test_parameters.sqf | 40 ------------------------- addons/ui/fnc_notify.sqf | 8 +++-- addons/ui/fnc_openItemContextMenu.sqf | 4 +-- 7 files changed, 22 insertions(+), 63 deletions(-) delete mode 100644 addons/diagnostic/test_parameters.sqf diff --git a/addons/ai/fnc_taskPatrol.sqf b/addons/ai/fnc_taskPatrol.sqf index 815637939a..42252fddf8 100644 --- a/addons/ai/fnc_taskPatrol.sqf +++ b/addons/ai/fnc_taskPatrol.sqf @@ -54,10 +54,10 @@ _position = _position call CBA_fnc_getPos; } forEach units _group; // Can pass parameters straight through to addWaypoint -_this =+ _this; -_this set [2,-1]; -if (count _this > 3) then { - _this deleteAt 3; +private _args = +_this; +_args set [2,-1]; +if (count _args > 3) then { + _args deleteAt 3; }; // Using angles create better patrol patterns @@ -71,12 +71,12 @@ for "_i" from 1 to _count do { // Alternate sides of circle & modulate offset private _theta = (_i % 2) * 180 + sin (deg (_step * _i)) * _offset + _step * _i; - _this set [1, _position getPos [_rad, _theta]]; - _this call CBA_fnc_addWaypoint; + _args set [1, _position getPos [_rad, _theta]]; + _args call CBA_fnc_addWaypoint; }; // Close the patrol loop -_this set [1, _position]; -_this set [2, _radius]; -_this set [3, "CYCLE"]; -_this call CBA_fnc_addWaypoint; +_args set [1, _position]; +_args set [2, _radius]; +_args set [3, "CYCLE"]; +_args call CBA_fnc_addWaypoint; diff --git a/addons/common/fnc_getTerrainProfile.sqf b/addons/common/fnc_getTerrainProfile.sqf index 2145dd2f9c..6fdba4bdad 100644 --- a/addons/common/fnc_getTerrainProfile.sqf +++ b/addons/common/fnc_getTerrainProfile.sqf @@ -22,13 +22,11 @@ Author: ---------------------------------------------------------------------------- */ -params ["_posA","_posB"]; +params ["_posA","_posB", ["_resolution", 10]]; _posA = _posA call CBA_fnc_getPos; _posB = _posB call CBA_fnc_getPos; _posA set [2,0]; _posB set [2,0]; -DEFAULT_PARAM(2,_resolution,10); - private _angle = [_posA, _posB] call BIS_fnc_dirTo; private _2Ddistance = [_posA, _posB] call BIS_fnc_distance2D; diff --git a/addons/diagnostic/XEH_preInit.sqf b/addons/diagnostic/XEH_preInit.sqf index 3f09384da1..f111b1a607 100644 --- a/addons/diagnostic/XEH_preInit.sqf +++ b/addons/diagnostic/XEH_preInit.sqf @@ -27,9 +27,9 @@ if (getMissionConfigValue ["EnableTargetDebug", 0] == 1 || {getNumber (configFil private _timeStart = diag_tickTime; private _returnString = _statementText call { private ["_clientID", "_statementText", "_varName", "_timeStart", "_x"]; // prevent these variables from being overwritten - _this = ([nil] apply compile _this) select 0; - if (isNil "_this") exitWith {""}; - str _this + private _str = ([nil] apply compile _this) select 0; + if (isNil "_str") exitWith {""}; + str _str }; _returnString = _returnString select [0, 1000]; // limit string length private _duration = diag_tickTime - _timeStart; diff --git a/addons/diagnostic/fnc_test.sqf b/addons/diagnostic/fnc_test.sqf index 183c011361..89ac5e465f 100644 --- a/addons/diagnostic/fnc_test.sqf +++ b/addons/diagnostic/fnc_test.sqf @@ -37,8 +37,7 @@ Author: // ---------------------------------------------------------------------------- -DEFAULT_PARAM(0,_addon,"cba"); -DEFAULT_PARAM(1,_component,"main"); +params [["_addon", "cba"], ["_component", "main"]]; LOG('===== STARTING TESTS ====='); diff --git a/addons/diagnostic/test_parameters.sqf b/addons/diagnostic/test_parameters.sqf deleted file mode 100644 index bbd127181c..0000000000 --- a/addons/diagnostic/test_parameters.sqf +++ /dev/null @@ -1,40 +0,0 @@ -// ---------------------------------------------------------------------------- - -#include "script_component.hpp" - -SCRIPT(test_parameters); - -// ---------------------------------------------------------------------------- - -LOG("Testing parameters"); - -private ["_expected", "_result", "_this"]; - -// Test default params. -_this = [5]; -DEFAULT_PARAM(0,_result,12); -_expected = 5; -TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); - -_result = nil; - -_this = []; -DEFAULT_PARAM(0,_result,12); -_expected = 12; -TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); - -_result = nil; - -_this = [nil]; -DEFAULT_PARAM(0,_result,12); -_expected = 12; -TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); - -_result = nil; - -_this = nil; -DEFAULT_PARAM(0,_result,12); -_expected = 12; -TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); - -nil; diff --git a/addons/ui/fnc_notify.sqf b/addons/ui/fnc_notify.sqf index 0dc44f0408..8b2c6c0c52 100644 --- a/addons/ui/fnc_notify.sqf +++ b/addons/ui/fnc_notify.sqf @@ -39,13 +39,15 @@ if (canSuspend) exitWith { if (!hasInterface) exitWith {}; +private _args = _this; + // compose structured text if !(_this isEqualType []) then { - _this = [_this]; + _args = [_this]; }; if !(_this select 0 isEqualType []) then { - _this = [_this]; + _args = [_this]; }; private _composition = []; @@ -83,7 +85,7 @@ private _skippable = false; } else { _composition pushBack parseText format ["%1", _text, _size, _color]; }; -} forEach _this; +} forEach _args; _composition deleteAt 0; diff --git a/addons/ui/fnc_openItemContextMenu.sqf b/addons/ui/fnc_openItemContextMenu.sqf index b405bb25aa..3fcf6b71da 100644 --- a/addons/ui/fnc_openItemContextMenu.sqf +++ b/addons/ui/fnc_openItemContextMenu.sqf @@ -125,9 +125,9 @@ _list setVariable [QFUNC(activate), { // Call statement and safe check return value. private _keepOpen = [nil] apply { - private _this = [_this, _statement]; + private _args = [_this, _statement]; private ["_list", "_index", "_condition", "_statement", "_consume"]; - (_this select 0) call (_this select 1) // return + (_args select 0) call (_args select 1) // return } param [0, false] isEqualTo true; // If statement returned true, keep context menu open, otherwise close. From fc0ea376e51337f5ca02f902e1677871a8d5edae Mon Sep 17 00:00:00 2001 From: Brett Mayson Date: Sat, 19 Oct 2024 01:40:47 +0000 Subject: [PATCH 2/5] restore test --- addons/diagnostic/test_parameters.inc.sqf | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 addons/diagnostic/test_parameters.inc.sqf diff --git a/addons/diagnostic/test_parameters.inc.sqf b/addons/diagnostic/test_parameters.inc.sqf new file mode 100644 index 0000000000..bbd127181c --- /dev/null +++ b/addons/diagnostic/test_parameters.inc.sqf @@ -0,0 +1,40 @@ +// ---------------------------------------------------------------------------- + +#include "script_component.hpp" + +SCRIPT(test_parameters); + +// ---------------------------------------------------------------------------- + +LOG("Testing parameters"); + +private ["_expected", "_result", "_this"]; + +// Test default params. +_this = [5]; +DEFAULT_PARAM(0,_result,12); +_expected = 5; +TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); + +_result = nil; + +_this = []; +DEFAULT_PARAM(0,_result,12); +_expected = 12; +TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); + +_result = nil; + +_this = [nil]; +DEFAULT_PARAM(0,_result,12); +_expected = 12; +TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); + +_result = nil; + +_this = nil; +DEFAULT_PARAM(0,_result,12); +_expected = 12; +TEST_OP(_result,==,_expected,"DEFAULT_PARAM"); + +nil; From 3d27aad9ad73630716c30ad1080f67d3609ce19e Mon Sep 17 00:00:00 2001 From: Brett Mayson Date: Sat, 19 Oct 2024 02:53:45 +0000 Subject: [PATCH 3/5] params --- addons/common/fnc_directCall.sqf | 4 ++-- addons/ui/fnc_openItemContextMenu.sqf | 10 +++++----- addons/xeh/fnc_init.sqf | 24 ++++++++++++------------ addons/xeh/fnc_postInit.sqf | 6 +++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/addons/common/fnc_directCall.sqf b/addons/common/fnc_directCall.sqf index d4eda2224f..92df23c2ba 100644 --- a/addons/common/fnc_directCall.sqf +++ b/addons/common/fnc_directCall.sqf @@ -22,14 +22,14 @@ Author: commy2 ---------------------------------------------------------------------------- */ -params [["_CBA_code", {}, [{}]], ["_this", []]]; +params [["_CBA_code", {}, [{}]], ["_args", []]]; private "_CBA_return"; isNil { // Wrap the _CBA_code in an extra call block to prevent problems with exitWith and apply //IGNORE_PRIVATE_WARNING ["_x"]; - _CBA_return = ([_x] apply {call _CBA_code}) select 0; + _CBA_return = ([_x] apply {_args call _CBA_code}) select 0; }; if (!isNil "_CBA_return") then {_CBA_return}; diff --git a/addons/ui/fnc_openItemContextMenu.sqf b/addons/ui/fnc_openItemContextMenu.sqf index 3fcf6b71da..12d9f49e76 100644 --- a/addons/ui/fnc_openItemContextMenu.sqf +++ b/addons/ui/fnc_openItemContextMenu.sqf @@ -111,11 +111,11 @@ private _unit = call CBA_fnc_currentUnit; // Execute context menu option statement on selection. _list setVariable [QFUNC(activate), { params ["_list", "_index"]; - _list getVariable (_list lbData _index) params ["_condition", "_statement", "_consume", "_this"]; + _list getVariable (_list lbData _index) params ["_condition", "_statement", "_consume", "_args"]; - if (_this call _condition) then { + if (_args call _condition) then { if (_consume) then { - params ["_unit", "_container", "_item", "_slot"]; + _args params ["_unit", "_container", "_item", "_slot"]; if !([_unit, _item, _slot, _container] call CBA_fnc_consumeItem) then { ERROR_2("Cannot consume item %1 from %2.",_item,_slot); @@ -125,7 +125,7 @@ _list setVariable [QFUNC(activate), { // Call statement and safe check return value. private _keepOpen = [nil] apply { - private _args = [_this, _statement]; + private _args = [_args, _statement]; private ["_list", "_index", "_condition", "_statement", "_consume"]; (_args select 0) call (_args select 1) // return } param [0, false] isEqualTo true; @@ -135,7 +135,7 @@ _list setVariable [QFUNC(activate), { // Keep focus to prevent auto closing. ctrlSetFocus _list; } else { - [{ctrlDelete _this}, _list] call CBA_fnc_execNextFrame; + [{ctrlDelete _args}, _list] call CBA_fnc_execNextFrame; }; }; }]; diff --git a/addons/xeh/fnc_init.sqf b/addons/xeh/fnc_init.sqf index 45db4f4889..6025e60543 100644 --- a/addons/xeh/fnc_init.sqf +++ b/addons/xeh/fnc_init.sqf @@ -21,33 +21,33 @@ Author: commy2 ---------------------------------------------------------------------------- */ -params ["_this"]; +params ["_object"]; -if (_this call CBA_fnc_isTerrainObject) exitWith { - INFO_2("Abort init event for terrain object %1. Class: %2.",_this,typeOf _this); +if (_object call CBA_fnc_isTerrainObject) exitWith { + INFO_2("Abort init event for terrain object %1. Class: %2.",_object,typeOf _object); }; -if !(ISINITIALIZED(_this)) then { - SETINITIALIZED(_this); +if !(ISINITIALIZED(_object)) then { + SETINITIALIZED(_object); // run Init { - [_this] call _x; - } forEach (_this getVariable QGVAR(init)); + [_object] call _x; + } forEach (_object getVariable QGVAR(init)); // run InitPost or put on stack if (SLX_XEH_MACHINE select 8) then { [{ { - [_this] call _x; - } forEach (_this getVariable QGVAR(initPost)); - }, _this] call CBA_fnc_execNextFrame; + [_object] call _x; + } forEach (_object getVariable QGVAR(initPost)); + }, _object] call CBA_fnc_execNextFrame; } else { - GVAR(initPostStack) pushBack _this; + GVAR(initPostStack) pushBack _object; }; // fix for respawnVehicle clearing the object namespace - _this addEventHandler ["Respawn", { + _object addEventHandler ["Respawn", { params ["_vehicle", "_wreck"]; if (ISINITIALIZED(_vehicle)) exitWith {}; // Exit if unit respawned normaly with copied variables (e.g. humans) diff --git a/addons/xeh/fnc_postInit.sqf b/addons/xeh/fnc_postInit.sqf index 09d0417f10..0f2fe579c6 100644 --- a/addons/xeh/fnc_postInit.sqf +++ b/addons/xeh/fnc_postInit.sqf @@ -45,11 +45,11 @@ isNil { // do InitPost { - _x params ["_this"]; + _x params ["_object"]; { - [_this] call _x; - } forEach (_this getVariable QGVAR(initPost)); + [_object] call _x; + } forEach (_object getVariable QGVAR(initPost)); } forEach GVAR(initPostStack); GVAR(initPostStack) = nil; From a0f84642a5b4c8207761768ce7fa5c3407913242 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 31 Oct 2024 20:29:01 -0500 Subject: [PATCH 4/5] Add note for `DEFAULT_PARAM` --- addons/main/script_macros_common.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/main/script_macros_common.hpp b/addons/main/script_macros_common.hpp index 2683f3b033..ef31234b47 100644 --- a/addons/main/script_macros_common.hpp +++ b/addons/main/script_macros_common.hpp @@ -1335,7 +1335,7 @@ Macros: PARAMS_n() /* ------------------------------------------- Macro: DEFAULT_PARAM() - DEPRECATED - Use param/params commands added in Arma 3 1.48 + DEPRECATED - Use param/params commands added in Arma 3 1.48 - Will not work with HEMTT 1.13.2+ Getting a default function parameter. This may be used together with to have a mix of required and optional parameters. From 9f0b7537401b8b82caf6d29b2e0e16b6aa0eb806 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 31 Oct 2024 20:30:53 -0500 Subject: [PATCH 5/5] add cba prefix to local _args --- addons/common/fnc_directCall.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/fnc_directCall.sqf b/addons/common/fnc_directCall.sqf index 92df23c2ba..94762994db 100644 --- a/addons/common/fnc_directCall.sqf +++ b/addons/common/fnc_directCall.sqf @@ -22,14 +22,14 @@ Author: commy2 ---------------------------------------------------------------------------- */ -params [["_CBA_code", {}, [{}]], ["_args", []]]; +params [["_CBA_code", {}, [{}]], ["_CBA_args", []]]; private "_CBA_return"; isNil { // Wrap the _CBA_code in an extra call block to prevent problems with exitWith and apply //IGNORE_PRIVATE_WARNING ["_x"]; - _CBA_return = ([_x] apply {_args call _CBA_code}) select 0; + _CBA_return = ([_x] apply {_CBA_args call _CBA_code}) select 0; }; if (!isNil "_CBA_return") then {_CBA_return};