jacmac 2 Posted October 11, 2013 In the scriptlet below I have _pos = getMarkerPos "veh"); Since I would like to add event handlers for an unknown number of markers, I need something like: _pos = getMarkerPos _marker); The problem is that the eventhandler code isn't executed until the event takes place. So I would need to generate the code using Call Compile Format such that _pos = getMarkerPos "veh"); is dynamically generated. If I attempt to encapsulate the entire function below in a Call Compile Format Replacing "veh" with %1, ARMA crashes as soon as the event handler would take place. addMissionEventHandler ["Draw3D", { _pos = getMarkerPos "veh"); _distp = player distance _pos; if (_distp < 500 and (vehicle player isKindOf "LandVehicle")) then { _scale = 0.0251 - (_distp / 20000); _pos set [2, 2 + (_distp * 0.05)]; _alpha = _distp / 500; _texture = format ["#(rgb,1,1,1)color(0.5,0.5,0.5,%1)", _alpha]; if (_distp < 250) then { _alpha = 1.001 - (_distp / 500); }; _color = [0.85,0.65,0.13,_alpha]; drawIcon3D [_texture, _color, _pos, 0.5, 0.5, 0, "Ground vehicle Service", 1, _scale, "TahomaB"]; }; }]; Share this post Link to post Share on other sites
xyberviri 1 Posted October 11, 2013 use format instead _somevalue=1; _marker= format["veh%1",_somevalue]; //this is == to "veh1" _pos = getMarkerPos _marker; if(_pos select 0 == 0) exitWith{}; //almost no marker is ever created at 0,0,0 //if we get this far we have a valid marker. Share this post Link to post Share on other sites
jacmac 2 Posted October 12, 2013 I tried something like this before, what is produced is an endless series of "_mkr=any" in systemChat. I believe the code in addMissionEventHandler is not executed at compile time, it is executed as part of the event. Assuming this is true, the variable below named "_marker" is undefined. What I need to do is change the event code so that _marker is replaced with the name before the event. The only way I know of to do this is with something like call compile format. addMissionEventHandler ["Draw3D", { _mkr = format["%1", _marker]; systemChat ("_mkr=" + _mkr); _pos = getMarkerPos _mkr; _distp = player distance _pos; if (_distp < 500 and (vehicle player isKindOf "LandVehicle")) then { _scale = 0.0251 - (_distp / 20000); _pos set [2, 2 + (_distp * 0.05)]; _alpha = _distp / 500; _texture = format ["#(rgb,1,1,1)color(0.5,0.5,0.5,%1)", _alpha]; if (_distp < 250) then { _alpha = 1.001 - (_distp / 500); }; _color = [0.85,0.65,0.13,_alpha]; drawIcon3D [_texture, _color, _pos, 0.5, 0.5, 0, "Ground Vehicle Service", 1, _scale, "TahomaB"]; }; }]; Here is how I'm thinking it should work: call compile format ["addMissionEventHandler [""Draw3D"", {_pos = getMarkerPos ""%1""; _distp = player distance _pos; if (_distp < 500 and (vehicle player isKindOf ""LandVehicle"")) then {_scale = 0.0251 - (_distp / 20000); _pos set [2, 2 + (_distp * 0.05)]; _alpha = _distp / 500; _texture = format [""#(rgb,1,1,1)color(0.5,0.5,0.5,%1)"", _alpha]; if (_distp < 250) then { _alpha = 1.001 - (_distp / 500);}; _color = [0.85,0.65,0.13,_alpha]; drawIcon3D [_texture, _color, _pos, 0.5, 0.5, 0, ""Ground Vehicle Service"", 1, _scale, ""TahomaB""];};}];", _marker]; Here, %1 is replaced with the name before the event would supposedly take place, but ARMA crashes immediately after I enter a vehicle that satisfies isKindOf ""LandVehicle"". I maybe getting close, but I'm not sure what is causing the crash here. Share this post Link to post Share on other sites
Larrow 2801 Posted October 12, 2013 This works for me.. markername = "mrk1"; call compile format ["addMissionEventHandler [""Draw3D"", { _pos = getMarkerPos ""%1""; _distp = player distance _pos; if (_distp < 500 and (vehicle player isKindOf ""LandVehicle"")) then { _scale = 0.0251 - (_distp / 20000); _pos set [2, 2 + (_distp * 0.05)]; _alpha = _distp / 500; _texture = format [""#(rgb,1,1,1)color(0.5,0.5,0.5,%2)"", _alpha]; if (_distp < 250) then { _alpha = 1.001 - (_distp / 500); }; _color = [0.85,0.65,0.13,_alpha]; drawIcon3D [_texture, _color, _pos, 0.5, 0.5, 0, ""Ground Vehicle Service"", 1, _scale, ""TahomaB""]; }; }];", markername, "%1"]; As you have a format inside a format the %1 inside the _texture line was getting replaced with the marker name by the outer format. I have changed this to %2 and added "%1" to the second param of the outter format. When the inner format command happens it is now %1 and formats properly. Share this post Link to post Share on other sites
jacmac 2 Posted October 12, 2013 Good God, I didn't even consider the inner format as a potential problem. I'll try this out right away, thanks for the help! Share this post Link to post Share on other sites