I still don't understand tables...
Posted: Saturday 19 February 2022 18:29
I've spent hours reading at lua.org, lua-users.org and numerous other sites, looked at a lot of examples here at the forum, but somehow I still don't understand tables. Perhaps it has to do with the fact that I learned myself programming some 40+ years ago when i was a kid. BASIC and Pascal and dialects. I understand tables are not the arrays I used to know, but somehow I just can't grasp it.
I want to make a table ('myTable'). The index has to be a Domoticz device ID (DzDeviceID), the trigger. When that device triggers, I need to look up a premade api/json so I can open it (onActionUrl), and more info, like the name of the trigger (triggerName).
So, in my fantasy LaLaLua-language I need to do something like
etc
Obviously, it doesn't work.
I tried variations of declaring the array, like:
But I have really no clue what I am doing.
Do I need to use? I tried to use tables as unordered sets, because the order is irrelevant. The example doesn't use the way.
I am so confuuuused!
S.
I want to make a table ('myTable'). The index has to be a Domoticz device ID (DzDeviceID), the trigger. When that device triggers, I need to look up a premade api/json so I can open it (onActionUrl), and more info, like the name of the trigger (triggerName).
So, in my fantasy LaLaLua-language I need to do something like
Code: Select all
myTable[DzDeviceID].onActionUrl = myPremadeUrl
myTable[DzDeviceID].triggerName= thetriggername
Obviously, it doesn't work.
I tried variations of declaring the array, like:
Code: Select all
local myTable= {
onActionUrl= {},
triggerName= {}
}
Do I need to use
Code: Select all
insert.table
Code: Select all
insert.table
I am so confuuuused!
S.