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

Error: bios:338: [string "Harvest"]:4: '(' expected

Started by GareBear, 06 December 2012 - 03:16 PM
GareBear #1
Posted 06 December 2012 - 04:16 PM
This is my first time using functions and, for the life of me, I can not figure out what is wrong with my code. Unless I'm going crazy, the 4 means the 4th line of code, and I most certainly have a ( there.


x = 0
function noTree
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
end
function harvest
turtle.dig()
turtle.forward()
repeat
  turtle.digUp()
  turtle.up()
  x = x + 1
until turtle.compareUp() == false
repeat
  turtle.down()
  x = x - 1
until x == 0
turtle.digDown()
turtle.forward()
end
function harvestStone
turtle.select(13)
if turtle.compare() then
  harvest
else
  noTree
end
end
function harvestDirt
turtle.select(14)
if turtle.compare() then
  harvest
else
  noTree
end
end
function harvestCobble
turtle.select(15)
if turtle.compare() then
  harvest
else
  noTree
end
end
function harvestWood
turtle.select(16)
if turtle.compare() then
  harvest
else
  noTree
end
end
harvestStone
harvestDirt
harvestCobble
harvestWood
faubiguy #2
Posted 06 December 2012 - 04:20 PM
When writing a function, the function name (after "function") needs to have a list of parameters in () like when your calling a function. If the function doesn't use any arguments, just use () like when you're calling a function without arguments (such as "turtle.forward()").

For example:
function example()
  -- Do stuff
end
GareBear #3
Posted 06 December 2012 - 04:23 PM
Wow. Well, I'm not too bright then. It works now. Thank you very much, faubiguy.