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

Monitor Storage tanks lua script

Started by iceman11a, 17 September 2014 - 06:33 PM
iceman11a #1
Posted 17 September 2014 - 08:33 PM
I fount a script that's used to monitor the amounts and totals in a storage tank. The mainprog works. How ever the program used for monitoring the tank seems to give me a nil error in line 27 and i was hoping some one mite have an idea why and how to fix this error. here's the line and the full code it below.

tanksTable = val.getTanks("WhatIsThis") – Line 27

———-


    -- Valve, Monitor & Wireless Modem
    local val = peripheral.wrap("back")
    local mon = peripheral.wrap("top")
    local wmod = peripheral.wrap("bottom")
	
    local warning = 20	   -- Warning level in %
    local cap			    -- Tank capacity
    local amount			 -- Amount liquid in tank
    local percentfull	    -- Percent liquid in tank
    local lastpercent = 1000 -- Percent last loop
    local sendmsg		    -- Message to send
    local sleeptime		  -- How long to sleep
    local sendFreq = 3	   -- Modem Frequency
    local content = "Water"  -- What is in tank?
    -- Make sure frequency match the main computer
	
    -- Set warning lamp to off
    redstone.setOutput("right", false)
	
	
    -- Main prog loop, never stop
    while true do
	  mon.clear()
	  mon.setCursorPos(1,1)
	
	  -- Fill table with data from tank valve
	  tanksTable = val.getTanks("WhatIsThis") -- Line 27
	  maintank = tanksTable[1]
	
	  -- Get values for tank capacity and amount
	  cap = maintank.capacity / 1000   -- in buckets
	  amount = maintank.amount    -- in millibuckets
	
	  -- If tank is empty, to avoid math issues with 0
	  if amount == nil then
	    amount = 0
	    percentfull = 0
	  else
	    -- Use math.floor to convert to integers
	    amount = math.floor(amount / 1000)
	    percentfull = math.floor(100 * amount / cap)
	  end
	
	  -- Self explanatory :)/>
	  mon.write(content)
	  mon.setCursorPos(1,2)
	  mon.write("Amount: " ..amount .."/"..cap .." B.")
	  mon.setCursorPos(1,3)
	  mon.write("Amount: " ..percentfull .."%  ")
	
	  -- Check for change since last loop 
	  if percentfull == lastpercent then
	    print("Still " ..percentfull .. "%, nothing sent.")
	  else
	    -- If value changed, send to main!
	    sendmsg = content ..": " ..percentfull .." %"
	    wmod.transmit(sendFreq,0,sendmsg)
	    print("Sent: " ..sendmsg)
	  end
	
	  -- Save for next loop
	  lastpercent = percentfull
	
	  -- Warning control, local lamp
	  mon.setCursorPos(1,5)
	
	  if percentfull < warning then
	    redstone.setOutput("right", true)
	    mon.write("Less than " ..warning .."% full")
	    sleep(1)
	    redstone.setOutput("right", false)
	    sleeptime = 1
	  else
	    -- Above warning level, sleep longer
	    mon.write("More than " ..warning .."% full")
	    sleeptime = 10
	  end
	
	  -- Sleep either 1 or 10 seconds
	  sleep(sleeptime)   
    end

Dog #2
Posted 17 September 2014 - 09:08 PM
Try changing "WhatIsThis" to "unknown" - that *might* fix it, otherwise you may need to specify a direction ("north", "south", "east", "west", "up", "down"). The only other things I can see that might be an issue are:

1. Is the device that val is being used to wrap actually on the back?
2. Is getTanks() a valid call?

If it's not one of those, I'll have to defer to one of the more seasoned pros…
Dragon53535 #3
Posted 17 September 2014 - 09:09 PM
More than likely getTanks() isn't a valid function, try using

for key,value in pairs(peripheral.getMethods("back")) do
  print(key.."   :   "..value)
end

Edit: half ninja'd
Edited on 17 September 2014 - 07:10 PM
iceman11a #4
Posted 17 September 2014 - 09:39 PM
Nothing worked. so I tried your idea Dragon, and I get only 2 options back.

getAdvanceMethodsData
listMethods.

Can you guys tell me what to do. I don't know what to do or how to use those commands or functions. I'm still learning.
ShadowDisruptor #5
Posted 17 September 2014 - 09:56 PM
Are you sure you have all the correct mods to use this script?
iceman11a #6
Posted 17 September 2014 - 10:09 PM
Hope. I'm not sure of any thing, I'm all so new to this. I fount this. It's an older tutorial. https://www.youtube.com/watch?v=X-owrYlGCXI

He didn't say any thing about any requirements. So maybe you can see some thing I didn't.
Lyqyd #7
Posted 18 September 2014 - 02:39 AM
If those are the only two methods the peripheral provides, there is an incompatibility somewhere, most likely in the versions of OpenP and the mod providing the tank. You would need versions of both mods that are intended to work together.
Cranium #8
Posted 18 September 2014 - 02:42 AM
with OpenP, tank information should be returned using peripheral.getTankInfo(). This would return the amount, capacity, and fluid name and rawname.
Bomb Bloke #9
Posted 18 September 2014 - 02:44 AM
Though he already established that function isn't available. Which likely has a lot to do with him using MC 1.7.10. Beta software, and all that.

As I was saying, you might consider using a comparator instead. It's either that or waiting for a ton of updates, or downgrading to something stable.
Dog #10
Posted 18 September 2014 - 02:49 AM
In my experience OpenP for 1.7.10 doesn't work with/support CC 1.64pr4
Edited on 18 September 2014 - 12:49 AM
iceman11a #11
Posted 18 September 2014 - 03:50 AM
OpenCCSensors is only version 1.6.4 of minecraft and I have the bata version of OpenP. It's beta all so. The problem is that they don't have a list of all the methods for the OpenP mod. It was a dream. I thought it would be great if i could monitor my tanks from the network control room.
Dragon53535 #12
Posted 18 September 2014 - 04:50 AM
Hope. I'm not sure of any thing, I'm all so new to this. I fount this. It's an older tutorial. https://www.youtube....h?v=X-owrYlGCXI

He did update the tutorial in another video 10 days ago, he also put it in the description of that video. https://www.youtube.com/watch?v=G24i4Lbtau0
iceman11a #13
Posted 18 September 2014 - 10:50 AM
Well it looks like he's using OpenP for MC 1.6.4. So maybe what I'm trying to do haven't been added in this version of OpenP. I see that the code was changed as it was in a earlier post. I still have the same problem on the same line. I get getting a nil value error

SO I'll have to check with openP and see just what they added and so. I'll have to contact the coders and see if i can find out just what's going on. I'll have to see if I can find an OpenP IRC chat room all so.

Guys, If any of you have an idea or 2, please let me know.
iceman11a #14
Posted 18 September 2014 - 11:33 AM
Here's what I fount,

OpenPeripheral 1.7 is not functional. We give no guarantee that unreleased snapshots are functional.

So I guess I'm screwed.
iceman11a #15
Posted 18 September 2014 - 07:43 PM
From what I have done and what I learned. That most of the openperipheral doesn't have more then 1/2 of what it should have. I should be able to use a chest and that doesn't seem to work all so. So I need a list of what openperipheral has and what it supports. If any one has some ideas please let me know. In the mean time I'm going to try the IRC chat channel and see if I can get some real help this time.
iceman11a #16
Posted 18 September 2014 - 10:31 PM
I didn't think to look at the configure file. There's 5 blocks.

glassesbridge – All ready been playing with this block
peripheralproxy
pim
sensor
ticketmachine

Can some one tell me how to use these in CC = Computercraft. using the lua code. Oh and how do I report bugs. I see that the ink is missing for the ticket machine.
Cranium #17
Posted 18 September 2014 - 11:02 PM
From what I've learned about OpenPeripheral for 1.7.10, it's non-functional as far as peripherals are concerned. I believe they're waiting on a stable release of ComputerCraft before they finish up those features. I just saw Dan200 work through some bug reports lately, so it's possible we may see a new pr5 version soon. With that, a new OpenPeripheral as well.
iceman11a #18
Posted 19 September 2014 - 05:10 AM
From what I saw in the config files. There's only 5 blocks that work. I been playing with them and trying to learn and it's not easy. It's just going to take a lot of time. Due to the fact that I can't find help with them, Here's a list of the 5 blocks openP does have working,

glasses bridge
peripheralproxy
pim
sensor
ticketmachine – This one the ink is missing. So I can't even play with it.
Bomb Bloke #19
Posted 19 September 2014 - 06:35 AM
Due to the fact that I can't find help with them,

If you haven't tried it already, give the docs script a go:

openp/docs <peripheralSide>

openp/docs <peripheralSide> <functionName>

ticketmachine – This one the ink is missing. So I can't even play with it.

I'd sorta expect it to take vanilla squid ink?
iceman11a #20
Posted 19 September 2014 - 12:00 PM
1) Thanks how ever, That doesn't give me samples on how to use the methods. That's where my problem is. I don't know what to do.

2) I'd sorta expect it to take vanilla squid ink? (I can't find any thing related to a vanilla squid ink)

I need to find some one that can help with some small samples. If I can monitor the pressure in a pipe. Then why can't I monitor the energy in a cable or conduit. See openp is limited on what it can do until a stable release of CC is released,

I was on irc chat last night until I2 midnight looking and no one wants to help. I been spending hours searching google for samples and only finding samples that are years old, and out dated. Let me show you some thing.


p = peripheral.wrap("back")
while true do
x = p.getPressure()
print("Current pressure " .. x)
if x < 4 then
rs.setOutput("right", true)
print("Pressure low, Starting Engines")
else
rs.setOutput("right", false)
end
sleep(5)
end

This small sample monitors the pressure in a pipe from the back. Well why can't I do the same thing with energy. I know there's a way to do it. I just haven't figured it out yet.

I want to be able to use the computer and monitor. I want to be able to use openp all so. Getting the info for the monitor is all ready online. The problem is that openp is not well documented with samples.

If you have any ideas please provide links.
Bomb Bloke #21
Posted 19 September 2014 - 03:10 PM
(I can't find any thing related to a vanilla squid ink)

Ink that is available in vanilla - that is to say, unmodified - versions of MineCraft. That is to say, OpenPeripheral doesn't add it because it's already there. This stuff. You get it by butchering squid.

Anyway. Regarding reading energy levels, let's recap:

1) Stick a computer next to a cell/tank/whatever, run openp/docs <side>.

2) If a function for getting storage levels of energy or whatever you want is listed: Great, use that. (Such functions are recognisable by their names.)

3) As has been established, you're unlikely to find such a function for a given storage block with your current installation.

If a suitable function isn't listed, then you cannot get the information you want while treating the target block as a peripheral, while using your current install. Period. Full stop. To try is to shove the proverbial square peg against the round hole. The only way to change that is to change your entire MineCraft set up - MC 1.6.4 supports the stable mod builds which actually have the functionality you want, 1.7.10 currently does not. The cutting edge is the bleeding edge, as they say.

So! With all that in mind, let's forget about using OpenPeripheral to get energy levels from whatever it is you're trying to read from under 1.7.10 for now and try using a comparator instead.

The comparator has lots of handy functions, but that which we're interested in is the one which sends out redstone signals of strength according to the volume stored in a given storage block. ComputerCraft, of course, has its own API for dealing with redstone. rs.getAnalogInput() is, of course, the function we're interested in for the purposes of reading a variable signal strength.

Stick a comparator between your computer and the block you want to try to "read". The side with the two prongs should be facing the target, the side with the single prong should face the computer. Set it to "comparator" mode (by right-clicking it until the single prong goes dark).

Open the Lua command prompt on your computer and enter:

rs.getAnalogInput("whatEverSideTheComparatorIsOn")

You'll get a number between 0 and 15. If the number is 0, and the target block has a decent amount of "stuff" in it, you can safely assume the mod author didn't rig his block to work with comparators. If you get something non-zero, well done, you can read levels from that block.

If you can't use comparators/redstone signals with your target blocks, and the peripheral path is out, then there really aren't any other options concerning ComputerCraft with those software versions. Try using different mods instead - make some BuildCraft gates, for example.