useful_programs
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
useful_programs [2020/06/03 12:01] – [Other handy functions] emozolyak | useful_programs [2020/07/30 15:07] – atolstov | ||
---|---|---|---|
Line 877: | Line 877: | ||
</ | </ | ||
+ | ===== Curve handler ===== | ||
+ | Library | ||
+ | <code lua - curves.lib> | ||
+ | function GetCurveValue ( curve_register, | ||
+ | --[[ | ||
+ | --Curve handler | ||
+ | INPUT: | ||
+ | Put curve register as first argument and X coordinate as second. | ||
+ | OUTPUT: | ||
+ | Get as result status if it is inside curve range of outside(false) and the Y value as second output argument | ||
+ | | ||
+ | EXAMPLE: | ||
+ | curve_status, | ||
+ | --]] | ||
+ | table = cjson.decode( R ( curve_register ) ) | ||
+ | -- inRangeCurve( table, x_to_find_y ) | ||
+ | for _, value in ipairs( table ) do --piecewise handler inside range of the curve | ||
+ | if ( value.range[1] <= x_to_find_y and x_to_find_y < value.range[2] ) then | ||
+ | -- in_range_status, | ||
+ | in_range_status, | ||
+ | return in_range_status, | ||
+ | end | ||
+ | end | ||
+ | if x_to_find_y < table[1].range[1] then -- behaivior for outside left-sided | ||
+ | -- in_range_status, | ||
+ | in_range_status, | ||
+ | return in_range_status, | ||
+ | elseif x_to_find_y > table[# | ||
+ | -- in_range_status, | ||
+ | in_range_status, | ||
+ | return in_range_status, | ||
+ | end | ||
+ | |||
+ | return in_range_status, | ||
+ | end | ||
+ | </ | ||
+ | Example of usage: | ||
+ | <code lua - Getter> | ||
+ | include " | ||
+ | |||
+ | function main (userId) | ||
+ | |||
+ | local t = os.date(" | ||
+ | current_hour = tonumber(t.hour) | ||
+ | curve_status, | ||
+ | WriteReg(" | ||
+ | |||
+ | end | ||
+ | </ | ||
useful_programs.txt · Last modified: 2024/03/19 09:39 by emozolyak