Logic Machine Forum
Copy value to another GA multiple times - 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: Copy value to another GA multiple times (/showthread.php?tid=3586)



Copy value to another GA multiple times - Dré - 26.09.2021

Maybe someone can help me.

I have very much groupsadresses
what i want i have adres 63/1/1 till 63/1/28
i will copy the value of 63/1/1 to 63/1/2 and 63/1/2 to 63/1/3 and so go on till 63/1/28
and the same thing for 63/2/1 till 63/2/28

at the moment i did it like
Code:
Elektra_Verbruik_week0maandag = grp.getvalue('63/1/3')
grp.update('63/1/4', Elektra_Verbruik_week0maandag)
Elektra_Verbruik_week0maandag = grp.getvalue('63/1/2')
grp.update('63/1/3', Elektra_Verbruik_week0maandag)
Elektra_Verbruik_week0maandag = grp.getvalue('63/1/1')
grp.update('63/1/2', Elektra_Verbruik_week0maandag)
...........
........

end so on untill 63/1/28
My question is, is there a more easy way to do this?


RE: Copy value to another GA multiple times - admin - 27.09.2021

This can be done with a loop in a descending order:
Code:
prefix = '63/1/'
for i = 28, 2, -1 do
  value = grp.getvalue(prefix .. (i - 1))
  grp.update(prefix .. i, value)
end



RE: Copy value to another GA multiple times - Dré - 02.10.2021

Thanks Admin, this is working perfect to me


RE: Copy value to another GA multiple times - Dré - 31.12.2022

Maybe someone can help me why this isn't working?

This is working fine
Code:
prefix = '56/0/'
for i = 20, 1, -1 do
  value = grp.getvalue(prefix .. (i - 1))
  grp.checkupdate(prefix .. i, value)
end

Code:
prefix = '56/0/'
for i = 20, 201, -1 do
  value = grp.getvalue(prefix .. (i - 1))
  grp.checkupdate(prefix .. i, value)
end
But this one doesn't, the only thing that was change is the last part of the groupadres, it has a 3 digit.
Is it possible to get this working too?

I have group object from 200 til 220 that i would move, like the first script is doing.
All the group addresses have the same data type too.


RE: Copy value to another GA multiple times - Erwin van der Zwart - 31.12.2022

Try changing for i = 20 into 220 as you count down (20 is already lower then 201)


RE: Copy value to another GA multiple times - Dré - 31.12.2022

I see, i thought the 'i = 20' is how many times, but now I see it from group adres 20 til group adres 200, so indeed it can't work.
Thanks Erwin, fijne jaar wisseling.


RE: Copy value to another GA multiple times - Erwin van der Zwart - 01.01.2023

It’s start, end, step size and direction (- is countdown)

Fijne jaarwisseling!


RE: Copy value to another GA multiple times - Dré - 01.01.2023

Thanks for explaining