PapyrusUtil.ClampFloat & ClampInt
Theses functions were introduced into PapyrusUtil 3.0 / SexLab 1.6. It allows you to squash a number to fit within a specific range. Previously this required a minimum of 5 lines of scripting to pull off, now you can do it seaside with one. This is a global function which can be accessed at any time via PapyrusUtil.ClampFloat(). There is a second version of this function called PapyrusUtil.ClampInt() which does the exact same thing, but you give it integers instead of floats, as well as returns an integer.
I am going to be honest here, these functions alone are totally worth making your mod depend on PapyrusUtil for if you are not already depending on SexLab.
The Functions
-
Float PapyrusUtil.ClampFloat(Float Input, Float Min, Float Max) Global
-
Int PapyrusUtil.ClampInt(Int Input, Int Min, Int Max) Global
Requirements
Examples
Without this function:
If(Something < Minimum) Something = MinimumElseIf(Something > Maximum) Something = MaximumEndIf
With this function:
Something = PapyrusUtil.ClampFloat(Something,Minimum,Maximum)
As you can see, it cleans things up rather nicely.
Pros
- Clean as fukk.
Cons
- It performs a reassignment every time, even if it was within range, e.g. Something = Something. However the time spent reassigning is probably a wash with the time spent doing two tests in the Papyrus VM.
2 Comments
Recommended Comments