Old 12-15-2017, 06:51 AM   #1
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default Setting threshold for a calculated value?

Hey all,

I'm working on an "increase CC" script. It gets the actual CC value and multiplies it with 1.050.
The result is of course a floating point value, therefore I have to use math.floor(ccValue*1.050) to convert
It to integer.
However, when triggering the script multiple times there are also values over 127 and this causes issues.
For the moment I'm using a solution like:

Code:
newCCValue = math.floor(ccValue*1.050)
If newCCValue > 127 then
    newCCValue = 127
Is there a more elegant way to set a threshold, without an if condition?

Last edited by _Stevie_; 12-15-2017 at 06:58 AM.
_Stevie_ is offline   Reply With Quote
Old 12-15-2017, 11:07 AM   #2
ThomasE
Human being with feelings
 
Join Date: Aug 2009
Location: Sweden
Posts: 69
Default

Try this:

Code:
newCCValue = math.min(127, math.floor(ccValue*1.050))
ThomasE is offline   Reply With Quote
Old 12-15-2017, 11:42 AM   #3
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Quote:
Originally Posted by ThomasE View Post
Try this:

Code:
newCCValue = math.min(127, math.floor(ccValue*1.050))
Awesome Thomas, that worked, thanks a lot!!!
_Stevie_ is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:09 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.