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

trying to get a 9by9 program running

Started by slango20, 28 September 2012 - 11:38 PM
slango20 #1
Posted 29 September 2012 - 01:38 AM
my code:
for x = 1, 9 do
   print("Current Status: "..x)
while x = < 9 do
   if turtle.detectDown() == true then
      turtle.placeDown()
      x = x+1
   end
if x = 9 do
   turtle.turn right
   x = 1
end

(the final end just for testing)
error:bios:206: [string "9by9"]:3: 'do' expected
where is this missing 'do'?
Lettuce #2
Posted 29 September 2012 - 01:49 AM
This may be the problem: you ended the second "if" with "do," not "then." And it's turtle.turnRight().

The first while loop has an incorrect operator, there's no space between <= and they must be in that order.

Hope that fixes it, if I can nitpick some more, I'll let you know. Lua isn't as finnicky as it sounds, but it is a scripting language, you must be specific.

–Lettuce

*edit P.S. "if turtle.detectDown() == true then" works the same as "if turtle.detectDown() then" you don't have to specify true, it assumes you mean true, unless you specify otherwise, so it can be done with less typing. To say the equivalent of "== false" say "if not –stuff then"

P.S.S. You never ended the first "for" loop. I count 3 that need an "end," but only see 2.
Doyle3694 #3
Posted 29 September 2012 - 12:25 PM
actually, 2 loops arn't ended.
slango20 #4
Posted 30 September 2012 - 02:42 AM
ok, new code, different problem
for x = 1, 9 do
   print("Current Status: "..x)
end
while x < 9 do
   if turtle.detectDown() == true then
      turtle.placeDown()
 turtle.forward()
      x = x+1
   end
end
if x == 9 then
   turtle.turnRight()
   x = 1
end

problem, prints all status at once (1-9), cant seem to get an error that I can understand, any problems?
also, anyone know where I can get eloraam's mining turtle armada code?
Pharap #5
Posted 30 September 2012 - 03:22 AM
ok, new code, different problem
for x = 1, 9 do
   print("Current Status: "..x)
end
while x < 9 do
   if turtle.detectDown() == true then
	  turtle.placeDown()
turtle.forward()
	  x = x+1
   end
end
if x == 9 then
   turtle.turnRight()
   x = 1
end

problem, prints all status at once (1-9), cant seem to get an error that I can understand, any problems?
also, anyone know where I can get eloraam's mining turtle armada code?

This bit of code here:

for x = 1, 9 do
   print("Current Status: "..x)
end
Is a single loop. It goes through the ' print("Current Status: "..x)' line 9 times, with x being different each time.
So what you want is probably this:

while x < 9 do
   if turtle.detectDown() ~= true then
	  turtle.placeDown()
turtle.forward()
	  x = x+1
   end
 print("Current Status: "..x)
end
I would also like to point out that detectDown returns true if there is a block underneath the turtle, therefore placing a block underneath wont work because there's already a block there.
Thus I have replaced == (is equal to) with ~= (is not equal to) so that the code now translates loosely as 'if turtle does not detect a block below, turtle places block'

Though I still fail to see what this program is attempting to achieve.
Perhaps if you gave a better description of your intentions you'd get better feedback, since at the moment, I don't know about other people but I'm clutching at straws trying to figure out what you are trying to do. Something about 9s and digging?
slango20 #6
Posted 30 September 2012 - 03:53 AM
for one, building automated 9x9 houses via turtle, and keep getting this in the console
9by9:1: attempt to compare __lt on nil and number
while x < 9 do
   if turtle.detectDown() == false then
         turtle.placeDown()
turtle.forward()
         x = x+1
   end
   print("Current Status: "..x)
end
if x == 9 then
   turtle.turnRight()
   x = 1
end

Pharap #7
Posted 30 September 2012 - 04:12 AM
for one, building automated 9x9 houses via turtle, and keep getting this in the console
9by9:1: attempt to compare __lt on nil and number
while x < 9 do
   if turtle.detectDown() == false then
		 turtle.placeDown()
turtle.forward()
		 x = x+1
   end
   print("Current Status: "..x)
end
if x == 9 then
   turtle.turnRight()
   x = 1
end


Did you remember to assign x before using it?
slango20 #8
Posted 02 October 2012 - 12:34 AM
DUURP! major derp on my part, will see if that fixes it
EDIT: fixes that error, now it does nothing, constantly going through an infinite loop, while doing nothing

x = 1
while x < 9 do
   if turtle.detectDown() == false then
	  turtle.placeDown()
  turtle.forward()
		 x = x+1
   print("Current Status: "..x)
   end
end
if x == 9 then
   turtle.turnRight()
   x = 1
end
KillaVanilla #9
Posted 02 October 2012 - 01:55 AM
DUURP! major derp on my part, will see if that fixes it
EDIT: fixes that error, now it does nothing, constantly going through an infinite loop, while doing nothing

x = 1
while x < 9 do
   if turtle.detectDown() == false then
	  turtle.placeDown()
  turtle.forward()
		 x = x+1
   print("Current Status: "..x)
   end
end
if x == 9 then
   turtle.turnRight()
   x = 1
end

You forgot to make the loop increment x.

ooops I need to read code better.

Okay, from what I can tell, this code will only do something if there is empty space below the turtle. Are you sure that this is intended? If so, are you sure that you're testing this code somewhere that has only empty space?
slango20 #10
Posted 02 October 2012 - 02:16 PM
Derp, forgot about the else statement, will try tonight, in school right now
Pharap #11
Posted 02 October 2012 - 08:50 PM
Ok, try this:


local x = 1 --Assign X
for x = 1,9 do -- everything in this loop will be done 9 times
  --(x starts at 1 and gains 1 at the end of each cycle and the loop continues until x is 9)
  if turtle.detectDown() == false then -- if the turtle doesnt detect a block below
		  turtle.placeDown()  -- the turtle places a block
  end -- end the if
   turtle.forward() --turtle moves forward regardless of whether it detects a block or not
   print("Current Status: "..x) --status is also printed regardlessly
end
turtle.turnRight() -- after moving forward 9, the turtle turns right


I'm still not sure what it is you are trying to do, but I'm guessing that's closer to what you are trying to achieve
slango20 #12
Posted 02 October 2012 - 10:29 PM
thanks for the help, still tweaking it a bit to try to get it to go 9 blocks then stop, currently it will do 9 blocks placed ten moved, more helpful would be an already made 9x9 program, for bulding direwolf20's famous 9by9s
Pharap #13
Posted 05 October 2012 - 04:05 AM
thanks for the help, still tweaking it a bit to try to get it to go 9 blocks then stop, currently it will do 9 blocks placed ten moved, more helpful would be an already made 9x9 program, for bulding direwolf20's famous 9by9s

That's easy to do:

local x = 1 --Assign X
for x = 1,8 do -- everything in this loop will be done 9 times
  --(x starts at 1 and gains 1 at the end of each cycle and the loop continues until x is 8)
  if turtle.detectDown() == false then -- if the turtle doesnt detect a block below
				  turtle.placeDown()  -- the turtle places a block
  end -- end the if
   turtle.forward() --turtle moves forward regardless of whether it detects a block or not
   print("Current Status: "..x) --status is also printed regardlessly
end
if turtle.detectDown() == false then -- if the turtle doesnt detect a block below
				  turtle.placeDown()  -- the turtle places a block
  end -- end the if
print("Current Status: "..x) --status is also printed regardlessly
turtle.turnRight() -- after moving forward 9, the turtle turns right

They aren't as famous as you think, I've never heard of them.
Do you mean a 9x9 square of blocks on the ground?
Or are you looking for a 9x9 wall?
These things are important, computers are stupid and need very specific instructions before they can do things (and turtles are just computers that move,arguably they are even stupider).