I get an error message. It's probably obvious what is wrong but I just can't see it. Can You?
global_data.lua:
Code: Select all
return {
data = {
openSections = { initial = {0, 0, 0, 0} },
}
}
Code: Select all
return {
active = true,
on = {
'Test Button',
},
execute = function(domoticz, device)
local z = 1
domoticz.globalData['openSections'][z] = domoticz.globalData['openSections'][z] + 1
print(domoticz.globalData['openSections'][z])
end
}}
Code: Select all
2017-03-15 08:58:19.916 LUA: =====================================================
017-03-15 09:15:52.934 LUA: >>> Handler: testScript3
2017-03-15 09:15:52.934 LUA: >>> Device: "Test Button" Index: 47
2017-03-15 09:15:52.934 LUA: .....................................................
2017-03-15 09:15:52.935 LUA: An error occured when calling event handler testScript3
2017-03-15 09:15:52.935 LUA: /home/pi/domoticz/scripts/lua/scripts/testScript3.lua:9: attempt to index field 'openSections' (a nil value)
2017-03-15 09:15:52.935 LUA: .....................................................
2017-03-15 09:15:52.935 LUA: <<< Done
If I alter the script temporarily so it initializes the array before the first use
Code: Select all
domoticz.globalData['openSections'] = {0, 0, 0, 0}
It seems that the initialization of the variable openSections defined in global_data.lua doesn't work.
I'd like to get a grip of this problem in case that the global data gets "reset" or deleted for some reason.
Any help is very appreciated. Thanks!