Posted 10 February 2014 - 06:02 PM
So I'm writing some code to 'count' my tanks and display onto a screen and I'm pretty close to finished, however I've run into a bit of a snag. The tanks are all connected through a wired modem via the top, and the monitor is connected to the left. The code in question is this:
This returns:
rcsteeltank_0
rcsteeltank_1
etc…
This works perfectly, however, when I 'add' the monitor, I need the above tankList to ignore both 'top' and 'left.' Naturally I make it:
This returns:
top
rcsteeltank_0
etc…
left
So my question is, can you not use the or statement inside the 'in pairs' statement? Thanks in advance for any help that you can give! The total code is listed below for any reference needed.
for k,v in pairs(tempList) do
if v~= "top" then
table.insert(tankList, v)
end
end
This returns:
rcsteeltank_0
rcsteeltank_1
etc…
This works perfectly, however, when I 'add' the monitor, I need the above tankList to ignore both 'top' and 'left.' Naturally I make it:
for k,v in pairs(tempList) do
if (v~= "top") or (v~= "left") then
table.insert(tankList, v)
end
end
This returns:
top
rcsteeltank_0
etc…
left
So my question is, can you not use the or statement inside the 'in pairs' statement? Thanks in advance for any help that you can give! The total code is listed below for any reference needed.
--mon = peripheral.wrap("left")
--mon.clear()
--mon.setCursorPos(1,1)
tempList = peripheral.getNames()
num = (#tempList)
tankList = {}
varNum = {}
for k,v in pairs(tempList) do
if k~= "top" then
table.insert(tankList, v)
end
end
for x,y in pairs(tankList) do
table.insert(varNum, peripheral.wrap(tostring(y)))
end
mPos = 1
for w, b in pairs(varNum) do
for s, e in pairs(b.getTankInfo("top")) do
for a,n in pairs(e) do
if a == ("rawName") then
print(n)
--mon.setCursorPos(1,mPos)
--mon.write(n)
--mPos = mPos+1
end
if a == ("amount") then
print(n)
--mon.setCursorPos(1,mPos)
--mon.write(n)
--mPos = mPos+2
end
end
end
end