Jump to content
Sertica

Variable Visibility Problem

Recommended Posts

To show my test mission debug info window I have code like this:

infoInit = {
	waitUntil {!isNull findDisplay 46};
	disableSerialization;
	_ctrl = ((findDisplay 46) displayCtrl 9999);
	if (!isNull ctrl) then {ctrlDelete ctrl};
	_ctrl = (findDisplay 46) ctrlCreate ["RscStructuredText", 9999];
	_ctrl ctrlSetPosition [0, 0, 0.25, 5]; 
	_ctrl ctrlSetTextColor [0.5, 0, 0.5, 1];
	_ctrl ctrlSetbackgroundColor [0.8, 0.8, 0.8, 0.1];
	_ctrl ctrlCommit 0;
	_strings = [];
	
	info = {
		_strings pushBack ("Visible Quantity: "+(str uavVisEnemyCount)+"<br/>");
		_strings pushback ("UAV Vision Distance: "+(str uavVisDistance)+"<br/>");
		_ctrl ctrlSetStructuredText parsetext (_strings joinString "");
		_ctrl ctrlSetPosition [-0.6, 0.0, ctrlTextWidth _ctrl, ctrlTextHeight _ctrl];
		_ctrl ctrlCommit 0;
		_strings resize 0;
	};
};

info is supposed to be called to update the display just before uavVisEnemyCount is reset at the end of the cycle.  But the local variable defs in infoInit are apparently invisible to info despite it being nested in that scope.  On the other hand I get a pop-up complaining about serialization if I make them global even with disableSerialization in both.  I don't understand this serialization issue with widgets.  The way I was getting the info displayed before was checking the values constantly in a loop, which is a bad hack to get around this.

Share this post


Link to post
Share on other sites

At least

if (!isNull _ctrl) then {ctrlDelete _ctrl}; instead of if (!isNull ctrl) then {ctrlDelete ctrl};

 

info is a code. Nested or not, the inner params must be defined if passed from outer scope.

There is no added value to embed this code inside the infoInit.

So, keep in mind the working syntax:

[_strings,_ctrl] call info;

and

info = { params ["_strings","_ctrl"]; ..... };

Share this post


Link to post
Share on other sites
4 hours ago, pierremgi said:

At least

if (!isNull _ctrl) then {ctrlDelete _ctrl}; instead of if (!isNull ctrl) then {ctrlDelete ctrl};

That is just a typo from when I changed it back from global.

 

4 hours ago, pierremgi said:

info is a code. Nested or not, the inner params must be defined if passed from outer scope.

There is no added value to embed this code inside the infoInit.

So, keep in mind the working syntax:

[_strings,_ctrl] call info; 

and

info = { params ["_strings","_ctrl"]; ..... }; 

They are still not visible where info is called.  I moved info outside of infoInit, changed all variables to global again and now it is not giving the serialization error.  I've never coded without class and interface, so I guess the general practice with sqf is to use global variable for everything except the temporary variables in functions.  There is no encapsulation.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×