Difference between revisions of "Min / Max"

Jump to navigation Jump to search
553 bytes added ,  12:42, 31 July 2009
Added Max and reformatted a bit (Notes before Examples)
imported>DragoonWraith
(linking to a User Function page)
imported>QQuix
(Added Max and reformatted a bit (Notes before Examples))
Line 1: Line 1:
__NOTOC__
A [[User Function]] for use with [[:Category:Oblivion Script Extender|Oblivion Script Extender]]
A [[User Function]] for use with [[:Category:Oblivion Script Extender|Oblivion Script Extender]]


'''Syntax:'''
'''Syntax:'''
  Min ''value1:float, value2:float''  
  Min ''ValuesArray''
   
Min2 ''Value1, Value2''
  Min3 ''value1:float, value2:float, value3:float''  
 
  Max ''ValuesArray''
  Max2 ''Value1, Value2''
 
Returns the smallest/highest number in a set of values.
 
 
==Notes==
*Min/Max returns the smallest/highest of the values stored in an array
*Min2/Max2 returns the smaller/higher of two values
*Other variations with fixed number of arguments may be easily created if you use them frequently in tour mod (Min3, Min4, etc)
 


Returns the smallest number in a set of values.
==Examples:==


Getting the smallest of many values
(considering that ValueXX are predefined float vars already filled with values)
Let MyArray := ar_Construct Array
Let MyArray [0] := Value00
    . . .
Let MyArray [''NN''] := Value''NN''
Let MyNumber := call Min MyArray
; --- or just ---
set MyNumber to call Min ar_list Value01, Value02, Value03, . . . , ValueNN ;(up to 20 values)


'''Examples:'''
Making sure a number is smaller than a given limit:
  let MyNumber1 := 512
  let MyNumber := Call Min MyNumber 100
let MyNumber2 := 27.9
let Myval := Call Min MyNumber1 MyNumber2


let MyNumber1 := 512
Making sure a number is >= zero:
let MyNumber2 := 0.001
  let MyNumber := Call Max MyNumber 0
let MyNumber3 := 27.9
  let Myval := Call Min3 MyNumber1 MyNumber2 MyNumber3


==Notes==
*If an argument is not provided, it defaults to zero, e.g, '''Call Min3 1 2''' will return zero as it returns the smallest of 1, 2 and zero (the missing third argument)
*Of course, new Min functions with more arguments can be created as needed
==Code==
==Code==
  ScriptName Min
 
  ScriptName Min  
array_var aArray
float xReturn
   
   
Begin Function {aArray}
    Let xReturn := ( ar_sort aArray ) [0]
    SetFunctionValue xReturn
End
ScriptName Min2
  float arg1
  float arg1
  float arg2
  float arg2
   
   
  Begin Function {arg1, arg2}  
  Begin Function {arg1, arg2}  
  if arg1< arg2
  if arg1 < arg2
     SetFunctionValue arg2
     SetFunctionValue arg1
  else
  else
     SetFunctionValue arg2
     SetFunctionValue arg2
Line 37: Line 62:
  End
  End


  ScriptName Min3
  ScriptName Max
array_var aArray
float xReturn
   
   
  float val1
  Begin Function {aArray}
  float val2
    Let xReturn := ( ar_sort aArray 1 ) [0]
  float val3
    SetFunctionValue xReturn
End
 
ScriptName Max2
  float arg1
  float arg2
   
   
  Begin Function {val1, val2, val3}  
  Begin Function {arg1, arg2}  
  if val1< val2
  if arg1 > arg2
  if val1< val3
    SetFunctionValue arg1
    SetFunctionValue val1
  else
    SetFunctionValue val3
  endif
  else
  else
  if val2< val3
    SetFunctionValue arg2
    SetFunctionValue val2
  else
    SetFunctionValue val3
  endif
  endif
  endif
 
  End
  End


==See Also==  
==See Also==  
* [[Max]]
* [[User Functions]]


[[Category: User Functions]]
[[Category: User Functions]]
Line 67: Line 91:
<!-- Begin Search Terms
<!-- Begin Search Terms
  Min
  Min
Max
End Search Terms -->
End Search Terms -->
Anonymous user

Navigation menu