curves
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
curves [2021/09/10 14:33] – atolstov | curves [2022/05/24 08:52] – [Get value from the curve via Lua] emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{ : | + | {{ network: |
======Curves====== | ======Curves====== | ||
=====Introduction===== | =====Introduction===== | ||
Line 99: | Line 99: | ||
<code lua - curves.lib> | <code lua - curves.lib> | ||
- | function | + | --[[ |
- | --[[ | + | The function |
- | --Curve handler | + | Example of a curve, having multiple ranges of kx + b, set in a register of a String type with Json |
- | | + | [{" |
- | Put curve register as first argument and X coordinate as second. | + | --]] |
- | | + | function getCurveValue (curveReg, inputValue) |
- | Get as result status if it is inside curve range of outside(false) and the Y value as second output argument | + | |
+ | | ||
+ | local tab = cjson.decode( R(curveReg) ) | ||
+ | local outputValue, | ||
| | ||
- | | + | for _, sub_ in ipairs(tab) do |
- | curve_status, | + | if ( (sub_.range[s] <= inputValue) |
- | --]] | + | |
- | table = cjson.decode( R ( curve_register ) ) | + | |
- | -- inRangeCurve( table, x_to_find_y ) | + | |
- | | + | |
- | if ( value.range[1] <= x_to_find_y | + | |
- | | + | |
- | in_range_status, | + | |
- | return in_range_status, y | + | |
end | end | ||
end | end | ||
- | | + | -- edge cases |
- | -- in_range_status, | + | |
- | | + | |
- | | + | |
- | elseif | + | elseif |
- | | + | |
- | | + | |
- | return in_range_status, | + | |
end | end | ||
- | + | | |
- | | + | |
end | end | ||
</ | </ | ||
Example of usage: | Example of usage: | ||
<code lua - Getter> | <code lua - Getter> | ||
- | include " | + | include " |
- | SAFE_VALUE = 10 | + | |
function main (userId) | function main (userId) | ||
- | + | local SAFE_VALUE = 10 | |
- | local t = os.date(" | + | local curHour |
- | | + | |
- | | + | |
- | if curve_status | + | |
- | | + | if (not valueOutOfRange) |
+ | | ||
else | else | ||
- | | + | |
end | end | ||
- | | ||
- | |||
end | end | ||
</ | </ |
curves.txt · Last modified: 2024/06/03 08:45 by emozolyak