This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
renjestoo's profile picture

reading tanks from openblocks

Started by renjestoo, 10 May 2015 - 05:35 AM
renjestoo #1
Posted 10 May 2015 - 07:35 AM
Hey there,

I was making a script for reading out a couple of tanks from openblocks 1.4

in a few posts I saw that you can read out the information from Openblocks tanks with

a = peripheral.wrap("openblocks_tank_1")
a.getTankInfo[1]

this is not working at all. In this version you have to use the following:

a = peripheral.wrap("openblocks_tank_1")
a.getTankInfo[1].contents.amount
a.getTankInfo[1]capacity
a.getTankInfo[1].contents.rawname

while I solved that little issue, I stumble across a crash in the OpenComputers computer when performing the following script:

local tankName = ""
local mon = peripheral.wrap("monitor_3")
local dir = "UNKNOWN"
local tank = {}
local maxT = 11
local row = 6
local tankAmount1 = peripheral.wrap("openblocks_tank_13")
local tankAmount2 = peripheral.wrap("openblocks_tank_12")
local amounts1 = tankAmount1.getTankInfo(dir)
local amounts2 = tankAmount2.getTankInfo(dir)
for t = 8,maxT do
tankName = "openblocks_tank_"..tostring(t)
tank[t] = peripheral.wrap(tankName)
end
while true do
amount = 0
capacity = 0

for t = maxT,8 do
  details = tank[t].getTankInfo(dir)
  if details[1].contents.amount then
   detaila = details[1].contents.amount
   detailc = details[1].capacity
   detailn = details[1].contents.rawname
   else
   mon.write("The Tanks can't register the data!!!")
  end
  amount = detaila + (detaila * 6)
  capacity = detailc + (detailc * 6)
  mon.clear()
  mon.setTextScale(1)
  mon.setCursorPos(1,1)
  mon.write(tostring(amount).." / "..tostring(capacity))
  while amounts1[1].contents.amount do
   amount1 = amounts2[1].contents.amount
   if amount1 <= 1000 then
	rs.setOutput("right",true)
	mon.setCursorPos(1,3)
	mon.write("Laat de blazes maar komen!")
	mon.setCursorPos(1,4)
	mon.write("XP Verzamelen AAN")
   end
  end
  while amounts2[1].contents.amount do
   amount2 = amounts2[1].contents.amount
   if amount2 >= 31000 then
	rs.setOutput("right",false)
	mon.setCursorPos(1,3)
	mon.write("Eindelijk....Rust!! :D/>/>")
	mon.setCursorPos(1,4)
	mon.write("XP Verzamelen UIT")
   end
  end
  sleep(1)
end
end

When I start the script It seems to work in the console. (No errors or such things.)
when I leave the console and go back to it (rightclick) I see that the computer is restarted.

What did I do wrong?

PS:
I added a screenshot of my setup as it is right now ;)/>
just to clarify my situation.

PPS:
the modems are setup like this: (from top to bottom)

[ openblocks_tank_12 ]
[ openblocks_tank_11 ]
[ openblocks_tank_10 ]
[ openblocks_tank_9 ]
[ openblocks_tank_8 ]
[ openblocks_tank_13 ]

I added the modem on the bottom later on ;)/>


I hope this is a little clear for you guys, Because I am getting a Headache from this puzzle :S
SquidDev #2
Posted 10 May 2015 - 08:52 AM
I'd say at a guess it is this line:

while amounts1[1].contents.amount do
You never reassign this, so gets stuck in an infinite loop, and so crashes because 'too long without yielding'.
renjestoo #3
Posted 10 May 2015 - 10:20 AM
Can you help me solve this issue? because maybe there is a better way to do this.
Bomb Bloke #4
Posted 10 May 2015 - 12:26 PM
for t = maxT,8 do

"maxT" is 11, which is higher than 8; this loop is hence skipped entirely. Either change the order or set a step size of -1.