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

"Help with turtle program"

Started by hctcboy, 06 February 2013 - 11:33 AM
hctcboy #1
Posted 06 February 2013 - 12:33 PM
I want to get some help with debugging a turtle program i got from direwolf20 (if you saw season 5 episode 24 of his series). Here is the program:

local location = ""
function teleport()
   tp = peripheral.wrap("bottom")
   tp.teleport()
end
function checkFull()
   greader = peripheral.wrap("right")
   data = greader.get()
   while not data["Full Energt"] do
	  sleep(2)
	  data=greader.get()
   end
   turtle.dig()
end
function checkEmpty()
   greader=peripheral.wrap("right")
   data = greader.get()
   while not data["No Energy"] do
	  sleep(2)
	  data = greader.get()
   end
   turtle.dig()
end
function checkLoc()
   loc = turtle.detectUp()
   if loc == true then
	  print("I am at the quarry")
	  location = "Quarry"
   else
	  print("I am at the charge station")
	  location = "Charging"
   end
end
function getFuel()
   turtle.turnRight()
   for i = 1, 9 do turtle.forward() end
   turtle.turnLeft()
   for i = 1, 6 do turtle.forward() end
   turtle.suck()
   turtle.refuel()
   turtle.turnLeft()
   turtle.turnLeft()
   for i = 1, 6 do turtle.forward() end
   turtle.turnRight()
for i = 1, 9 do turtle.forward() end
   turtle.turnRight()
end

function checkFuel()
   fuel = turtle.getFuelLevel()
   print("My fuel level:"..tostring(fuel))
   if fuel < 2500 then
	  print("I need fuel")
	  getFuel()
	  print("My fuel level:"..tostring(turtle.getFuelLevel()))
   end
end

checkLoc()
if location == "Quarry" then
   turtle.turnRight()
   turtle.place()
   checkEmpty()
   teleport()
else
   turtle.turnRight()
   turtle.forward()
   turtle.forward()
   turtle.place()
   checkFuel()
   checkFull()
   turtle.turnLeft()
   turtle.turnLeft()
   turtle.forward()
   turtle.forward()
   teleport()
end
On the line that says "function getFuel()" it says im missing an =. Any help would be great :)/>
ChunLing #2
Posted 08 February 2013 - 10:31 AM
Please use edit to open the program as it appears on the turtle where you're trying to run it. Navigate to the line that gave the error. Copy that exact line out, exactly as it appears there (use rCtrl+C so as to not open the exit menu), and paste that here. Also, while you're at it, check the lines above if to see if any of them are misspelled or whatever.
hctcboy #3
Posted 09 February 2013 - 08:13 AM
i've checked thoroughly, and i am convinced that it is not a typo. Do you see any problems with the code itself though? (specifically on the getFuel() function)
Engineer #4
Posted 09 February 2013 - 09:32 AM
How did you installed this, Did you type it over? Did you copy it from pastebin?
Maybe your version of CC (wich I dont think wich is the issue, since I assume you are DW20 pack from FTB)

Try reinstalling. Otherwise we need a little bit more info
JokerRH #5
Posted 09 February 2013 - 11:46 AM
By the way, you know that you have a typo in line 9 where it says "Full energy"? Maybe that is another problem …:)/>
ChunLing #6
Posted 09 February 2013 - 08:43 PM
That would probably be a problem on runtime, but the syntax error being thrown by the interpreter is not for this code. Go into edit, get that exact line and the line previous (which is just an end), and post them exactly as they appear in your program.

If you are on a local world, then open the file directly with a text editor (out of game) and post the contents. The code you have posted does not produce the error you report. Post the code that does produce the error you report, and you have a chance of someone being able to explain how to fix it.