Jump to content
Sign in to follow this  
igneous01

Format encased strings?

Recommended Posts

I've run into a bit of an issue using format, no matter how many times I try it, I cannot get some code to compile with strings encased inside the string code. Basically I am trying to compile some code that will add a unit portrait and name to a KIA list box in my custom menu. I am using an eventhandler to trigger this:

// Add killed EH to all platoon units
{_EH = _x addEventHandler ["killed", 
{
	private ["_unit", "_control"];
	_unit = _this select 0;
	_control = 901; // listbox control idc
	private ["_name", "_pic", "_string"];
	call compile format ["_name = %1", name _unit];
	call compile format ["_pic = %1", _unit getVariable "IdentityPicture"];
	_string = compile (format ["_ind = lbAdd [%1, %2]; lbSetPicture [%1, _ind, %3]", _control, _name, _pic]);
	GPKILLED = GPKILLED + [_string];
}];
} foreach GPUNITS;

ive tried with and without compiling the name and picture variables, but it still wont do it, and it errors saying missing bracket (because quotations broke off)

This is where I will run the compiled array everytime I open up the KIA list box:

waitUntil {
private ["_index"];
_index = lbCurSel _comboCtrl;
switch (_index) do
{
   		case 0:
   		{
    		{ctrlSetText [_x, ""]} foreach [201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212];
    		_nul = [sQUAD1 select 0, SQUAD1 select 1, SQUAD1 select 2] call Organizer_Team;
           };
           case 1:
           {
            {ctrlSetText [_x, ""]} foreach [201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212];
            _nul = [sQUAD2 select 0, SQUAD2 select 1, SQUAD2 select 2] call Organizer_Team;
      };
      case 2:
           {
	      {ctrlSetText [_x, ""]} foreach [201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212];            
            _nul = [sQUAD3 select 0, SQUAD3 select 1, SQUAD3 select 2] call Organizer_Team;
      };
      case 5:
      {
      	[color="Red"]ctrlShow [_lbKIA, true];
		ctrlEnable [_lbKIA, true];		      
		lbClear _lbKIA;
	      {call _x} foreach GPKILLED;[/color]
	};
      default
   		{
      	{ctrlSetText [_x, ""]} foreach [201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212];
       	};

  	};
  	waitUntil {private ["_temp"]; _temp = lbCurSel _comboCtrl; _temp != _index};

     if (ctrlVisible _lbKIA) then {
      ctrlShow [_lbKIA, false];
	ctrlEnable [_lbKIA, false];
};
sleep 0.10;
GP_MENUSELECTION != -1
};

Is where I am running it, I cant figure out any other way to reload all the KIA units in the list because once the menu closes, you cannot update the list anymore.

any ideas?

Share this post


Link to post
Share on other sites

call compile format ["_name = %1", name _unit];

call compile format ["_pic = %1", _unit getVariable "IdentityPicture"];

have you tried

_name = name _unit; // as its already a string

_pic = str(_unit getVariable "IdentityPicture"); str() converts anything to a string so if "IdentityPicture value" is a string you will end up with ""IdentityPicture- value"";

so

you may just need to do

_pic = _unit getVariable "IdentityPicture";

also do you have GPKILLED = [];

somewhere outside the script like in the init.sqf

Edited by Zonekiller

Share this post


Link to post
Share on other sites

I tried it as you suggested before, and it did not work, so then I tried to see what would happen when I used str to convert it to a string again, and sure enough, it worked ^^

here is the fixed code:

// Add killed EH to all platoon units
{_EH = _x addEventHandler ["killed", 
{
	private ["_unit", "_control"];
	_unit = _this select 0;
	_control = 901; // listbox control idc
	_unit removeEventHandler ["killed", 0];
	private ["_name", "_pic", "_string"];
	_name = name _unit;
	_pic = _unit getVariable "IdentityPicture";
	_string = compile (format ["_ind = lbAdd [%1, %2]; lbSetPicture [%1, _ind, %3]",[color="Red"] _control, str _name, str _pic[/color]]);
	GPKILLED = GPKILLED + [_string];
}];
} foreach GPUNITS;

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
Sign in to follow this  

×