Skip to content

Commit

Permalink
Merge pull request #1706 from BrettMayson/this_reassign
Browse files Browse the repository at this point in the history
Common - Cleanup DEFAULT_PARAM, _this
  • Loading branch information
PabstMirror authored Nov 10, 2024
2 parents 8dded77 + 9f0b753 commit f592bff
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 45 deletions.
20 changes: 10 additions & 10 deletions addons/ai/fnc_taskPatrol.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
4 changes: 2 additions & 2 deletions addons/common/fnc_directCall.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ Author:
commy2
---------------------------------------------------------------------------- */

params [["_CBA_code", {}, [{}]], ["_this", []]];
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 {call _CBA_code}) select 0;
_CBA_return = ([_x] apply {_CBA_args call _CBA_code}) select 0;
};

if (!isNil "_CBA_return") then {_CBA_return};
4 changes: 1 addition & 3 deletions addons/common/fnc_getTerrainProfile.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions addons/diagnostic/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {"<any>"};
str _this
private _str = ([nil] apply compile _this) select 0;
if (isNil "_str") exitWith {"<any>"};
str _str
};
_returnString = _returnString select [0, 1000]; // limit string length
private _duration = diag_tickTime - _timeStart;
Expand Down
3 changes: 1 addition & 2 deletions addons/diagnostic/fnc_test.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ Author:

// ----------------------------------------------------------------------------

DEFAULT_PARAM(0,_addon,"cba");
DEFAULT_PARAM(1,_component,"main");
params [["_addon", "cba"], ["_component", "main"]];

LOG('===== STARTING TESTS =====');

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion addons/main/script_macros_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PARAMS_n()> to have a mix of required and
optional parameters.
Expand Down
8 changes: 5 additions & 3 deletions addons/ui/fnc_notify.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -83,7 +85,7 @@ private _skippable = false;
} else {
_composition pushBack parseText format ["<t align='center' size='%2' color='%3'>%1</t>", _text, _size, _color];
};
} forEach _this;
} forEach _args;

_composition deleteAt 0;

Expand Down
12 changes: 6 additions & 6 deletions addons/ui/fnc_openItemContextMenu.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -125,17 +125,17 @@ _list setVariable [QFUNC(activate), {

// Call statement and safe check return value.
private _keepOpen = [nil] apply {
private _this = [_this, _statement];
private _args = [_args, _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.
if (_keepOpen) then {
// Keep focus to prevent auto closing.
ctrlSetFocus _list;
} else {
[{ctrlDelete _this}, _list] call CBA_fnc_execNextFrame;
[{ctrlDelete _args}, _list] call CBA_fnc_execNextFrame;
};
};
}];
Expand Down
24 changes: 12 additions & 12 deletions addons/xeh/fnc_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check notice on line 39 in addons/xeh/fnc_init.sqf

View workflow job for this annotation

GitHub Actions / build

Variable should not be all caps: SLX_XEH_MACHINE

all caps variable
[{
{
[_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)
Expand Down
6 changes: 3 additions & 3 deletions addons/xeh/fnc_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f592bff

Please sign in to comment.