Jump to content
Sign in to follow this  
Luft08

Need help understanding code

Recommended Posts

I took a piece of code that Grumpy Old Man wrote and modified it to do what I needed. The modified code does indeed work. Now I would like to know why.

 

Here is my modified code:

{
	private _referencePos = _x;
	private _sortedByRange = [allMapMarkers,[],{_referencePos distanceSqr getMarkerPos _x},"ASCEND", {(_x select [0,3] == "wp_")}] call BIS_fnc_sortBy;
	_sortedByRange params ["_nearestMarker"];
	private _townNameArray = _nearestMarker splitString "_";
	private _wpPrefix = "wp_" + (_townNameArray select 1) + "_";
	
	hint _wpPrefix;
} forEach activePlayerArray;

 I wanted the code to get the closest marker that name begins with "wp_" which it does. I just don't understand this line:

private _sortedByRange = [allMapMarkers,[],{_referencePos distanceSqr getMarkerPos _x},"ASCEND", {(_x select [0,3] == "wp_")}] call BIS_fnc_sortBy;

In particular I don't understand where the "magic variable" _x is getting its data. It's not from the forEach which would return a player. I think its from the allMapMarkers but I don't know why as I don't see a looping structure.

Share this post


Link to post
Share on other sites

It's from allMapMarkers, and not from the forEach.  It's from an apply in BIS_fnc_sortBy.

 

Using the debug console function viewer, you should be able to review the function itself (falls under category Arrays).

  • Like 1

Share this post


Link to post
Share on other sites

Thanks, I didn't know anything about "apply." I guess I still have a lot of learning ahead.

 

Thanks again.

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  

×