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

Computercraft,Pneumaticcraft Help

Started by Nesbro, 22 June 2014 - 10:17 PM
Nesbro #1
Posted 23 June 2014 - 12:17 AM
Trying to have my turtle interact with the pneumaticcraft air compressor to have it turn it off when it reaches a certain point in pressure and also have it refuel the compressor when it reaches to a certain amount. So that way I don't have to keep a constant eye on it. I am new to computer Craft so any help on how i should do this will be much appreciated! Thanks!
Edited on 22 June 2014 - 11:15 PM
KingofGamesYami #2
Posted 23 June 2014 - 02:56 PM
You want this page.

functions most likely to be used:

comp = peripheral.wrap( "side" ) --#wrap the compressor
comp.getPressure()  --#get the current pressure, can be compared directly or by storing in a variable
comp.getDangerPressure() --#get the dangerous pressure, could be compared to the getPressure() variable

Aside from this, you will also want to read up on loopsand if/then statements. You may also want to look at the term api if you want to display stuff.
Nesbro #3
Posted 25 June 2014 - 03:52 AM
Thanks! I ended up just using a simple command of detecting a redstone signal from the pressure Gauge tube. But now I will try what you told me to see if i can figure it out without using redstone, So that way i can have a smaller compact setup
Nesbro #4
Posted 25 June 2014 - 06:39 AM
Need more Help! I'm trying to get the turtle to detect the item count in slot 1 and if it equals to 0 i want it to suckDown to the chest below it and refill slot 1, but I can get it to grab the item below but it completely ignores the number of items in slot 1. It seems like its just ignoring everything but suckDown,
Bomb Bloke #5
Posted 25 June 2014 - 06:55 AM
Can't really comment on what you're doing wrong without seeing the code you're talking about.
KingofGamesYami #6
Posted 25 June 2014 - 03:59 PM
As Bomb Bloke said, we can't tell you what you are doing wrong without the code. However, here is a quick example of how to set up what (i think) you described:

if turtle.getItemCount( 1 ) < 1 then
  turtle.suckDown()
end
Nesbro #7
Posted 25 June 2014 - 05:39 PM
http://pastebin.com/4T9e8was

I want to replace the redstone signal part with the option of wrapping the air compressor but i cannot figure it out. Ive tried just wrapping the turtle with a monitor and air compressor but apparently im not doing it right. I dont have the wrapping code because i was only testing it. Thanks for your help
Edited on 25 June 2014 - 06:22 PM
KingofGamesYami #8
Posted 25 June 2014 - 10:10 PM
So, what I would change about that code…
Spoiler

local compressor = peripheral.wrap( "side" ) --#whatever side it is on, note that if the turtle ever moves the peripheral will need to be re-wrapped
local dPressure = compressor.getDangerPressure() --#get the danger pressure
while true do
   local pressure = compressor.getPressure() --#get the current pressure
   print("Compresser Pressure: "..pressure)
   if pressure <= dPressure / 2 then  --#if the pressure is too low, in this case if it is lower than the danger pressure divided by two
	  rs.setOutput ("left", true) --#sorry for weird formatting, the forums is derping on me ~.~
	  print("Refueling")
	  turtle.turnLeft()
	  turtle.drop(1)
	  turtle.turnRight() --#aha, turtle moved... we need to re-wrap the peripherals after turning
	  compressor = peripheral.wrap( "side" ) --#wrap again, because the connection was broken. (I have heard stuff about needing a sleep( 0 ) before it as well, but never confirmed myself)
  else
	  rs.setOutput("left", false)
  end
  turtle.select(1)
  if turtle.getItemCount(1) < 1 then
	 turtle.suckDown()
	 print("Need Coal..")
  end
  print ("Waiting 10 sec..")
  sleep (10)
end
Edited on 25 June 2014 - 08:14 PM
Nesbro #9
Posted 26 June 2014 - 12:21 AM
Awesome thanks! Ill rewrite the code now.

I think the main reason i couldn't figure it out, is because i wasn't to for sure what to put the Local as. But once you define the local everything else falls into place.
Nesbro #10
Posted 26 June 2014 - 12:39 AM
Hmmm "pressure:2: attempt to index ? (a nil value)" is what im getting. Advice on what I did wrong?

http://pastebin.com/nJmLCC3w
KingofGamesYami #11
Posted 26 June 2014 - 02:54 AM
The error states
1) your program is named pressure ("pressure:")
2) the error occured on line 2 (":2:")
3) something was nil (": attempt to index ? (a nil value)")

From this, I conclude one of these situations:
1) the peripheral.wrap("left") did not wrap a compressor
2) the compressor peripheral does not contain that function

I suggest using peripheral.getMethods("left") to see which of these two is correct.
Nesbro #12
Posted 26 June 2014 - 03:00 AM
Yeaa i was thinking that just didnt know how to correct it. Ill try it real fast.
Nesbro #13
Posted 26 June 2014 - 03:15 AM
Must not contain that function, its still telling me the same thing.

My program does not have to work the way I want it completely, just thought it would be nice to do something that i haven't seen before.
KingofGamesYami #14
Posted 26 June 2014 - 03:44 AM
I'm not sure you used the command correctly, it should give you a list of functions.
command prompt>lua
lua> peripheral.getMethods( "left" )
getPressure
getDangerPressure
etc.
>
Edited on 26 June 2014 - 01:45 AM
Bomb Bloke #15
Posted 26 June 2014 - 03:50 AM
From this, I conclude one of these situations:
1) the peripheral.wrap("left") did not wrap a compressor
2) the compressor peripheral does not contain that function

Half right. If the peripheral was correctly wrapped, but did not contain a function called "getDangerPressure", you'd get an "attempt to call nil".
KingofGamesYami #16
Posted 26 June 2014 - 03:52 AM
From this, I conclude one of these situations:
1) the peripheral.wrap("left") did not wrap a compressor
2) the compressor peripheral does not contain that function

Half right. If the peripheral was correctly wrapped, but did not contain a function called "getDangerPressure", you'd get an "attempt to call nil".
Oh, thanks for pointing that out. I guess the compressor can't wrap? I'll have to check that (watch this space)
Nesbro #17
Posted 26 June 2014 - 04:06 AM
Well dang…lol. Hey king if you look at the page you sent me about computercraft commands for pneumaticcraft it does mention that the getpressure() command only works on vacuum pumps currently, but i guess it really means it only works for that. But hopefully in future updates of pneumatic craft it will allow it to have more options with computercraft. It should would be nice because I learned a lot from you 2 about code just from the help provided. But I will be keeping a eye on this page just in case King happens to try it and gets it working.
Edited on 26 June 2014 - 02:06 AM
KingofGamesYami #18
Posted 26 June 2014 - 04:43 AM
Actually, the wiki states that command is available for all machines. It does say the compressor falls into that category, the wiki mentions the vacuum pump because it requires an additional parameter, due to the fact that it includes multiple pressures.

"…You can get the following info from any PneumaticCraft block that runs on compressed air (including the Air Compressor, Pressure Tube):
-getPressure(), getPressure(<side>) – Will get the pressure in the block. The side parameter is an optional parameter, and is currently only useful when getting the pressure from a Vacuum Pump, as it contains two different pressures.
-getDangerPressure() – This is a constant, it’ll be 5 bar for tier one machines, and 20 for tier two.
-getCriticalPressure() – This is a constant, it’ll be 7 bar for tier two machines, and 25 for tier two."