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

Turtle help

Started by Expenox, 16 December 2012 - 12:26 PM
Expenox #1
Posted 16 December 2012 - 01:26 PM
Anyone help me I'm trying to make a turtle lumberjack but there is a error I ran into

The error is: bios:338: [string "lumberjack"]:8:
'<eof>' expected
Spoiler

local function checkFuel()
  if turtle.getFuelLevel() <1 then
	turtle.select(1)
	turtle.refuel(1)
	print("Refueled and Ready to go!")
  end
end
end
local function Tree()
  if turtle.detect() then
	turtle.select(16)
	if turtle.compare(true) then
	  turtle.dig()
	  turtle.forward()
	  if turtle.detectUp() then
		turtle.digUp()
		else
		turtle.select(15)
		turtle.place()
	  end
   end
end	
local function move()
  turtle.forward()
  turtle.forward()
  turtle.forward()
end
while not turtle.detectUp() do
  checkFuel()
  turtle.up()
end
turtle.forward()
turtle.forward()
turtle.forward()
-- Moves turtle forward 3 times.
turtle.turnLeft()
-- Turns turtle left
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
-- Gets it close to the tree
checkFuel()
turtle.down()
turtle.turnRight()
-- Checks to see if it has enough fuel
turtle.forward()
turtle.forward()
tree()
Help please!
theoriginalbit #2
Posted 16 December 2012 - 01:52 PM
please don't forget to post the error so that you can get help quicker :)/>
theoriginalbit #3
Posted 16 December 2012 - 01:57 PM
This will only use one item from the stack to put into fuel, if you want to do more then put the stack amount, if you want a whole stack just have an empty call

turtle.refuel(1)

turtle.compare() does not have any parameters, it will return true or false

if turtle.compare(true) then

so unless the error was related to that ^^^ I can't see whats wrong until I see the error.
Expenox #4
Posted 16 December 2012 - 01:59 PM
This will only use one item from the stack to put into fuel, if you want to do more then put the stack amount, if you want a whole stack just have an empty call

turtle.refuel(1)

turtle.compare() does not have any parameters, it will return true or false

if turtle.compare(true) then

so unless the error was related to that ^^^ I can't see whats wrong until I see the error.
And if I cant use true, then how can I get it to not destroy the sapling and only the wood?
theoriginalbit #5
Posted 16 December 2012 - 02:03 PM
This will only use one item from the stack to put into fuel, if you want to do more then put the stack amount, if you want a whole stack just have an empty call

turtle.refuel(1)

turtle.compare() does not have any parameters, it will return true or false

if turtle.compare(true) then

so unless the error was related to that ^^^ I can't see whats wrong until I see the error.
It returns a boolean therefore it can have true false etc.
And if I cant use true, then how can I get it to not destroy the sapling and only the wood?

Just because it returns a boolean doesn't mean it can have a boolean parameter.
select the slot the sapling is and then have
if not turtle.compare() then
that will make sure that only when it isnt a sapling that it will destroy it


as for the error you have one too many ends after the checkFuel() function. and you are missing an end for the if compare() statement
Expenox #6
Posted 16 December 2012 - 02:08 PM
This will only use one item from the stack to put into fuel, if you want to do more then put the stack amount, if you want a whole stack just have an empty call

turtle.refuel(1)

turtle.compare() does not have any parameters, it will return true or false

if turtle.compare(true) then

so unless the error was related to that ^^^ I can't see whats wrong until I see the error.
It returns a boolean therefore it can have true false etc.
And if I cant use true, then how can I get it to not destroy the sapling and only the wood?

Just because it returns a boolean doesn't mean it can have a boolean parameter.
select the slot the sapling is and then have
if not turtle.compare() then
that will make sure that only when it isnt a sapling that it will destroy it


as for the error you have one too many ends after the checkFuel() function. and you are missing an end for the if compare() statement
How should it look then?
Expenox #7
Posted 16 December 2012 - 02:10 PM
I did this

local function checkFuel()
  if turtle.getFuelLevel() <1 then
		turtle.select(1)
		turtle.refuel(1)
		print("Refueled and Ready to go!")
  end
end
local function Tree()
  if turtle.detect() then
		turtle.select(16)
		if not turtle.compare() then
		  turtle.dig()
		  turtle.forward()
		  if turtle.detectUp() then
				turtle.digUp()
				else
				turtle.select(15)
				turtle.place()
		  end
	end
end	
local function move()
  turtle.forward()
  turtle.forward()
  turtle.forward()
end
while not turtle.detectUp() do
  checkFuel()
  turtle.up()
end
turtle.forward()
turtle.forward()
turtle.forward()
-- Moves turtle forward 3 times.
turtle.turnLeft()
-- Turns turtle left
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
-- Gets it close to the tree
checkFuel()
turtle.down()
turtle.turnRight()
-- Checks to see if it has enough fuel
turtle.forward()
turtle.forward()
tree()
Is that right?
Don't worry about spacing this thing spaces it weird.
theoriginalbit #8
Posted 16 December 2012 - 02:13 PM
still missing the end to close the if not turtle.comapre() then statement


yes the indenting is annoying when copy/paste to here! and from here!
Expenox #9
Posted 16 December 2012 - 02:15 PM
still missing the end to close the if not turtle.comapre() then statement


yes the indenting is annoying when copy/paste to here! and from here!
So putting a end in the middle of my function wont mess it up?

still missing the end to close the if not turtle.comapre() then statement


yes the indenting is annoying when copy/paste to here! and from here!
So putting a end in the middle of my function wont mess it up?
And is it just one end or two?
theoriginalbit #10
Posted 16 December 2012 - 02:15 PM
just one end missing by the looks of it
Expenox #11
Posted 16 December 2012 - 02:18 PM
just one end missing by the looks of it
Thank you so much!
But now there is a problem, but I think i knowit
It needs to be a while loop and not a if
so it goes all the way up then down
But is there a way when it goes down from chopping the tree down to make it plant a sapling other then just moving on?
theoriginalbit #12
Posted 16 December 2012 - 02:20 PM
your welcome.

yep :)/>
Expenox #13
Posted 16 December 2012 - 02:32 PM
your welcome.

yep :)/>

Another problem, when it does the first part of the tree
i get the error: Lumberjack:51: attempt to call nill

Code:

local function checkFuel()
  if turtle.getFuelLevel() <1 then
	turtle.select(1)
	turtle.refuel(10)
	print("Refueled and Ready to go!")
  end
end
local function Tree()
checkFuel()
  if turtle.detect() then
	turtle.select(15)
	if not turtle.compare() then
	  turtle.dig()
	  turtle.forward()
   end
	  while turtle.detectUp() do
		turtle.digUp()
	  end
   end
end	
local function move()
  turtle.forward()
  turtle.forward()
  turtle.forward()
end
while not turtle.detectUp() do
  checkFuel()
  turtle.up()
end
turtle.forward()
turtle.forward()
turtle.forward()
-- Moves turtle forward 3 times.
turtle.turnLeft()
-- Turns turtle left
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
-- Gets it close to the tree
checkFuel()
turtle.down()
turtle.turnRight()
-- Checks to see if it has enough fuel
turtle.forward()
turtle.forward()
Tree()

Move()

Tree()

So on while turtle.detectUp() do I get the nil I belive
Expenox #14
Posted 16 December 2012 - 05:47 PM
Any help?
theoriginalbit #15
Posted 16 December 2012 - 05:55 PM
oh sorry didn't see the notification.

turtle.detectUp() or any or the detects return a boolean value.
Dlcruz129 #16
Posted 16 December 2012 - 05:57 PM
Lua is cAsE-sEnSiTiVe. You defined move(), then called Move().
Expenox #17
Posted 16 December 2012 - 06:52 PM
Lua is cAsE-sEnSiTiVe. You defined move(), then called Move().
I understand that but it still should have gone up and atleast harvested the tree it just digs the tree goes forward digs the one above it and gets the error
Expenox #18
Posted 16 December 2012 - 07:00 PM
Lua is cAsE-sEnSiTiVe. You defined move(), then called Move().
That fixed the error but now instead of stopping and going up to mine one whole tree just mines the one then one above and moves on, help?
It's a while do loop so it should go all the way up then back down
Expenox #19
Posted 16 December 2012 - 07:34 PM
Fixed it, was a problem in the code.
Expenox #20
Posted 16 December 2012 - 07:52 PM
Thanks everyone!