An archive of community.esquilo.io as of Saturday January 26, 2019.

Nv access question

JefferyS

If I have an nv.AnodizingTanks

nv.AnodizingTanks <- {
// Anodizing Config
Anodizing = {
tankName = "Anodizing",
tankTemp = 0,
tankProbe = 0,
tankMinTemp = 15,
tankMaxTemp = 22,
tankTempFC = "C",
tankAlarm = 1,
tankActive = 1
},
// 740 Cleaner Config
Cleaner740 = {
tankName = "Speciality 740 Cleaner",
tankTemp = 0,
tankProbe = 1,
tankMinTemp = 54,
tankMaxTemp = 71,
tankTempFC = "C",
tankAlarm = 1,
tankActive = 1
},
// SealantMTL Config
SealantMTL = {
tankName = "Speciality Sealant MTL",
tankTemp = 0,
tankProbe = 2,
tankMinTemp = 82,
tankMaxTemp = 88,
tankTempFC = "C",
tankAlarm = 1,
tankActive = 1
},
// SoakClean Config
SoakClean = {
tankName = "Soak Clean",
tankTemp = 0,
tankProbe = 3,
tankMinTemp = 57,
tankMaxTemp = 66,
tankTempFC = "C",
tankAlarm = 0,
tankActive = 1
},
// WarmRinse Config
WarmRinse = {
tankName = "-----",
tankTemp = 0,
tankProbe = 0,
tankMinTemp = 0,
tankMaxTemp = 0,
tankTempFC = "C",
tankAlarm = 0,
tankActive = 0
},
// Tank Dye
Dye = {
tankName = "Dye - Fast Blue GN",
tankTemp = 0,
tankProbe = 5,
tankMinTemp = 57,
tankMaxTemp = 63,
tankTempFC = "C",
tankAlarm = 1,
tankActive = 1
}
//
};

is there a way I can loop through it like an array. Like AnodizingTanks[0].tankTemp. the 0 ref the first tank in the list of Anodizing. Then [1] is Cleaner740 ect...

I hope that makes since what I'm trying to do.

Thanks,

Jeffery

Scott_Shumate

You can iterate through a table with the foreach command but it will iterate in an unpredictable order since tables do not have an ordering. Here's an example...

foreach (key, value in nv.AnodizingTanks) {
    print("Config: " + key + "\n");
    print("Tank Name: " + value.tankName + "\n");
}

If you need to maintain order, then you'll want the top-most data structure to be an array.

nv.AnodizingTanks <- [
// Anodizing Config
{
tankName = "Anodizing",
tankTemp = 0,
tankProbe = 0,
tankMinTemp = 15,
tankMaxTemp = 22,
tankTempFC = "C",
tankAlarm = 1,
tankActive = 1
},
// 740 Cleaner Config
{
tankName = "Speciality 740 Cleaner",
tankTemp = 0,
tankProbe = 1,
tankMinTemp = 54,
tankMaxTemp = 71,
tankTempFC = "C",
tankAlarm = 1,
tankActive = 1
},
...
];

Then you can use the foreach to iterate in order.

foreach (index, value in nv.AnodizingTanks) {
    print("Index: " + index+ "\n");
    print("Tank Name: " + value.tankName + "\n");
}
JefferyS

That's great, thanks Scott, I'll give that a try.

Jeffery

JefferyS

I don't think that is going to work like I thought.

Is there anyway to get the names of the tables in nv.AnodizingTanks?

I would like to get Anodizing, Cleaner740, SealantMTL, etc...

I hope that makes since. Then I can put them in an array and run through them and get the information I need. Right now I have them in code, I would like it to be dynamic.

listOfTanks <- ["Anodizing", "Cleaner740", "Dye", "WarmRinse", "SealantMTL", "SoakClean"];

Thanks,

Jeffery

Scott_Shumate

One way would be to put the short name in the nv table and then create the list dynamically.

Here's an example of adding the short name as the "id" slot:

// 740 Cleaner Config
{
  id = "Cleaner740",
  name = "Speciality 740 Cleaner",
  temp = 0,
  probe = 1,
  minTemp = 54,
  maxTemp = 71,
  tempFC = "C",
  alarm = 1,
  active = 1
},

Then you could dynamically create a list from the "id" slots:

listOfTanks <- [];
foreach (index, value in nv.AnodizingTanks)
    listOfTanks.append(value.id);