Logic Machine Forum
Backup/restore object values with storage.set/get? - 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: Backup/restore object values with storage.set/get? (/showthread.php?tid=3571)



Backup/restore object values with storage.set/get? - morkovka - 21.09.2021

Hi,

I have a script which runs some logic for a scene (e.g. dim the lights, set color X for RGB, etc.) - but before running it, I want to be able to provide a list of group addresses to 'backup', and then to 'restore' them after the scene finishes - can anybody help with this?

E.g. if we have:
Code:
backuplist = { '1/1/1', '2/2/2' }

save_values(backuplist)

grp.write('1/1/1', 52)
grp.write('2/2/2', false)

load_values(backup_list)

The group addresses will have different value types (boolean, percentage, int, etc.).

I'm not sure how to best implement the save_values() and load_values() functions - any ideas?


RE: Backup/restore object values with storage.set/get? - admin - 21.09.2021

If this is inside a single script you don't need to use storage at all.
Code:
backuplist = { '1/1/1', '1/1/2' }
-- save current values
values = {}
for _, addr in ipairs(backuplist) do
  values[ addr ] = grp.getvalue(addr)
end

...

-- restore values
for addr, value in pairs(values) do
  grp.write(addr, value)
end



RE: Backup/restore object values with storage.set/get? - morkovka - 21.09.2021

Thanks, this is very helpful.

I am using an event script, sometimes it's called with value 'on' and sometimes 'off' - in this case, I assumed I'll need to store the backuplist in storage, is something like the below the correct approach?

Code:
backuplist = { '1/1/1', '1/1/2' }

-- save current values
values = {}
for _, addr in ipairs(backuplist) do
  values[ addr ] = grp.getvalue(addr)
end
storage.set('backuplist', values)
...

-- restore values
values = storage.get('backuplist')
for addr, value in pairs(values) do
  grp.write(addr, value)
end