GetClosestIndex MEL

From scripting
Jump to: navigation, search
global proc int GetClosestIndex(string $LocArr[], vector $XYZArr[], vector $CurVec, int $Skip[]) {
	//0001D LLC 2015 Nick Pisca
	float $WinDist = 1000000.0;
	int $WinInt = -1;
	for ($x=0;$x<size($LocArr);$x++) {
		if (IsInIntArray($Skip, $x) == 0) {
			vector $Diff = $XYZArr[$x] - $CurVec;
			float $Dmag = mag($Diff);
			if ($Dmag < $WinDist) {
				$WinDist = $Dmag;
				$WinInt = $x;	
			}
		}	
	}
	return $x;
}


More information on strings and arrays, read pages 28-37 in YSYT.