Logic Machine Forum
Dealing with objects with 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: Dealing with objects with tag (/showthread.php?tid=4002)



Dealing with objects with tag - khalil - 18.04.2022

Hello 
I have set of GA(1,2,3,4,...) linked to TAG (TESt)
I want the script based on GA(1,2,3,4,...) value to write something in different GA(101,102,103,104,...) 

how to achieve this  especially when multiple GA's values changed together?
with Best regards,


RE: Dealing with objects with tag - admin - 19.04.2022

This will add 100 to the last group address part:
Code:
addr = event.dst:gsub('%d+$', function(a)
  return tonumber(a) + 100
end)
log(addr)



RE: Dealing with objects with tag - khalil - 19.04.2022

(19.04.2022, 06:58)admin Wrote: This will add 100 to the last group address part:
Code:
addr = event.dst:gsub('%d+$', function(a)
  return tonumber(a) + 100
end)
log(addr)

Thanks Admin 
and the Value?


RE: Dealing with objects with tag - admin - 19.04.2022

Use event.getvalue() as in any other event script. It does not matter if the script is attached to a tag or a single group address.


RE: Dealing with objects with tag - khalil - 19.04.2022

(19.04.2022, 06:58)admin Wrote: This will add 100 to the last group address part:
Code:
addr = event.dst:gsub('%d+$', function(a)
  return tonumber(a) + 100
end)
log(addr)
Thanks Admin
I think it will be easy for me to get only the last group address part as number, because its not the same pattern.

Also what is function(a)?

BR,


RE: Dealing with objects with tag - admin - 19.04.2022

This function replaces last part of the group address with the last part value + 100.
Another option for this is to split the address into parts and then join back:
Code:
parts = event.dst:split('/')
parts[3] = tonumber(parts[3]) + 100
addr = table.concat(parts, '/')

log(addr)



RE: Dealing with objects with tag - khalil - 19.04.2022

(19.04.2022, 08:49)admin Wrote: This function replaces last part of the group address with the last part value + 100.
Another option for this is to split the address into parts and then join back:
Code:
parts = event.dst:split('/')
parts[3] = tonumber(parts[3]) + 100
addr = table.concat(parts, '/')

log(addr)

Thanks Admin