Page MenuHomeFeedback Tracker

buttonSetAction sometimes fucks around with the script code
Closed, ResolvedPublic


During my modding project XMS2 i discovered that some working scripts are "bugged" due the time when they got added to a command array

as example just lets pick this here:


private['_unit', '_x'];
X39_XLib_var_ActionDialog_Executor playMove 'AidlPknlMstpSrasWrflDnon_AI';
_unit = objNull;

		if(_x getVariable ['X39_MS2_var_UnitInitialized', false]) then
			_unit = _x;

} count attachedObjects X39_XLib_var_ActionDialog_Executor;
if(!isNull _unit) then

		detach _unit;
		_unit playMove 'AinjPpneMstpSnonWrflDb_release';


		systemChat 'WHOOOPS! Something moved TERRIBLY wrong ...';
		systemChat 'Seems like ArmA bugs out with SQF AGAIN -.-*';
		systemChat 'Please report at XMS2 bugTracker and well ...';
		systemChat 'keep attached : /';


  • call X39_XLib_fnc_ActionDialog_closeDialog; }

there is no issue inside of this peice of code
but arma thinks different:

Error in expression <else>
Error position: <else>
Error Undefined variable in expression: else
Error in expression <else>
Error position: <else>
Error Undefined variable in expression: else

(sometimes arma also prints that the operation _unit = _x would be invalid ...)

i was able to discover that the issue is bount to the fact that im using a function to register the code (when using the ESC menu this wont happen)


Legacy ID
Operating System
Windows 7
Steps To Reproduce

First of all
sorry that im not able to provide something more accurate

  1. enable XMS2 & XLib in your mod string (suddenly you need to build it by yourself as i cannot attach them to this ticket)
  2. run ArmA 3
  3. head into the editor
  4. place down a player unit
  5. place down an AI unit
  6. click preview
  7. press ESC & navigate into the new menu entry mod properties
  8. select "XLib Action Dialog" from the left list
  9. double click & assign the self/others interaction key on the top right menu
  10. close the menu & use the others interaction menu (by pressing the key youve assigned) on the AI unit
  11. select "drag unit" (first unexpected scripting issue appears here but script runs as expected)
  12. use the self itneraction menu by pressing the key youve assigned
  13. select "drop unit" (second unexpected scripting issue appears here but script wont be executed correctly)
Additional Information

Git repos of both projects (might be already "patched" using a workaround i will find)

my steamaccount for direct chat if required

While working on this ticket it could be usefull to enable the DEBUG define in the default.hpp file to follow the XMS2/XLib function calls

Event Timeline

X39 edited Steps To Reproduce. (Show Details)Jul 21 2014, 7:21 PM
X39 edited Additional Information. (Show Details)
X39 set Category to Scripting.
X39 set Reproducibility to Always.
X39 set Severity to None.
X39 set Resolution to Open.
X39 set Legacy ID to 3606456911.May 7 2016, 7:03 PM
Bohemia added a subscriber: AD2001.Jul 21 2014, 7:21 PM

is there a thread in the BI forum about it?
how do you call/execute the code? what is the call/execution tree? where is the code defined and where is the file to be found?

X39 added a subscriber: X39.May 7 2016, 7:03 PM
X39 added a comment.Jul 25 2014, 1:09 PM

there is a seperated BI forum thread about it:

now to how everything gets callen, where what is defined, etc.
but due the size of the projects i will stick to those section inbound in this problem (i will use github links so everyone can check the code without asking for it)

the functions are defined in 3 config.cpps:

registering of the button actions:

  1. (auto)
  2. (auto)


  1. (auto)


executing a button action

  1. initial key event registered by X39_XLib_KeyCatcher

2.3.1 depending on what button was pressed (and if the condition of the actions return true) different code registered in will be executed

for the working part it is more or less the same but that you register the actions then directly inside the debug menu so you only got the call (no seperated one)

Your code logic is somewhat complex and as such I may misunderstand your intent.

if(_x getVariable ['X39_MS2_var_UnitInitialized', false]) then

		_unit = _x;

} count attachedObjects X39_XLib_var_ActionDialog_Executor;

This design seems not safe/defensive programming.


My suggestion:

private ['_attachedObjects','_unitFound'];
_attachedObjects = attachedObjects X39_XLib_var_ActionDialog_Executor;//not necessary
_unitFound = false;
private ['_currentUnit'];
_currentUnit = _x;
if (!isNil '_currentUnit') then

		if (!isNull _currentUnit) then
			if(_x getVariable ['X39_MS2_var_UnitInitialized', false]) then
				_unitFound = true;

if (_unitFound) exitWith {_unit = _x;};
} forEach _attachedObjects;

If you can be sure _attachedObjects doesn't contain undefined units or removed units, the isNil and isNull check is obsolete.

Also you should not need to private _x as its a special variable as the engine sets the scope itself (at least thats the current knowledge and how Squint handles it).

Overall I don't get why you use the {} count array construct here.
If you want to catch the last unit in _attachedObjects that contains your variable, just ditch the exit condition of my design.

X39 added a comment.Jul 25 2014, 4:20 PM

changed the design many times trying while to fix that problem
the first attempt did not contained any variable as you can solve everything without a single one (attachedObjects will return an empty array if no object is attached)

im using count because it is faster (at least it was ... not sure about now but im used to this by today ^^ works the same way but without the _forEachIndex variable) but ... yeah
already tried it with foreach too

Also the code is working (just how/when/whatEvar it is registered using the registerAction function makes the difference)

X39 added a comment.Jul 25 2014, 11:34 PM

can be closed due the comment i received on reddit ...
buttonSetAction does not supports SQF? the fuck BI?

raising new bug soon for this

LouMontana closed this task as Resolved.Nov 6 2020, 3:54 PM
LouMontana updated the task description. (Show Details)
LouMontana edited Steps To Reproduce. (Show Details)
LouMontana edited Additional Information. (Show Details)
LouMontana set Operating System to Windows 7.