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

Need help with a redstone dig/place program

Started by Sparkyro, 19 May 2014 - 04:11 PM
Sparkyro #1
Posted 19 May 2014 - 06:11 PM
Total computercraft noob here.
I have been trying to make a program that places a block on redstone signal and digs it when there is none. But i don't even have a clue how to do it. So i wondred can someone make a simple program like that for me. So I can then use the code and try to learn the mod a bit more.
KingofGamesYami #2
Posted 19 May 2014 - 10:15 PM
1. look at turtle api
2. look at redstone api
3. look at os.pullEvent functions
4. look at loops
augustas656 #3
Posted 19 May 2014 - 11:17 PM

side = "side" --turtle side, right / left / back / front / bottom / top
while true do
os.pullEvent("redstone")
  if redstone.getInput(side, true) then
  turtle.place()
  elseif redstone.getInput(side, false) then
  turtle.dig()
  end
end
This program will only dig or place blocks when the redstone signal changes, so if you switch it on, it will place a block, but then won't place ever again until the redstone changes. Then if the redstone switches to stop it will break the block and won't do anything until the redstone changes.


side = "side"
while true do
  if not turtle.detect() and redstone.getInput(side, true) then
  turtle.place()
  elseif turtle.detect() and redstone.getInput(side, false) then
  turtle.dig()
  end
end
This program will constantly place blocks if there is a redstone signal and a free space, and will constantly dig blocks if there is no redstone signal and there's a block to be broken. This program cycles through very often, and if it crashes from a java error, after the first end put a sleep(0), this fixes a specific error when nothing happens for too long after cycling many many times.

Make sure to replace the side in between the double-text quotes "side" to whatever side your turtle is facing, where it's right / left / up / bottom / front / back.

Regards,
Augustas
Sparkyro #4
Posted 20 May 2014 - 11:11 AM
Thx for the help
CCGrimHaxor #5
Posted 20 May 2014 - 11:38 AM
Here you go

If(rs.getInput(side_here)) --check if we are getting a redstone signal
turtle.place() --place the block if we have a redstone signal
Else --if we don't have a signal
turtle.dig() --dig the block
End --end the if statment

Where it says side_here replace it with your side.
Sparkyro #6
Posted 20 May 2014 - 01:11 PM
CCGrimHaxor when i try using yours i get
[string "startup"]:4: '='
expected
CometWolf #7
Posted 20 May 2014 - 04:57 PM
He capitalized if, else and end. Im guessing he posted it from his phone lol.