Min / Max

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

A User Function for use with Oblivion Script Extender

Syntax:

Min ValuesArray 
Min2 Value1, Value2
Max ValuesArray 
Max2 Value1, Value2

Returns the smallest/highest number in a set of values.


Notes[edit | edit source]

  • 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 your mod (Min3, Min4, etc)


Examples:[edit | edit source]

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] := ValueNN
Let MyNumber := call Min MyArray

; --- or just ---

set MyNumber to call Min ar_list Value01, Value02, Value03, . . . , ValueNN ;(up to 20 values)

Making sure a number is smaller than a given limit:

let MyNumber := Call Min MyNumber 100

Making sure a number is >= zero:

let MyNumber := Call Max MyNumber 0

Code[edit | edit source]

ScriptName Min 
array_var aArray
float xReturn

Begin Function {aArray} 
    Let xReturn := ( ar_sort aArray ) [0]
    SetFunctionValue xReturn 
End
ScriptName Min2
float arg1
float arg2

Begin Function {arg1, arg2} 
if arg1 < arg2
   SetFunctionValue arg1
else
   SetFunctionValue arg2
endif
 
End
ScriptName Max 
array_var aArray
float xReturn

Begin Function {aArray} 
    Let xReturn := ( ar_sort aArray 1 ) [0]
    SetFunctionValue xReturn 
End
ScriptName Max2 
float arg1
float arg2

Begin Function {arg1, arg2} 
if arg1 > arg2
   SetFunctionValue arg1
else
   SetFunctionValue arg2
endif
 
End

See Also[edit | edit source]