Page 1 of 1

Syntax examples wiki  [Solved]

Posted: Saturday 16 May 2020 11:58
by jkimmel

Code: Select all

return
{
    on =
    {
        devices = {
            'myDetector',
            'roomTemp'
    }
},
    execute = function(domoticz, device)
        if ((device.name == 'myDetector' and device.active) or
            (device.name == 'roomTemp' and device.temperature >= 45)) then
            domoticz.notify('Fire', 'The room is on fire', domoticz.PRIORITY_EMERGENCY)
        end
    end
}
Is the comma after 'myDetector correct?

And is a comma missing after

Code: Select all

  {
        devices = {
            'myDetector',
            'roomTemp'
    }

Re: Syntax examples wiki

Posted: Saturday 16 May 2020 12:34
by waaren
jkimmel wrote: Saturday 16 May 2020 11:58
Is the comma after 'myDetector correct?
Yes
And is a comma missing after
No

devices is here the name of a table and myDetector and roomTemp are values in that table. Values in a table constructor are separated by a comma or a semicolon.

In Lua (dzVents = Lua) "you can always put a comma after the last entry. These trailing commas are optional, but are always valid:"
source


Below constructor examples are all valid

Code: Select all

myTable = {x=10, y=45; "one", "two", "three"} 

print (myTable[1]) -- > one
print (myTable.x)--> 10

myTable = { ["domoticz scripting framework"] =  "dzVents"  }

print (myTable["domoticz scripting framework"]) --> dzVents

myTable = { scriptTypes = { "blockly" ;  "python", "dzvents", "Lua" ,},  }

print (myTable.scriptTypes[2]) --> python