Jump to content
Sign in to follow this  
GregRUS

Error in nearestobjects "select 1"

Recommended Posts

Hello everyone!

I have a problem in my script with "nearestobject" command;

I used -showscripterrors and got:

'...cts [getpos player, ["LandVehicle"], 5] |#|select 1);_vcl1 distance _vcl2 <=10 and...'
Error

Whole string in script file is:

_player addaction["Attach Vehicle","attact.sqf",["attach", "var1", 2,"tow"],1,false,true,"",'_vcl1 = (nearestobjects [getpos player, ["LandVehicle"], 5] select 0);_vcl2 = (nearestobjects [getpos player, ["LandVehicle"], 5] select 1);_vcl1 distance _vcl2 <= 10 and (((typeof _vcl1 in towarray and !(typeof _vcl2 in towarray)) or !((typeof _vcl1 in towarray) and typeof _vcl2 in towarray))) and (player == vehicle player)'];

Actually it works anyway but I dont want to leave any errors in my scripts.

Hope the answer will be simple xD

UPD: Of course there was no vehicles nearby.

Also tried to put that string before:

if (isnil (nearestobjects [getpos player, ["LandVehicle"], 5] select 1))exitwith {};

... didnt helped ;(

Edited by GregRUS
UPD

Share this post


Link to post
Share on other sites

Hi GregRus!

Are you shure, you want the 2nd vehicle you search for ?

You use "select 1". This is the second one.

To select the first one, you need "select 0".

I think you want to leave, if there is no second vehicle in the list.

So try the "count" statement:

if ( count (nearestobjects [getpos player, ["LandVehicle"], 5])  < 1) exitwith {};

If you want to leave, if there is NO vehicle found:

if ( count (nearestobjects [getpos player, ["LandVehicle"], 5])  = 0) exitwith {};

Hope this will help you.

Share this post


Link to post
Share on other sites
Hi GregRus!

Are you shure, you want the 2nd vehicle you search for ?

You use "select 1". This is the second one.

To select the first one, you need "select 0".

I think you want to leave, if there is no second vehicle in the list.

So try the "count" statement:

if ( count (nearestobjects [getpos player, ["LandVehicle"], 5])  < 1) exitwith {};

If you want to leave, if there is NO vehicle found:

if ( count (nearestobjects [getpos player, ["LandVehicle"], 5])  = 0) exitwith {};

Hope this will help you.

Thank you very much!! It helped! :yay:

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  

×