Jump to content
RicardoLew

Help with position of array elements

Recommended Posts

I want to make a simple script that gives me the position of each element of an array that i created.

That's all i got so far, but taking the position of each object is not working for me.

 

 _array = [];

_objs = player nearObjects ["Land_cargo40_blue_f", 30];

 _array pushback _objs;

 

I tried to make "getpos forEach _objs" but it didnt work.

Maybe someone can help me?

Thanks!

Share this post


Link to post
Share on other sites
{
	hintSilent format ["> %1 (%2)", _x, (_forEachIndex)];
} forEach _array;

Depending on what you are doing, you may not need to store (pushBack) nearObjects to an array.

{
	_objectPos = getPos _x;
	hintSilent format ["> %1 (%2)", _x, (_forEachIndex)];
	systemChat format ["Object position: %1", _objectPos];
	player setPos _objectPos;
} forEach player nearObjects ["Land_cargo40_blue_f", 30];

None tested, it is very late (or early) here, need coffee...

  • Like 2

Share this post


Link to post
Share on other sites

Got plenty of coffee flowing through my veins so here goes:

 

2 hours ago, RicardoLew said:

 _array = [];

_objs = player nearObjects ["Land_cargo40_blue_f", 30];

 _array pushback _objs;

 

Use -showscripterrors start parameter and utilize the debug console, which is capable of monitoring certain variables and what they're holding.

 

NearObjects returns an array, so all you're doing is pushing an array into an array.

You can use apply to change the contents of an array, like this:

_objs = player nearObjects ["Land_cargo40_blue_f", 30]; 
_positions = _objs apply {getpos _x};

Cheers

  • Like 4

Share this post


Link to post
Share on other sites

Thanks for the help! I think some more practice is needed if i want to be good in this coding world!

Share this post


Link to post
Share on other sites

or even _obs apply [_x, getpos _x];

so you can work with the couple (object,position).

  • Like 1

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

×