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

Retrieving a Boolean from A Turtle Function

Started by Maximombro, 17 June 2013 - 08:36 AM
Maximombro #1
Posted 17 June 2013 - 10:36 AM
I'm making some Self Replicating turtles and am having trouble with retrieving a success/fail from the "turtle.craft()" function.
The program is giving me errors on line 18 saying, "an '=' was expected."
Here is my code:

function  cftComp()
  turtle.up() -- Pane Start
  turtle.turnLeft()
  turtle.suck()
  turtle.transferTo(2, 1)
  turtle.transferTo(3, 1)
  turtle.transferTo(4, 1) -- Extra piece for slot 1
  turtle.transferTo(5, 1)
  turtle.transferTo(6, 1)
  turtle.transferTo(7, 1)
  turtle.select(1)
  turtle.drop()
  turtle.select(4)
  turtle.transferTo(1, 1)
  turtle.select(1)
  local compCraft = turtle.craft()
  compCraft
if compCraft == false then -- *cough* Line 18 *cough*
  print("Pane Crafting Has Failed")
  print("Retrieving Pane")
  turtle.select(2)
  turtle.transferTo(1, 64)
  turtle.select(3)
  turtle.transferTo(1, 64)
  turtle.select(5)
  turtle.transferTo(1, 64)
  turtle.select(6)
  turtle.transferTo(1, 64)
  turtle.select(7)
  turtle.transferTo(1, 64)
  turtle.select(1)
  turtle.drop()
  turtle.up()
  turtle.suck()
  turtle.transferTo(10,1)
  turtle.drop()
  print("Pane Retrieved")
else
  print("Panes Crafted")
  turtle.up()
  turtle.transferTo(10, 1) -- Prepairs to craft computer
  turtle.drop() -- Pane End
end
  turtle.down() -- Smooth Stone Start
  turtle.turnRight()
  turtle.suck()
  turtle.transferTo(2, 1)
  turtle.transferTo(3, 1)
  turtle.transferTo(4, 1) -- Extra piece for slot 1
  turtle.transferTo(5, 1)
  turtle.transferTo(7, 1)
  turtle.transferTo(9, 1)
  turtle.transferTo(11, 1)
  turtle.select(1)
  turtle.drop()
  turtle.select(4)
  turtle.transferTo(1, 1) -- Smooth Stone End
  turtle.turnRight() -- Redstone Start
  turtle.up()
  turtle.suck()
  turtle.select(4)
  turtle.transferTo(6,1)
  turtle.drop() -- Redstone End
  turtle.select(6)
  turtle.craft(1) -- Computer To Slot 6
  turtle.down()
  turtle.down()
  turtle.turnLeft()
  turtle.select(1)
end
Lyqyd #2
Posted 17 June 2013 - 02:09 PM
Split into new topic.

Okay, you got the boolean result back from the turtle.craft function, that's fine. But what is the next line supposed to do? You just put `compCraft` there all by itself, so the Lua interpreter thinks you're going to assign it a new value (hence the "= expected" error), but you don't. Are you trying to print it? You should use print, if so. print(compCraft) would do.
Bomb Bloke #3
Posted 17 June 2013 - 06:23 PM
Note that the reason the interpretor complains about line 18 is because it starts with an "if", instead of the "=" symbol that's expected. Lua reads the statement that starts on line 17 as going along the lines of "compCraft if compCraft == false then", which indeed makes no sense. Finishing line 17 properly (eg by shoving the variable into a print function) will allow it to read line 18 as a new statement.

Keep this in mind - sometimes the line Lua is pointing out to you can be well away from the error you've actually made.
Maximombro #4
Posted 18 June 2013 - 09:59 AM
Thanks you two, I managed to get it working quite simply with the print function.