08.04.2024, 08:17
Hello Admin,
I am using the following to find max value of multiple tables with multiple tagged objects. Now I am repeating the same calculation many times in a resident script; how can I achieve the same but with something like a table containing multiple tables in and run the for loop once per table?
Kind regards
I am using the following to find max value of multiple tables with multiple tagged objects. Now I am repeating the same calculation many times in a resident script; how can I achieve the same but with something like a table containing multiple tables in and run the for loop once per table?
Code:
--Actual Lux Values
lux_rest = grp.tag('Lux_Rest')
lux_hal1 = grp.tag('Lux_H1')
lux_hal2 = grp.tag('Lux_H2')
lux_hal3 = grp.tag('Lux_H3')
lux_hal4 = grp.tag('Lux_H4')
lux_hal5 = grp.tag('Lux_H5')
lux_hal6 = grp.tag('Lux_H6')
lux_hal7 = grp.tag('Lux_H7')
-----------MAX LUX VALUE--------------
-- Calculate Max Lux Value in Zone Under Restaurant
t0 = {}
for i, v in ipairs(lux_rest) do
table.insert(t0, v.value)
end
if t0 then
table.sort(t0)
local max = t0[#t0]
grp.checkwrite('3/0/0', max, 1)
end
os.sleep(0.1)
-- Calculate Max Lux Value in Hal 1
t1 = {}
for i, v in ipairs(lux_hal1) do
table.insert(t1, v.value)
end
if t1 then
table.sort(t1)
local max = t1[#t1]
grp.checkwrite('3/0/10', max, 1)
end
os.sleep(0.1)
-- Calculate Max Lux Value in Hal 2
t2 = {}
for i, v in ipairs(lux_hal2) do
table.insert(t2, v.value)
end
if t2 then
table.sort(t2)
local max = t2[#t2]
grp.checkwrite('3/0/20', max, 1)
end
os.sleep(0.1)
-- Calculate Max Lux Value in Hal 3
t3 = {}
for i, v in ipairs(lux_hal3) do
table.insert(t3, v.value)
end
if t3 then
table.sort(t3)
local max = t3[#t3]
grp.checkwrite('3/0/30', max, 1)
end
os.sleep(0.1)
-- Calculate Max Lux Value in Hal 4
t4 = {}
for i, v in ipairs(lux_hal4) do
table.insert(t4, v.value)
end
if t4 then
table.sort(t4)
local max = t4[#t4]
grp.checkwrite('3/0/40', max, 1)
end
os.sleep(0.1)
-- Calculate Max Lux Value in Hal 5
t5 = {}
for i, v in ipairs(lux_hal5) do
table.insert(t5, v.value)
end
if t5 then
table.sort(t5)
local max = t5[#t5]
grp.checkwrite('3/0/50', max, 1)
end
os.sleep(0.1)
-- Calculate Max Lux Value in Hal 6
t6 = {}
for i, v in ipairs(lux_hal6) do
table.insert(t6, v.value)
end
if t6 then
table.sort(t6)
local max = t6[#t6]
grp.checkwrite('3/0/60', max, 1)
end
os.sleep(0.1)
-- Calculate Max Lux Value in Hal 7
t7 = {}
for i, v in ipairs(lux_hal7) do
table.insert(t7, v.value)
end
if t7 then
table.sort(t7)
local max = t7[#t7]
grp.checkwrite('3/0/70', max, 1)
end
Kind regards