Posted 21 July 2014 - 03:37 AM
I am working with OpenCCSensors for my first time and I'm having a problem access the data for my BuildCraft Tanks.
Here is an example of the table that I'm having problems with:
How do I access the values stored in the "Tanks" array? I have never worked with a table thats formatted table.index = { { k = v } }
Here is the solution I've found for now. Can anyone improve on it? I'm not to fond of the nested loops.
Here is an example of the table that I'm having problems with:
Spoiler
{
Tanks = {
{
RawName = "fluid.jet fuel",
Temperature = 295,
Name = "jet fuel",
Luminousity = 0,
Viscosity = 800,
Amount = 24000,
Capacity = 48000,
IsGaseous = false,
},
},
DamageValue = 0,
Position = {
Y = 0,
X = -1,
Z = -1,
},
RawName = "buildcraft.tank",
Name = "Tank",
}
How do I access the values stored in the "Tanks" array? I have never worked with a table thats formatted table.index = { { k = v } }
Here is the solution I've found for now. Can anyone improve on it? I'm not to fond of the nested loops.
local function getDetails()
tDetails = {}
for _,targetName in pairs(tTargets) do
results = sens.getTargetDetails(targetName)
tTanks = results.Tanks
for _,tank in pairs(tTanks) do
for k,dets in pairs(tank) do
if tostring(k) == "Name" then tankName = tostring(dets)
elseif tostring(k) == "Amount" then sAmount = tostring(dets)
elseif tostring(k) == "Capacity" then sCapacity = tostring(dets)
end
end
if tankName then
if tankName == "jet fuel" then tankName = "jet_fuel" end
tDetails[tankName] = { ["Amount"] = sAmount, ["Capacity"] = sCapacity }
end
end
end
return tDetails
end
Edited on 21 July 2014 - 03:00 AM