malu05 Posted November 11, 2006 Share Posted November 11, 2006 I tried looking through the help file but couldnt find the command. How is it that you compare some numbers and see wich of them that are closest to $x? Like in a array or so? [center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center] Link to comment Share on other sites More sharing options...
Cue Posted November 11, 2006 Share Posted November 11, 2006 go through the array and do$x - element value then use Abs ( expression )store the element number if smaller than previous element or continue if larger. hope that made sense Link to comment Share on other sites More sharing options...
Cue Posted November 11, 2006 Share Posted November 11, 2006 I would do this for you but iam feeling lazy. Link to comment Share on other sites More sharing options...
malu05 Posted November 11, 2006 Author Share Posted November 11, 2006 go through the array and do$x - element value then use Abs ( expression )store the element number if smaller than previous element or continue if larger. hope that made senseHmm.. what would Abs help here?isnt there a specified command for this? [center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center] Link to comment Share on other sites More sharing options...
Paulie Posted November 11, 2006 Share Posted November 11, 2006 (edited) This is a quickie that returns "1" if the first one is closer, "2" id the second is closer, and "0"if they are equal distance in comparison to the third number This example will return a 1 for example $msg = _Compare(100, 200, 0) MsgBox(0,"", $msg) ;---------- Func _Compare($Number1, $Number2, $NumToComp) Local $1 = Abs($NumToComp - $Number1) Local $2 = Abs($NumToComp - $Number2) Select Case $1 = $2 $value = 0 Case $1 < $2 $value = 1 Case $1 > $2 $Value = 2 EndSelect Return $Value EndFunc Edited November 11, 2006 by Paulie Link to comment Share on other sites More sharing options...
Cue Posted November 11, 2006 Share Posted November 11, 2006 (edited) I took the time to write it for you both functions _ArrayMinDiff and _ArrayMaxDiff return an array with 2 values elment [0] gives the index at which the min difference or max difference was found and [1] gives the min or max difference expandcollapse popup$Array = StringSplit("4,2,6,8,12,5",",") $min=_ArrayMinDiff($Array,6,1) $max=_ArrayMaxDiff($Array,6,1) ConsoleWrite('min:'&$min[0]&@CRLF&$min[1]&@CRLF&"max:"&$max[0]&@CRLF&$max[1]&@CRLF) Func _ArrayMinDiff($F_Array,$F_Value,$i_Base=0) If Not IsArray($F_Array) Then SetError(1) Return "" EndIf Local $ArrayMinDiff[2],$i,$i_DiffValue $ArrayMinDiff[0]=$i_Base Local $i_Upper = UBound($F_Array)-1 For $i= $i_Base To $i_Upper $i_DiffValue=Abs(Number($F_Array[$i])-$F_Value) if $i_DiffValue<Abs(Number($F_Array[$ArrayMinDiff[0]])-$F_Value) then $ArrayMinDiff[0]=$i $ArrayMinDiff[1]=$i_DiffValue EndIf Next SetError(0) Return $ArrayMinDiff EndFunc Func _ArrayMaxDiff($F_Array,$F_Value,$i_Base=0) If Not IsArray($F_Array) Then SetError(1) Return "" EndIf Local $ArrayMaxDiff[2],$i,$i_DiffValue $ArrayMaxDiff[0]=$i_Base Local $i_Upper = UBound($F_Array)-1 For $i= $i_Base To $i_Upper $i_DiffValue=Abs(Number($F_Array[$i])-$F_Value) if $i_DiffValue>Abs(Number($F_Array[$ArrayMaxDiff[0]])-$F_Value) then $ArrayMaxDiff[0]=$i $ArrayMaxDiff[1]=$i_DiffValue EndIf Next SetError(0) Return $ArrayMaxDiff EndFunc Edited November 11, 2006 by Cue Link to comment Share on other sites More sharing options...
Cue Posted November 11, 2006 Share Posted November 11, 2006 Hmm... just one question what exactly is alpha Numeric Link to comment Share on other sites More sharing options...
malu05 Posted November 11, 2006 Author Share Posted November 11, 2006 I took the time to write it for you both functions _ArrayMinDiff and _ArrayMaxDiff return an array with 2 values elment [0] gives the index at which the min difference or max difference was found and [1] gives the min or max difference expandcollapse popup$Array = StringSplit("4,2,6,8,12,5",",") $min=_ArrayMinDiff($Array,6,1) $max=_ArrayMaxDiff($Array,6,1) ConsoleWrite('min:'&$min[0]&@CRLF&$min[1]&@CRLF&"max:"&$max[0]&@CRLF&$max[1]&@CRLF) Func _ArrayMinDiff($F_Array,$F_Value,$i_Base=0) If Not IsArray($F_Array) Then SetError(1) Return "" EndIf Local $ArrayMinDiff[2],$i,$i_DiffValue $ArrayMinDiff[0]=$i_Base Local $i_Upper = UBound($F_Array)-1 For $i= $i_Base To $i_Upper $i_DiffValue=Abs(Number($F_Array[$i])-$F_Value) if $i_DiffValue<Abs(Number($F_Array[$ArrayMinDiff[0]])-$F_Value) then $ArrayMinDiff[0]=$i $ArrayMinDiff[1]=$i_DiffValue EndIf Next SetError(0) Return $ArrayMinDiff EndFunc Func _ArrayMaxDiff($F_Array,$F_Value,$i_Base=0) If Not IsArray($F_Array) Then SetError(1) Return "" EndIf Local $ArrayMaxDiff[2],$i,$i_DiffValue $ArrayMaxDiff[0]=$i_Base Local $i_Upper = UBound($F_Array)-1 For $i= $i_Base To $i_Upper $i_DiffValue=Abs(Number($F_Array[$i])-$F_Value) if $i_DiffValue>Abs(Number($F_Array[$ArrayMaxDiff[0]])-$F_Value) then $ArrayMaxDiff[0]=$i $ArrayMaxDiff[1]=$i_DiffValue EndIf Next SetError(0) Return $ArrayMaxDiff EndFunc Ohhh, you didnt really need to do all that for me, since it was what i tried to avoid. Im kinda a "tiny code hugger". [center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center] Link to comment Share on other sites More sharing options...
Cue Posted November 11, 2006 Share Posted November 11, 2006 Your welcome. it may come in handy for me in the future aswell Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now