DAGR / Interaction Menu / Repair - Fix overwriting globals (#7990)

* Remove global DAGR_NEXT variable

* Remove global ERR variable

* Fix overwriting global this variable

* Fix overwriting global total and hitpoint variables

* fix condition

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
BaerMitUmlaut 2020-11-08 15:54:14 +01:00 committed by GitHub
parent 5d1aa28419
commit 119450f4e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 10 deletions

View File

@ -201,7 +201,6 @@ class DAGR_Menu {
class DAGR_NEXT_Button : DAGR_Button {
idc = 266868;
action = QUOTE(DAGR_NEXT = true);
x = 0.60;
y = 0.65;
};

View File

@ -596,7 +596,6 @@ GVAR(menuRun) = true;
GVAR(F1) = false;
GVAR(MENU_B) = false;
GVAR(SEL) = false;
DAGR_NEXT = false;
GVAR(RIGHT) = false;
GVAR(LEFT) = false;
GVAR(UP) = false;

View File

@ -92,7 +92,6 @@ if (({((_x select 0) in _listOfItemsToRemove) && {(getNumber (configFile >> "Cfg
};
//Verify holder has mags unit had
if (!([_targetMagazinesStart, _targetMagazinesEnd, _holderMagazinesStart, _holderMagazinesEnd] call FUNC(verifyMagazinesMoved))) then {
ERR = [_targetMagazinesStart, _targetMagazinesEnd, _holderMagazinesStart, _holderMagazinesEnd];
_holder setVariable [QGVAR(holderInUse), false];
[_caller, _target, "Debug: Crate Magazines not in holder"] call FUNC(eventTargetFinish);
};

View File

@ -25,8 +25,6 @@ if (uiNamespace getVariable [QGVAR(cursorMenuOpened),false]) then {
};
if (GVAR(actionSelected)) then {
this = GVAR(selectedTarget);
private _player = ACE_Player;
private _target = GVAR(selectedTarget);
@ -38,6 +36,11 @@ if (GVAR(actionSelected)) then {
// Check the action conditions
private _actionData = GVAR(selectedAction) select 0;
// Use global variable this for action condition and action code
private _savedThis = this;
this = GVAR(selectedTarget);
if ([_target, _player, _actionData select 6] call (_actionData select 4)) then {
// Call the statement
[_target, _player, _actionData select 6] call (_actionData select 3);
@ -45,6 +48,9 @@ if (GVAR(actionSelected)) then {
// Clear the conditions caches again if the action was performed
[QGVAR(clearConditionCaches), []] call CBA_fnc_localEvent;
};
// Restore this variable
this = _savedThis;
};
["ace_interactMenuClosed", [GVAR(openedMenuType)]] call CBA_fnc_localEvent;

View File

@ -91,13 +91,16 @@ if (GVAR(openedMenuType) >= 0) then {
};
};
if (_runOnHover) then {
this = GVAR(selectedTarget);
private _player = ACE_Player;
private _target = GVAR(selectedTarget);
// Clear the conditions caches
[QGVAR(clearConditionCaches), []] call CBA_fnc_localEvent;
// Use global variable this for action condition and action code
private _savedThis = this;
this = GVAR(selectedTarget);
// Check the action conditions
private _actionData = GVAR(selectedAction) select 0;
if ([_target, _player, _actionData select 6] call (_actionData select 4)) then {
@ -107,6 +110,9 @@ if (GVAR(openedMenuType) >= 0) then {
// Clear the conditions caches again if the action was performed
[QGVAR(clearConditionCaches), []] call CBA_fnc_localEvent;
};
// Restore this variable
this = _savedThis;
};
};
};

View File

@ -41,15 +41,34 @@ private _fnc_getMemPointOffset = {
private _fnc_userAction_Statement = {
params ["_target", "_player", "_variable"];
_variable params ["_actionStatement", "_actionCondition"];
// Use global variable this for action condition and action code
private _savedThis = this;
this = _target getVariable [QGVAR(building), objNull];
call _actionStatement;
// Restore this variable
this = _savedThis;
};
private _fnc_userAction_Condition = {
params ["_target", "_player", "_variable"];
_variable params ["_actionStatement", "_actionCondition"];
private _building = _target getVariable [QGVAR(building), objNull];
if (isNull _building) exitWith {false};
// Use global variable this for action condition and action code
private _savedThis = this;
this = _target getVariable [QGVAR(building), objNull];
if (isNull this) exitWith {false};
call _actionCondition;
private _result = call _actionCondition;
// Restore this variable
this = _savedThis;
_result
};
private _configPath = configFile >> "CfgVehicles" >> _typeOfBuilding >> "UserActions";

View File

@ -46,9 +46,11 @@ TRACE_2("",_realHitPoints,_dependentHitPoints);
if (_dependentHitPoints isEqualTo []) exitWith {};
// Define global variables
Total = damage _vehicle;
// Define global variables and save original values
private _savedGlobals = [["total", total]];
total = damage _vehicle;
{
_savedGlobals pushBack [_x, missionNamespace getVariable _x];
missionNamespace setVariable [_x, _vehicle getHitPointDamage _x];
} forEach _realHitPoints;
@ -58,3 +60,8 @@ Total = damage _vehicle;
TRACE_2("setting depend hitpoint", _x, _damage);
_vehicle setHitPointDamage [_x, _damage];
} forEach _dependentHitPoints;
// Restore global variables
{
missionNamespace setVariable _x;
} forEach _savedGlobals;