The_Oakster 0 Posted July 13, 2006 Hello, I have the following code in a script: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_veh = ["SKODA","SKODARED","SKODAGREEN","SKODABLUE","TruckV3SCivil"] car = nearestobject[ch2,"_veh"] ch1 domove getpos car ch2 domove getpos car But it doesnt work, however if I do this then it does: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">car = nearestobject[ch2,"skodared"] ch1 domove getpos car ch2 domove getpos car Is there something wrong with how I have defined the array, or do arrays not work for nearestobject? Ben Share this post Link to post Share on other sites
Metal Heart 0 Posted July 13, 2006 "_veh" != _veh Quotation marks are used to identify strings like: player sidechat "Hello world!"; Share this post Link to post Share on other sites
The_Oakster 0 Posted July 13, 2006 If I change it to: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">car = nearestobject[ch2,_veh] I get an error message: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">'car = nearestobject[ch2,_veh|#|]': error type object, expected number Share this post Link to post Share on other sites
suma 8 Posted July 13, 2006 Arrays do not work for nearestObject. There is even nothing in the command references which could create an impression they do. Share this post Link to post Share on other sites
The_Oakster 0 Posted July 13, 2006 Arrays do not work for nearestObject. There is even nothing in the command references which could create an impression they do. I noticed that but I just wondered if it would, I am just getting to grips with things and I was just wondering and playing about Ben Share this post Link to post Share on other sites
Guest [B.B.S.] T_D Posted July 13, 2006 hardrock made a function for that, fNearestObjectList: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_p","_o","_a","_d","_di","_no","_r"]; _o=_this select 0; _a=_this select 1; _d=200; _r=objNull; _p=if (_o in [_o]) then {getpos _o} else {_o}; { _no=nearestObject[_p,_x]; _di=([_p,getpos _no] call fVectorTo) call fVectorLength; if(_di<_d)then { _r=_no; _d=_di; }; } forEach _a; _r This function returns the nearest Object, but you can take a list of different objects as a parameter: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_veh = ["SKODA","SKODARED","SKODAGREEN","SKODABLUE","TruckV3SCivil"] fNearestObjectList = loadFile "fNearestObjectList.sqf" car = [ch2, _veh] call fNearestObjectList But this function need two other ones: fVectorTo.sqf <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> private["_p1","_p2"]; _p1=_this select 0; _p2=_this select 1; [(_p2 select 0)-(_p1 select 0), (_p2 select 1)-(_p1 select 1), (_p2 select 2)-(_p1 select 2)] [\CODE] and fVectorLength.sqf sqrt( ((_this select 0)^2)+((_this select 1)^2)+((_this select 2)^2) )These have to be initialized, too, so your final script would look like:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>[b]Code Sample[/b] </td></tr><tr><td id="CODE">_veh = ["SKODA","SKODARED","SKODAGREEN","SKODABLUE","TruckV3SCivil"]fVectorLength = loadFile "fVectorLength.sqf"fVectorTo = loadFile "fVectorTo.sqf"fNearestObjectList = loadFile "fNearestObjectList.sqf"car = [ch2, _veh] call fNearestObjectList Share this post Link to post Share on other sites