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

[SOLVED] Auto Builder Not Working

Started by ultiomos, 13 September 2012 - 09:35 PM
ultiomos #1
Posted 13 September 2012 - 11:35 PM
My auto builder script isn't working and I was hoping I could get some help. When I try to run the program it throws an error for line 6, "then expected". I don't see what's wrong, but I am a beginner at this. Any help would be appreciated!


local haveblocks = 0
local block = 0
Check = function()
block = turtle.detect()
if block = true then
   turtle.turnLeft()
   block = turtle.detect()
   if block = true then
	turtle.turnLeft()
	turtle.turnLeft()
	block = turtle.detect()
	if block = true then
	 block = turtle.detectUp()
	 if block = true then
	  break
	 else
	  turtle.up()
	  turtle.placeDown()
	  turtle.turnLeft()
	  turtle.forward()
	  Check()
	 end
	end
   end
end
end
while true do
for i = 1,16 do
   haveblocks = turtle.getItemCount(i)
   if haveblocks = 0 then
	turtle.select(i+1)
   end
end
Check()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
end
OmegaVest #2
Posted 13 September 2012 - 11:38 PM
For if statements, you need two ='s for comparisons. Unless you are doing ~=, >= or <=.
Cranium #3
Posted 13 September 2012 - 11:39 PM
You need to do "==" instead of "=" when evaluating a variable. So anytime you do if x then, the operator is "==". This means "evaluates equal".
ProTip:
If you are doing an if x == true, you can drop the "==true", since it is read the same way. For example, you would do "if block then". For false, you would do "if not block then".

EDIT: Ninja'd
Edited on 13 September 2012 - 09:39 PM
ultiomos #4
Posted 13 September 2012 - 11:44 PM
Thanks to both of you! It works fine now.
Lyqyd #5
Posted 14 September 2012 - 01:03 AM
If you are doing an if x == true, you can drop the "==true", since it is read the same way. For example, you would do "if block then". For false, you would do "if not block then".

This is not actually true.


if x then

Is the same as:


if x ~= false and x ~= nil then