Logic Machine Forum
result of grp.tag - 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: result of grp.tag (/showthread.php?tid=323)



result of grp.tag - rocfusion - 15.06.2016

Hi,

What is the most efficient way of testing for the table object returned by grp.tag?  ie is it better to test for the existence of the table or the length or is there something else?


Code:
if (event.type=='groupwrite') then
 local myvl = grp.tag({'VL0','vl'},'all')
 if(myvl) then --existence
   myvl:write(event.getvalue())
 end
 local myls = grp.tag({'VL0','ls'},'all')
 if(#myls>0) then  --length
   if (event.getvalue() > 0) then
     myls:write(true)
   else
     myls:write(false)
   end
 end
end
Thanks,


Roger


RE: result of grp.tag - admin - 15.06.2016

grp.tag always returns a table if valid tag, tag list or tag table is passed. So the correct way is to check table length (#mytable). Still, you can call write and other methods on an empty table returned by grp.tag, it just won't do anything.


RE: result of grp.tag - rocfusion - 15.06.2016

ok thanks