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.

Backup/restore object values with storage.set/get?
#1
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?
Thank you!
Morkov
Reply
#2
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
Reply
#3
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
Thank you!
Morkov
Reply


Forum Jump: