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

Recursive Mining

Started by Krasnogvardiech, 06 October 2014 - 04:41 AM
Krasnogvardiech #1
Posted 06 October 2014 - 06:41 AM
Hello, world and sundry. I've recently installed ComputerCraft to help out with RotaryCraft, as the two seem to synergize well together. On a less related note, I'm having a bit of trouble with the damnable turtles.

I'm trying to program a turtle to place down a gravel block and then break it apart for the purpose of harvesting Flint, a 1 in 10 chance. Then the turtle would suck up whichever item was dropped and place it back into the chest that it was next to. Entered the following code into the bugger as per the Turtle tutorial on the ComputerCraft wiki, but it doesn't appear to work.

The code is as follows:


if true do
   turtle.refuel(1)
   print ("Turtle Refuelled")
   if turtle.detect("false") then
	  print "Placing..."
	  sleep(0.5)
	  turtle.select(1)
	  turtle.place(1)
	  print "Block Placed"
	  sleep(0.5)
	  print "Breaking..."
	  turtle.dig()
	  print "Sucking..."
	  turtle.turnRight()
	  turtle.drop()
	  turtle.get(1)
	  turtle.turnLeft()
end

Lua coding was familiar; from back in the day with Warcraft 3's World Editor. Good times. Anyhoo, could anyone help me out with this? The thing's being uncooperative and non-responsive.
theoriginalbit #2
Posted 06 October 2014 - 08:55 AM
Can you please provide the link of the tutorial you got this from? it needs to be fixed immediately!

There are many useful tutorials in the Tutorials forum of these forums, you should probably prefer these over the ones on the Wiki as they're monitored closer for accuracy. One tutorial that could have been helpful is this one.

A list of problems:
  • if true do is not valid syntax, a valid if statement syntax is if [condition] then however you wish to loop, so it should be while true do
  • the next thing isn't a problem, but it is unnecessary, and that is all the calls to the sleep function, these could be removed to speed up the script
  • the last notable problem is there is no function turtle.get in the Turtle API
Edited on 06 October 2014 - 06:56 AM
Dragon53535 #3
Posted 06 October 2014 - 10:55 AM
Your code also does not have enough block closing statements (the word "end") at the end and thus will error out.

Onto the matter of where he found them, an intensive google search pulled up nothing.
Bomb Bloke #4
Posted 06 October 2014 - 11:09 AM
I'd assume he's saying he wrote this code; based on what he read in a tutorial.
YoYoYonnY #5
Posted 10 October 2014 - 09:01 PM
Another error:

if turtle.detect("false") then
This should be:

if turtle.detect() == false then
-- This might increase performance: if not turtle.detect() then