Difference between revisions of "Min / Max"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>DragoonWraith
(linking to a User Function page)
imported>Shademe
m (Typo corrected)
 
(2 intermediate revisions by one other user not shown)
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 your 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 -->

Latest revision as of 18:18, 3 August 2009

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]