This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

tag group write, only different data
#1
Hello,

I have a script that writes values to a group addresses:
AllStatus = grp.tag('test')
AllStatus:write( true )

I want to write only to that addresses that have different data then the value to write. In this case only write value true to addresses with tag 'test' and value false.
Reply
#2
Code:
function tagcheckwrite(tag, value)
  local objects = grp.tag(tag)
  for _, object in ipairs(objects) do
    if object.data ~= value then
      object:write(value)
    end
  end
end

tagcheckwrite('test', false)
Reply
#3
if you look for the object AllStatus, you'll find it's an array with all object.

You can do a loop on this array and write the value only if it's not the same

Will look something like:

for _, item in ipairs(AllStatus) do
if item.value != newvalue then
grp.write(item.address, newvalue
end
end

Edit: Admin send a reply just before my. take his Smile
Reply


Forum Jump: