Logic Machine Forum
2 byte floating compare - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: 2 byte floating compare (/showthread.php?tid=1707)



2 byte floating compare - AlexLV - 08.11.2018

Hello.

I am a little confused how compare 2 byte float values. I have group 2/0/0 with Brightness value in 2 byte floating point and suffix used - 3 LUX.  have compare this value with set point? I tried made set point also in 2 byte floating, not a working idea.. How better compare or before convert my value to numbers? Will it work if setpoint = 0? 

I tried like this:

value = tonumber(event.getvalue())
setpoint = tonumber(grp.getvalue('20/0/5'))
if value >= setpoint then
grp.write('20/2/0', 1)
else
  grp.write('20/2/0', 0)
end
But error... :
User script:2: bad argument #2 to 'tonumber' (number expected, got string)
stack traceback:
[C]: in function 'tonumber'
User script:2: in main chunk

How do my task better? Where better read about values converting/compare in LUA?


RE: 2 byte floating compare - admin - 09.11.2018

You don't need to call tonumber, the result of event.getvalue and grp.getvalue is already a number if proper data type is set.
Code:
value = event.getvalue()
setpoint = grp.getvalue('20/0/5')