saetheer 9 Posted April 19, 2014 (edited) Hello, Can anyone explain to me why this doesn't work? It fails when I preview mission. All I want, is to mark certain units defined in the UnitArray UnitArray which is defined this way { // if (isFormationLeader _x) then { if ((side _x) == Resistance) then { _name = groupID (group _x); _rank = rank _x; _rankIcon = [_rank,"texture"] call BIS_fnc_rankParams; _tempArray = [_x,_rankIcon,_rank,_name]; UnitArrayset [count UnitArray,_tempArray ]; // Contains units with [[unit,RankIcon,Rank,GroupID]] }; // }; } forEach allUnits; In my module I've defined function = "fn_test"; fn_test.sqf { // foreach unit defined in UnitArray // [[unit,RankIcon,Rank,GroupID]] _UnitArray = _x select 0; _unit = _UnitArray select 0; _texture = _UnitArray select 1; _rank = _UnitArray select 2; _text = _UnitArray select 3; _pos = getPosATL _unit; ((findDisplay 12) displayCtrl 51) drawIcon [_texture,"ColorGUER",_pos, 1, 1, 0, _text, 0, 0.035,"TahomaB","Left"]; } forEach UnitArray; MapDrawEH = ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw", {[] call DrawLeaderIcon}]; Clearly I'm missing something, appreciate any help given - Thanks Edited April 20, 2014 by Saetheer Share this post Link to post Share on other sites
das attorney 858 Posted April 19, 2014 Hi, Just a few things with your first script: You should define UnitArray = []; before the forEach Statement. Unless you have defined it in code which you didn't post then it is an undefined variable. You may also want to add in a check for dead units, so you don't add them to the arrays if they die while the script is running. Also, not sure if it's the formatting, but this statement will error out as it's written in your post: UnitArrayset [count UnitArray,_tempArray ]; Should be: UnitArray set [count UnitArray,_tempArray ]; Haven't looked at the rest of the scripts but give those a go and see how you get on. And also post up your .rpt as the answers to these questions are usually in there anyway. :) Regards DA Share this post Link to post Share on other sites
saetheer 9 Posted April 20, 2014 Thanks. I have actually done your suggestion mentioned. As well the space on 'UnitArray set....' However, it seems lite UnitArray set [count UnitArray,_tempArray ]; uses the -1 index or something, which messes something up What I initially want is to have arrays within arrays. // ... some code gathers info and ends up with _tempArray = [_x,_rankIcon,_rank,_name]; // Adds all groupleaders into UnitArray UnitArray set [count UnitArray, _tempArray ]; I want UnitArray to look like this [ [unit1,"path to texture","PRIVATE","ALPHA"], [unit2,"path to texture","PRIVATE","Bravo"] ] As you can see adove is an example on what I want the array to look like, arrays within a array. Since I'm accessing this UnitArray Later { _unit = _x select 0; _texture = _x select 1; _rank = _x select 2; _text = _x select 3; // Code to proccess and give access to certain things } foreach UnitArray; Share this post Link to post Share on other sites
saetheer 9 Posted April 20, 2014 Small update: I've run som debugs and it fails at this: Error 0 elements provided, 4 expected... Share this post Link to post Share on other sites
das attorney 858 Posted April 20, 2014 On your fn_test, you have defined this: _UnitArray = _x select 0; { // foreach unit defined in UnitArray // [[unit,RankIcon,Rank,GroupID]] _UnitArray = _x select 0; _unit = _UnitArray select 0; _texture = _UnitArray select 1; _rank = _UnitArray select 2; _text = _UnitArray select 3; _pos = getPosATL _unit; ((findDisplay 12) displayCtrl 51) drawIcon [_texture,"ColorGUER",_pos, 1, 1, 0, _text, 0, 0.035,"TahomaB","Left"]; } forEach UnitArray; But I think it should be just: _UnitArray = _x; { // foreach unit defined in UnitArray // [[unit,RankIcon,Rank,GroupID]] _UnitArray = _x; _unit = _UnitArray select 0; _texture = _UnitArray select 1; _rank = _UnitArray select 2; _text = _UnitArray select 3; _pos = getPosATL _unit; ((findDisplay 12) displayCtrl 51) drawIcon [_texture,"ColorGUER",_pos, 1, 1, 0, _text, 0, 0.035,"TahomaB","Left"]; } forEach UnitArray; See if that helps. Share this post Link to post Share on other sites
saetheer 9 Posted April 20, 2014 Thanks but that didnt work either I've been testing things out and for me, this should be the solution, however it returns the error '0 elements provided, 4 expected..' again. Its only when I open the map, so the eventhandler fies only in the map, but it complains about the drawIcon it seems. I've tried to work with this instead: fn_test ((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw", " _index = -1; for '_i' from 0 to ( count LAMBS_Leader ) -1 do { _index = _index + 1; _pos = getPosATL ((UnitArray select _i) select 0); _texture = ((UnitArray select _i) select 1); _rank = ((UnitArray select _i) select 2); _text = ((UnitArray select _i) select 3); ((findDisplay 12) displayCtrl 51) drawIcon [_texture,'ColorGUER',_pos, 1, 1, 0, _text, 1, 0.03,'TahomaB','left']; };"]; Suggestion? Share this post Link to post Share on other sites
das attorney 858 Posted April 20, 2014 I was just reading up on the drawIcon wiki page, I don't think it will accept variables passed to it (even if from a global var), so you may need to use global ones directly in the drawIcon args instead. I'm trapped at work today so I can't check for you but if you haven't got it sorted later I can check at home. BTW - have you checked the contents of unitArray with diag_log or similar to make sure the info is saved in the first place? Share this post Link to post Share on other sites
saetheer 9 Posted April 20, 2014 yeah, the arrays fills correcly with the units I want. However still "0 elements provided, 4 expected" Share this post Link to post Share on other sites
saetheer 9 Posted April 21, 2014 In my config.ccp I've the following code class Extended_PostInit_EventHandlers { class PREFIX { serverInit = QUOTE(call COMPILE_FILE2(\LAMBS\server_init.sqf)); playerInit = QUOTE(call COMPILE_FILE2(\LAMBS\player_init.sqf)); }; }; server_init.sqf [] spawn { waituntil {time > 0}; sleep .1; while {true} do { GREEN_Leader = []; { if ((side _x) == Resistance) then { _grpID = groupID (group _x); _rank = rank _x; _tempArray = [_x,"\A3\ui_f\data\map\markers\nato\n_inf.paa",_grpID,_rank]; GREEN_Leader set [count GREEN_Leader, _tempArray]; }; } forEach allUnits; publicVariable "GREEN_Leader"; sleep 20; }; }; player_init.sqf TTDrawGREEN = { _return = true; _display = (findDisplay 12); _cntrlScreen = _display displayCtrl 51; _index = -1; for "_i" from 0 to ( count _cfgVehicles ) -1 do { _obj = (GREEN_Leader select _i) select 0; _texture = (GREEN_Leader select _i) select 1; _text = (GREEN_Leader select _i) select 2; _rank = (GREEN_Leader select _i) select 3; _pos = getPosATL _obj; _cntrlScreen drawIcon [_texture,[1,1,1,1],_pos, 1, 1, 0, _text, 0, 0.035,"TahomaB"]; _index = _index + 1; }; _return; }; and my fn_test.sqf - Called from the module findDisplay 12 displayCtrl 51 ctrlAddEventHandler ["Draw", { [] call TTDrawGREEN; }]; I've tried using global variables and see All my debugs says that the array is filled correctly. However I still get the "0 elements provided, 4 expected" error... Share this post Link to post Share on other sites
saetheer 9 Posted April 21, 2014 So while I'm in editor: Pasting this into the debug console it works perfect. findDisplay 12 displayCtrl 51 ctrlAddEventHandler ["Draw", { _display = (findDisplay 12); _cntrlScreen = _display displayCtrl 51; { if ((side _x) == Resistance) then { _pos = getPosATL _x; _text = groupID (group _x); _rank = rank _x; _texture = "\LAMBS\Img\n_inf.paa"; _cntrlScreen drawIcon [_texture,[0,0.5,0,1],_pos, 24, 24, 0, _text, 0, 0.035,"TahomaB"]; }; } forEach allUnits; }]; The maps is nicly populated with some icons that reflects the position on resistance units. However the same code in fn_test gives error. What am I missing? Share this post Link to post Share on other sites
saetheer 9 Posted April 23, 2014 So, how stupid is it possible to be... In the module, I had defined function = "fn_Teamtracker"; . Apparently, this doesn't referance the function I made, which gave some errors. So basically, disregard above, as when I defined the function as function = "LAMBS_fnc_Teamtracker"; it executed in editor without 'cheating' As of now, This only works in editor and not in dedicated. Code in fn_Teamtracker.sqf (LAMBS_fnc_Teamtracker) waituntil {time > 30}; findDisplay 12 displayCtrl 51 ctrlAddEventHandler ["Draw", { _display = (findDisplay 12); _cntrlScreen = _display displayCtrl 51; { if ((side _x) == resistance) then { _pos = getPosATL _x; _text = groupID (group _x); _rank = rank _x; _texture = "\A3\ui_f\data\map\markers\nato\n_inf.paa"; if (leader (group _x) == _x) then { _cntrlScreen drawIcon [_texture,[0,0.5,0,1],_pos, 24, 24, 0, _text, 0, 0.035,"TahomaB"]; }; }; } forEach allUnits; }]; Anyone knows how I could make this globally? Given that the code is executed by the module Share this post Link to post Share on other sites