Jump to content
  • entries
  • comments
  • views

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




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.



  • Clean as fukk.


  • 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.


Recommended Comments

Do we know if PapyrusUtil functions are latent? I'd expect not, given that they're used in SexLab where timing is important, but it would be nice to know.


If we lose the thread every time we call ClampInt it could be worth doing the five lines of code.

Link to comment

DocClox - not sure off hand. Ashal hasn't released updated source yet. I guess we could ask him.

If it is, or if it isn't, it actually wouldn't be that bad of a thing. Allowing your script to lose the thread will allow other things to get done by other mods, sharing the love basically. I believe there are very few cases where you would truely want to lock a thread so hard that you intentionally break the entire point of a multi-threaded system.


For data integrity cases, where you really need to know something hasn't been dicked with, you're probably looking at implementing a spinlock or something of sorts anyway since without one you really cant trust that the thread timeslice is yours in entirety with Papyrus VM being amazeballz.

Link to comment
  • Create New...