Logic Machine Forum
Question of table - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Question of table (/showthread.php?tid=2644)



Question of table - 38348259 - 16.05.2020

Dear All, I have a question about the group address of table. There are some lines in a GA table, e.g. 

table = {
{onoff=1/1/1, feedback=1/2/1},
{onoff=1/1/2, feedback=1/2/2},
{onoff=1/1/3, feedback=1/2/3},
{onoff=1/1/4, feedback=1/2/4},
}

I want to define a local var which called "num",which means when I trigger "1/1/3", the "num"=3, when I trigger "1/1/1", the "num"=1. How can I write the script?

Thanks a lot


RE: Question of table - Erwin van der Zwart - 16.05.2020

Hi,

There is a better way to do this:
Code:
mapping = {
  ['1/1/1'] = {feedback = '2/1/1'},
  ['1/1/2'] = {feedback = '2/1/2'},
  ['1/1/3'] = {feedback = '2/1/3'},
  ['1/1/4'] = {feedback = '2/1/4'},
  ['1/1/5'] = {feedback = '2/1/5'},
  ['1/1/6'] = {feedback = '2/1/6'},
  ['1/1/7'] = {feedback = '2/1/7'},
}

address_feedback = mapping[event.dst].feedback
BR,

Erwin


RE: Question of table - 38348259 - 17.05.2020

(16.05.2020, 14:43)Erwin van der Zwart Wrote: Hi,

There is a better way to do this:
Code:
mapping = {
  ['1/1/1'] = {feedback = '2/1/1'},
  ['1/1/2'] = {feedback = '2/1/2'},
  ['1/1/3'] = {feedback = '2/1/3'},
  ['1/1/4'] = {feedback = '2/1/4'},
  ['1/1/5'] = {feedback = '2/1/5'},
  ['1/1/6'] = {feedback = '2/1/6'},
  ['1/1/7'] = {feedback = '2/1/7'},
}

address_feedback = mapping[event.dst].feedback
BR,

Erwin
Thanks a lot. I will try. But if I use the table, can you tell me what should I write?


RE: Question of table - admin - 17.05.2020

Please specify what do you want your script to do.