Page MenuHomeFeedback Tracker

buttonSetAction sometimes fucks around with the script code
Closed, ResolvedPublic

Description

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;
		};
		false

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

		detach _unit;
		_unit playMove 'AinjPpneMstpSnonWrflDb_release';

}
else
{

		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)

Details

Legacy ID
3606456911
Severity
None
Resolution
Open
Reproducibility
Always
Operating System
Windows 7
Category
Scripting
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)
https://github.com/X39/XMS2/tree/dev_X39
https://github.com/X39/XLib

my steamaccount for direct chat if required
http://steamcommunity.com/id/x39

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

yep
there is a seperated BI forum thread about it:
http://forums.bistudio.com/showthread.php?180959-unexpected-script-runtime-issue-when-putting-much-code-into-variables-by-a-seperated

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:
https://github.com/X39/XLib/blob/master/X39_XLib_KeyCatcher/config.cpp
https://github.com/X39/XLib/blob/master/X39_XLib_ActionDialog/config.cpp
https://github.com/X39/XMS2/blob/dev_X39/X39_MS2_Scripting/config.cpp

registering of the button actions:

  1. (auto) https://github.com/X39/XLib/blob/master/X39_XLib_KeyCatcher/Functions/init.sqf
  2. (auto) https://github.com/X39/XLib/blob/master/X39_XLib_ActionDialog/Functions/init.sqf

2.1 https://github.com/X39/XLib/blob/master/X39_XLib_KeyCatcher/Functions/registerKey.sqf

  1. (auto) https://github.com/X39/XMS2/blob/dev_X39/X39_MS2_Scripting/Functions/initMod.sqf

3.1 https://github.com/X39/XMS2/blob/dev_X39/X39_MS2_Scripting/Functions/initModHelpers/addInteractionMenuEntries.sqf
3.1.1 https://github.com/X39/XLib/blob/master/X39_XLib_ActionDialog/Functions/registerAction.sqf

executing a button action

  1. initial key event registered by X39_XLib_KeyCatcher
  2. https://github.com/X39/XLib/blob/master/X39_XLib_KeyCatcher/Functions/cb_KeyDown.sqf

2.1 https://github.com/X39/XLib/blob/master/X39_XLib_ActionDialog/Functions/createDialog.sqf
2.2 https://github.com/X39/XLib/blob/master/X39_XLib_ActionDialog/Functions/initSystemVariables.sqf
2.3 https://github.com/X39/XLib/blob/master/X39_XLib_ActionDialog/Functions/initActions.sqf
2.3.1 depending on what button was pressed (and if the condition of the actions return true) different code registered in https://github.com/X39/XMS2/blob/dev_X39/X39_MS2_Scripting/Functions/initModHelpers/addInteractionMenuEntries.sqf 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 https://github.com/X39/XLib/blob/master/X39_XLib_ActionDialog/Functions/registerAction.sqf 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;

};
false
} 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.
Ref: https://community.bistudio.com/wiki/count

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

-----edit-----
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 ...
http://www.reddit.com/r/arma/comments/2bn5gu/sqf_i_surrender/
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.