Difference between revisions of "Min / Max"
Jump to navigation
Jump to search
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 '' | Min ''ValuesArray'' | ||
Min2 ''Value1, Value2'' | |||
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) | |||
==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) | |||
Making sure a number is smaller than a given limit: | |||
let | let MyNumber := Call Min MyNumber 100 | ||
Making sure a number is >= zero: | |||
let MyNumber := Call Max MyNumber 0 | |||
let | |||
==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 | SetFunctionValue arg1 | ||
else | else | ||
SetFunctionValue arg2 | SetFunctionValue arg2 | ||
Line 37: | Line 62: | ||
End | End | ||
ScriptName | ScriptName Max | ||
array_var aArray | |||
float xReturn | |||
Begin Function {aArray} | |||
float | Let xReturn := ( ar_sort aArray 1 ) [0] | ||
float | SetFunctionValue xReturn | ||
End | |||
ScriptName Max2 | |||
float arg1 | |||
float arg2 | |||
Begin Function { | Begin Function {arg1, arg2} | ||
if | if arg1 > arg2 | ||
SetFunctionValue arg1 | |||
else | else | ||
SetFunctionValue arg2 | |||
endif | endif | ||
End | End | ||
==See Also== | ==See Also== | ||
* [[ | * [[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 --> |
Revision as of 12:42, 31 July 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
- 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)
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] := 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
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