lawman_actual 24 Posted August 30, 2015 I have the following code snippets: _site13 = createLocation ["group_0", getMarkerPos "objmark13", 0, 0]; _site13 setName "site13"; AR_siteList = ["site1","site2","site3","site4","site5","site6","site7","site8","site9","site10","site11","site12","site13"]; fnc_triggerUnitsChanged = { _thisList = _this select 0; _thisListPrev = _this select 1; { //for each entering unit _newUnit = (_thisList - _thisListPrev) select 0; _siteList = nearestLocations [(getPos (_newUnit)), ["Area","group_0","Name"], 250]; _nearest = (_siteList select 0); _strNearest = (format ['"%1"',_nearest]); _objRef = AR_siteList find str _strNearest; _oldNumber = ticker select (_objRef); _side = side _newUnit; hint (format ["sites: %1 | StrNearest: %3 | ObjRef: %2", _siteList, _objRef, _strNearest]); if ((str _side) == "West") then {ticker set [(_objRef),(_oldNumber + 1)];} else {}; if ((str _side) == "East") then {ticker set [(_objRef),(_oldNumber - 1)];} else {}; //hint (format ["Influence: %1", ticker select (_myObj - 1)]); } forEach (_thisList - _thisListPrev); { //for each leaving unit _newUnit = (_thisListPrev - _thisList) select 0; _siteList = nearestLocations [(getPos (_newUnit)), ["Area","group_0","Name"], 250]; _nearest = (_siteList select 0); _objRef = AR_siteList find _nearest; _oldNumber = ticker select (_objRef); _side = side _newUnit; if ((str _side) == "West") then {ticker set [(_objRef),(_oldNumber + 1)];} else {}; if ((str _side) == "East") then {ticker set [(_objRef),(_oldNumber - 1)];} else {}; //hint (format ["Influence: %1", ticker select (_myObj - 1)]); } forEach (_thisListPrev - _thisList); }; However the following piece of code is producing a zero divisor error: _oldNumber = ticker select (_objRef); From hinting some of my variables I have determined that the following is returning objRef as -1 _siteList = nearestLocations [(getPos (_newUnit)), ["Area","group_0","Name"], 250]; _nearest = (_siteList select 0); _strNearest = (format ['"%1"',_nearest]); _objRef = AR_siteList find str _strNearest; From hinting I have also found that these are returned: _siteList = [site13] _nearest = site13 _strNearest = "site13" Given that _strNearest is being returned as "site13" I can't see why it won't return the correct position in the array AR_siteList. Especially since I tried manually overriding _strNearest to "site13" within the script and it all worked perfectly. Share this post Link to post Share on other sites
dreadedentity 278 Posted August 31, 2015 _objRef = AR_siteList find str _strNearest; It's probably because of the str command you use here, you're making a string into a string, which adds another set of double quotes around it, but it's impossible to tell without seeing what parameters you pass when you call the function. for a better visual, run these 2 commands with a short sleep in between hint "string"; //hint box shows string hint str "string"; //hint box shows "string" Share this post Link to post Share on other sites
lawman_actual 24 Posted August 31, 2015 Thanks entity, that probably explains it. I've actually changed how I do this now and the code is no longer in use - so I'm afraid I won't be checking at the moment! Share this post Link to post Share on other sites
lawman_actual 24 Posted August 31, 2015 I'm actually experiencing a similar problem now with finding the position of a marker that's stored in an array (this is all in the .init) At the start I define the following: markerlist = ["objmark1","objmark2","objmark3","objmark4","objmark5","objmark6","objmark7","objmark8","objmark9","objmark10","objmark11","objmark12","objmark13"]; But when I come to set a waypoint at the position of the marker, I found that the position was being returned as "any". Here's the code I was using: starthemtt = createVehicle ["B_MRAP_01_hmg_F", _startspawn, [], 0, "NONE"]; _newgroup = createGroup west; _dag1a1 = _newgroup createUnit ["B_Soldier_GL_F",[135,122,0],[],0.5,"CORPORAL"]; _dag1a1 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _dag1a2 = _newgroup createUnit ["B_soldier_AR_F",getMarkerPos "respawn1",[],0.5,"PRIVATE"]; _dag1a2 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _dag1a3 = _newgroup createUnit ["B_medic_F",getMarkerPos "respawn1",[],0.5,"PRIVATE"]; _dag1a3 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _dag1a4 = _newgroup createUnit ["B_soldier_LAT_F",getMarkerPos "respawn1",[],0.5,"PRIVATE"]; _dag1a4 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _old = +(assignmentus select numbhandle); _new = (_old + [_dag1a1,_dag1a2,_dag1a3,_dag1a4]); assignmentus set [numbhandle, _new]; hemttcrew = group _dag1a1; hemttcrew allowFleeing 0; starthemtt setDir ([(getPos starthemtt), (getMarkerPos newobj)] call BIS_fnc_dirTo); hemttcrew setCombatMode "YELLOW"; w_unload = hemttcrew addWaypoint [_startdeploy, 1]; w_unload setWaypointType "MOVE"; hemttcrew setCurrentWaypoint w_unload; if (chosenside == 1) then { potentialunits = potentialunits + units _newgroup; } else {}; w_unload setWaypointStatements ["true", " _myvehicle = (vehicle this); _myvehicle lock false; _aunit = (assignedDriver _myvehicle); _myDriver = [assignedDriver _myvehicle]; _myGunner = [assignedGunner _myvehicle]; _myCargo = assignedCargo _myvehicle; _incargo = []; _incargo = _incargo + _myDriver + _myGunner + _myCargo; _alphagroup = group (_incargo select 0); { doGetOut _x} foreach _incargo; {_x leaveVehicle _myvehicle} foreach _incargo; _endof = count assignmentus; for '_a' from 0 to _endof do { _ismine = (assignmentus select _a) find _aunit; if (_ismine > -1) then {_number = _a; objnumb = +_number;_a = _endof;} else {}; }; _thisobj = (markerlist select objnumb); objpos = getMarkerPos _thisobj; hint (format ['Obj: %1 Pos: %2', _thisobj, _objpos]); player sideChat (format ['%1', _markerlist]); if (player in _incargo) then {_thisobj setMarkerAlpha 1;} else {}; alphaobj = alphagroup addWaypoint [objpos, 25]; alphaobj setWaypointType 'SAD'; alphaobj setWaypointCombatMode 'RED'; alphagroup setCurrentWaypoint alphaobj;"]; _dag1a1 moveInDriver starthemtt; _dag1a2 moveInGunner starthemtt; _dag1a3 moveInCargo starthemtt; _dag1a4 moveInCargo starthemtt; A hint tells me that _thisobj is being returned as objmark13, but it's refusing to return the position of the marker (yes the marker definitely exists.) I have also tried doing a string of that so I am finding the pos of "objmark13". What's really confusing me about this one is that an identical example is working for a slightly different situation involving HEMTTs, Helos and APCs. Here's one example in which the marker pos is successfully found: _newgroup = createGroup west; _dag1a1 = _newgroup createUnit ["B_Soldier_GL_F",[135,122,0],[],0.5,"CORPORAL"]; _dag1a1 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _dag1a2 = _newgroup createUnit ["B_soldier_AR_F",getMarkerPos "respawn1",[],0.5,"PRIVATE"]; _dag1a2 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _dag1a3 = _newgroup createUnit ["B_medic_F",getMarkerPos "respawn1",[],0.5,"PRIVATE"]; _dag1a3 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _dag1a4 = _newgroup createUnit ["B_soldier_LAT_F",getMarkerPos "respawn1",[],0.5,"PRIVATE"]; _dag1a4 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _newgroup2 = createGroup west; _dag1b1 = _newgroup2 createUnit ["B_Soldier_GL_F",[135,122,0],[],0.5,"CORPORAL"]; _dag1b1 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _dag1b2 = _newgroup2 createUnit ["B_soldier_AR_F",getMarkerPos "respawn1",[],0.5,"PRIVATE"]; _dag1b2 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _dag1b3 = _newgroup2 createUnit ["B_medic_F",getMarkerPos "respawn1",[],0.5,"PRIVATE"]; _dag1b3 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _dag1b4 = _newgroup2 createUnit ["B_soldier_LAT_F",getMarkerPos "respawn1",[],0.5,"PRIVATE"]; _dag1b4 addEventHandler ["killed", {null = call {_this execVM "respawni.sqf";}}]; _old = +(assignmentus select numbhandle); _new = (_old + [_dag1a1,_dag1a2,_dag1a3,_dag1a4,_dag1b1,_dag1b2,_dag1b3,_dag1b4]); assignmentus set [numbhandle, +_new]; if (chosenside == 1) then { potentialunits = potentialunits + units _newgroup; potentialunits = potentialunits + units _newgroup2; } else {}; w_unload setWaypointStatements ["true", " _myvehicle = vehicle (thislist select 0); _myvehicle lock false; _increw = (assignedDriver _myvehicle); _incargo = (assignedCargo _myvehicle); { doGetOut _x} foreach _incargo; {_x leaveVehicle _myvehicle} foreach _incargo; _aunit = _incargo call BIS_fnc_selectRandom; _endof = count assignmentus; for '_a' from 0 to _endof do { _ismine = (assignmentus select _a) find _aunit; if (_ismine > -1) then {_number = _a; objnumb = +_number;_a = _endof;} else {}; }; _thisobj = markerlist select objnumb; objpos = getMarkerPos _thisobj; player sideChat (format ['Obj: %1 Pos: %2', _thisobj, _objpos]); if (player in _incargo) then {_thisobj setMarkerAlpha 1;} else {}; _aunit = _incargo call BIS_fnc_selectRandom; alphagroup = (group _aunit); _incargo = _incargo - (units alphagroup); _aunit = _incargo call BIS_fnc_selectRandom; bravogroup = (group _aunit); _incargo = _incargo - units bravogroup; alphaobj = alphagroup addWaypoint [objpos, 25]; alphaobj setWaypointType 'SAD'; alphaobj setWaypointCombatMode 'RED'; alphagroup setCurrentWaypoint alphaobj; bravoobj = bravogroup addWaypoint [objpos, 25]; bravoobj setWaypointType 'SAD'; bravoobj setWaypointCombatMode 'RED'; bravogroup setCurrentWaypoint bravoobj; _rtbpos = getMarkerPos 'usdeploymark'; _rtb = (group _increw) addWaypoint [_rtbpos, 50]; _rtb setWaypointType 'MOVE'; _rtb setWaypointStatements ['true', '{_myvehicle deleteVehicleCrew _x} forEach crew _myvehicle; deleteVehicle myvehicle;'];"]; _dag1a1 moveInCargo starthemtt; _dag1a2 moveInCargo starthemtt; _dag1a3 moveInCargo starthemtt; _dag1a4 moveInCargo starthemtt; _dag1b1 moveInCargo starthemtt; _dag1b2 moveInCargo starthemtt; _dag1b3 moveInCargo starthemtt; _dag1b4 moveInCargo starthemtt; It's really stumping me how the same code is finding the markerPos in one example and not in the other. I've tried copying and pasting bits of code to make sure they're the same and they should be. Share this post Link to post Share on other sites
lawman_actual 24 Posted August 31, 2015 Hm. It would seem that in both cases the position is being returned as "any" when hinted or sidechatted. And yet with the second example the waypoint is correctly set and in the first it is not. Edit: I think I've spotted the problem. Some of the _objpos have been mistyped as objpos and I was struggling to spot it without the formatting (it was all green as part of the waypoint statement). Share this post Link to post Share on other sites