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

[Lua][Question][Turtle][1.4] Fueled turtle turns, but won't move.

Started by Lettuce, 13 August 2012 - 06:10 AM
Lettuce #1
Posted 13 August 2012 - 08:10 AM
*First post, if I messed up somewhere in the guidelines (too many tags?), I'm sorry.

My CC version is 1.4, the turtle is fueled. That's the first thing I checked. The program is designed to clear a user-specified area, so that it's easier to build on. No more hunting down plains biomes for me! …If it worked. The turtle asks for the size of the area, then turns left, as per instruction. It then looks stubbornly at the horizon, too good to clear land for me like a common turtle. Seal and clear functions work, moveForward does not, apparently. However, I've used that function before, for gravel in the mines. Here's my code:


function moveForward()
   repeat
   turtle.dig()
   until turtle.forward() == true
end

function seal()
   if turtle.detectDown() == false then
   turtle.select(1)
   turtle.placeDown()
   end
end

function clear()
   while turtle.detectUp() == true do
   turtle.digUp()
   turtle.up()
   end
	  repeat
	  turtle.down()
	  until turtle.detectDown == true
end


-- setting variables
local f = turtle.getFuelLevel()
f = tostring(f)
print "Dirt in slot 1, fuel in 16."
print "How wide is the foundation? (x)"
   local x = io.read()
   x = tonumber(x)
print "How long is the foundation? (y)"
   local y = io.read()
   y = tonumber(y)
print "Fuel Level:"
print(f)

turtle.turnLeft()
n = x/2
-- n is half of x, used only in the first loop.
for a=1,n do
	if turtle.getFuelLevel() <= 10 then
		turtle.select(16)
		turtle.refuel(1)
   end
   seal()
	  if turtle.detectDown() == false then
	  break
	  end
   clear()
   moveForward()
end
   turtle.turnLeft()
   turtle.turnLeft()
-- main loop
for i=1,y do
   for b=1,x do
	  print "Fuel Level:"
	  print(f)
		 if turtle.getFuelLevel() <= 10 then
		 turtle.select(16)
		 turtle.refuel(1)
		 end
	  seal()
		 if turtle.detectDown() == false then
		 break
		 end
	  clear()
	  moveForward()
   end
	  turtle.turnLeft()
	  moveForward()
	  turtle.turnLeft()
   for c=1,x do
	  print "Fuel Level:"
	  print(f)
		  if turtle.getFuelLevel() <= 10 then
		  turtle.select(16)
		  turtle.refuel(1)
		  end
	  seal()
		 if turtle.detectDown() == false then
		 break
		 end
	  clear()
	  moveForward()
   end
	 turtle.turnRight()
	 moveForward()
	 turtle.turnRight()
   for d=1,x do
	  print "Fuel Level:"
	  print(f)
			if turtle.getFuelLevel() <= 10 then
			turtle.select(16)
	   	 turtle.refuel(1)
			end
	  seal()
		 if turtle.detectDown() == false then
		 break
		 end
	  clear()
	  moveForward()
   end
end

Any help/tips for the future will be greatly appreciated, thank you in advance. :P/>/>
filipkwro #2
Posted 13 August 2012 - 09:06 AM
Try going to %appdata%/minecraft/config/Mod_CCTurtle.cfg (on linux: /home/username/.minecraft/config) and change

#MLProp : turtlesNeedFuel (int:1,>=0,0,<=1,0)
(...)
turtlesNeedFuel=1
to

#MLProp : turtlesNeedFuel (int:0,>=0,0,<=1,0)
(...)
turtlesNeedFuel=0
Cranium #3
Posted 13 August 2012 - 03:04 PM
I don't think that repeat exists within lua…
If you want a loop, use one of the loops available within lua. You can use a while/do loop, or a for/do loop. I'm not sure about any others though.
Lyqyd #4
Posted 13 August 2012 - 03:42 PM
I don't think that repeat exists within lua…
If you want a loop, use one of the loops available within lua. You can use a while/do loop, or a for/do loop. I'm not sure about any others though.

Repeat loops are just fine. While he does have an unnecessary comparison to true, that function should work fine.
Cranium #5
Posted 13 August 2012 - 03:47 PM
I don't think that repeat exists within lua…
If you want a loop, use one of the loops available within lua. You can use a while/do loop, or a for/do loop. I'm not sure about any others though.

Repeat loops are just fine. While he does have an unnecessary comparison to true, that function should work fine.
So the command "repeat" exists? I was not aware of that… The more I learn, the more I realize how much I don't know… :P/>/>
Lyqyd #6
Posted 13 August 2012 - 03:51 PM
I don't think that repeat exists within lua…
If you want a loop, use one of the loops available within lua. You can use a while/do loop, or a for/do loop. I'm not sure about any others though.

Repeat loops are just fine. While he does have an unnecessary comparison to true, that function should work fine.
So the command "repeat" exists? I was not aware of that… The more I learn, the more I realize how much I don't know… :P/>/>

Yes, repeat/until loops are used in lua, in the manner OP is using them.
Grim Reaper #7
Posted 13 August 2012 - 04:52 PM
Although I am not totally sure as to why your turtle refuses to move, I did see one minor LUA error in your code.

On the last line in your clear function,

until turtle.detectDown == true
You forgot the parenthesis at the end of turtle.detectDown, since it is a function call.

until turtle.detectDown() == true
-- Also, you don't have to check if the function returns true with a comparison operator.
-- You could try this:
-- until turtle.detectDown()
-- The above yields the same result. As for false you could use the 'not' keyword.
-- until not turtle.detectDown()

Once you fix that, (and reexamine your code for any other errors we might have missed), if your turtle still won't move then I would suggest perhaps re-installing the mod after backing up the files you wrote, of course.

Hope I helped! :P/>/>
Lettuce #8
Posted 13 August 2012 - 07:37 PM
Thanks a lot, guys!

Craniumkid, repeat loops are used when you want it to run before checking if the condition is met, while is used if you want to do it after checking. In my case, where it really didn't matter, I used repeat so it's easier to type, I forget or misplace 'do,' with 'then' pretty often, repeat/until doesn't require it, I need only tell it the condition to meet. That can make a difference though, depending on the program, so I hope that helps you later. I use that particular function for clearing gravel/sand without messing up the rectangle, since it will keep digging until it moves forward. Even if you step in front of it, the turtle mines the same way.

Grim Reaper, I feel like an idiot now. Those parenthesis were the whole problem, the program runs fine after I fixed it. Thank you for the tip on not using comparison operators, that helped me clean up my code, I will do that in the future, I wasn't aware you could do that.

This community is awesome. I hope I can get better at coding, and help everyone out, too.
On a side note, my program is simple, but useful. Should I post it on the programs page, or should I bother? I personally never got any programs from that page, so I don't know how advanced they should be.
Grim Reaper #9
Posted 14 August 2012 - 02:18 AM
I am very glad I could help. I would be happy to answer any questions you have; PM those questions if you'd like :P/>/>

You can post any program to the forums. These can be from simple locks to Operating Shells, as long as you had fun making it I am sure someone will give you some comments or learn from your code. In the end, it is very much worth it to post things to the forums because of the feedback and due to the fact your could could have helped someone with a break through,