Page 1 of 1

can I do forEach on a table in global_data? [closed]

Posted: Monday 25 June 2018 16:11
by rbisschops
Hi all,

I have a table in global_data that looks like this:

Code: Select all

harmony = {
            poweroff = {
                ['name']='PowerOff',
                ['índex']=10,
                ['lightscene']='video'
            },
            television = {
                ['name']='Televisie',
                ['índex']=20,
                ['lightscene']='video'
            }
        }
it is part of the helpers
I can call it with:

Code: Select all

domoticz.log (domoticz.helpers.harmony.television.lightscene)
But can I also do this:

Code: Select all

       domoticz.helpers.harmony().forEach(function(test)
            domoticz.log (test.name)
        end)
It throws an error:

Code: Select all

2018-06-25 16:01:54.123 Status: dzVents: Error (2.4.6): Harmony set Domoticz: ...moticz/scripts/dzVents/scripts/harmony_V-0-0-2-alpha.lua:101: attempt to call field 'harmony' (a table value)
Thank you all!

Ralph

Re: can I do forEach on a table in global_data?

Posted: Tuesday 26 June 2018 7:12
by dannybloe
That's correct. forEach is a dzVents construct that is implemented for the various collections. So for other stuff you will have to do a standard Lua for loop.

Re: can I do forEach on a table in global_data? [closed]

Posted: Friday 20 July 2018 15:55
by rbisschops
Thx @dannybloe, was expecting that.