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

Turtle wont move

Started by Mickle23, 05 August 2015 - 10:25 PM
Mickle23 #1
Posted 06 August 2015 - 12:25 AM
Im trying to get my Advanced Wireless Mining Turtle to dig a staircase down to bedrock (im on flatlands at the moment but hopefully gonna introduce this to a normally generated world in the future), and I want it to stop once it inspects the bedrock below it…and after I tried for hours trying many different variations of this text I had to give up and come here as a last resort because I am new to lua and wanted to try and do it myself (I just started yesterday so sorry if this code is very badly written). When I figure this out i can continue to make it strip mine by myself I am just stuck at the moment.

The file is called 'MTStairs' and it is on a disk name 'Turtles' in my disk drive and my turtle should sit beside the disk drive until I say MTStairs after I change my directory to 'disk' but when I do that, it doesnt give me an error all it does is sit there doing nothing and I cant type anything and I have to terminate it. I did once let it sit there for about 5 minutes but still nothing happened and I still had to terminate it. If you could help it would be much appreciated.




local block, data = turtle.inspectDown()
local bottom, name = 'minecraft:bedrock'

function stop()
  if bottom then
	print('Block name: ', data.name)
	os.reboot()
  end
end

function refuel()
  if turtle.getFuelLevel() < 10 then
	turtle.select(1)
	turtle.refuel(1)
  end
end

function moving()
  turtle.dig()
  turtle.digDown()
  turtle.down()
  turtle.dig()
  turtle.forward()
end

function staircase()
  while moving() do
	stop()
	refuel()
  end
end

while true do
  staircase()
end
Lyqyd #2
Posted 06 August 2015 - 01:15 AM
Have you fueled the turtle? Your code has a couple other issues, but that would prevent it from moving at all.
safetyscissors #3
Posted 06 August 2015 - 03:52 AM
Hello Mickle and welcome to the cc forums.

Main issue, moving() doesnt return anything so its counted as false. so staircase()'s while loop doesnt run which you wrap in a while true. so its forever looping nothing. I suggest getting rid of staircase().

local isRunning = true
--// all your functions except staircase.

function refuel
end

function checkForBedrock()
end

function moving()
end

while isRunning do
  refuel()
  checkForBedrock()
  moving()
end

Next issue, stop() doesnt detect the bottom. Thats mainly because turtle.inspectDown() needs to be run each time it checks for bedrock so it needs to go inside the stop function. Also, we assign two variables here, "local success, block = turtle.inspectDown()" because that function returns two variables. When theres only one, we might use "local name = 'minecraft:block' "


function checkForBedrock()
  local success, blcok = turtle.inspectDown()
  if success == true and block.name == 'minecraft:bedrock' then
	--// return to the top code
	--// or to stop this loop,
	isRunning = false
  end
end
Mickle23 #4
Posted 06 August 2015 - 06:18 AM
Hello Mickle and welcome to the cc forums.

Main issue, moving() doesnt return anything so its counted as false. so staircase()'s while loop doesnt run which you wrap in a while true. so its forever looping nothing. I suggest getting rid of staircase().

local isRunning = true
--// all your functions except staircase.

function refuel
end

function checkForBedrock()
end

function moving()
end

while isRunning do
  refuel()
  checkForBedrock()
  moving()
end

Next issue, stop() doesnt detect the bottom. Thats mainly because turtle.inspectDown() needs to be run each time it checks for bedrock so it needs to go inside the stop function. Also, we assign two variables here, "local success, block = turtle.inspectDown()" because that function returns two variables. When theres only one, we might use "local name = 'minecraft:block' "


function checkForBedrock()
  local success, blcok = turtle.inspectDown()
  if success == true and block.name == 'minecraft:bedrock' then
	--// return to the top code
	--// or to stop this loop,
	isRunning = false
  end
end


local isRunning = true

function checkForBedrock()
  local success, block = turtle.inspectDown()
  if success == true and block.name == 'minecraft:bedrock' then
		isRunning = false
  end
end

function refuel()
  if turtle.getFuelLevel() < 10 then
	turtle.select(1)
	turtle.refuel(1)
  end
end

function moving()
  turtle.dig()
  turtle.digDown()
  turtle.down()
  turtle.dig()
  turtle.forward()
end

function refuel
end

function checkForBedrock()
end

function moving()
end

while isRunning do
  refuel()
  checkForBedrock()
  moving()
end

Im not sure if this is right and if it isnt could you maybe reply with what the whole thing should look like because I dont understand some things like

"function checkForBedrock()
end"
does that without anything in between the two lines do something?
Mickle23 #5
Posted 06 August 2015 - 06:31 AM
Have you fueled the turtle? Your code has a couple other issues, but that would prevent it from moving at all.

Yes, the turtle is fueled, when I first started the fueling was the first thing I wanted to get done, and in the process it sucked up a whole stack of coal instead of just one piece which it was intended to do…..oh…I just checked manually with the turtle.getFuelLevel() and it turned 0….just remembered I broke my old one so I could just place a new one by the disk drive instead of manually moving it with 'go up' 'go back' all the way to the top of the staircase….wow….
Lyqyd #6
Posted 06 August 2015 - 04:30 PM
If you label the turtle, it will retain its fuel level and any programs you've stored on it when you pick it up to move it.
safetyscissors #7
Posted 06 August 2015 - 06:49 PM
function checkForBedrock()
end

Sorry for the confusion. The lines like the above code are just a placeholder that does nothing. It was just an example of where you'd put your own code inside those functions. You should only have one function definition per name. I think it overwrites otherwise.
Your code is almost there.

Spoiler

local isRunning = true

function checkForBedrock()
  local success, block = turtle.inspectDown()
  if success == true and block.name == 'minecraft:bedrock' then
				isRunning = false
  end
end

function refuel()
  if turtle.getFuelLevel() < 10 then
		turtle.select(1)
		turtle.refuel(1)
  end
end

function moving()
  turtle.dig()
  turtle.digDown()
  turtle.down()
  turtle.dig()
  turtle.forward()
end

while isRunning do
  refuel()
  checkForBedrock()
  moving()
end
Mickle23 #8
Posted 06 August 2015 - 09:56 PM
function checkForBedrock()
end

Sorry for the confusion. The lines like the above code are just a placeholder that does nothing. It was just an example of where you'd put your own code inside those functions. You should only have one function definition per name. I think it overwrites otherwise.
Your code is almost there.

Spoiler

local isRunning = true

function checkForBedrock()
  local success, block = turtle.inspectDown()
  if success == true and block.name == 'minecraft:bedrock' then
				isRunning = false
  end
end

function refuel()
  if turtle.getFuelLevel() < 10 then
		turtle.select(1)
		turtle.refuel(1)
  end
end

function moving()
  turtle.dig()
  turtle.digDown()
  turtle.down()
  turtle.dig()
  turtle.forward()
end

while isRunning do
  refuel()
  checkForBedrock()
  moving()
end

It worked! thank you soo much for your help! Hopefully I can learn from this and continue on coding by myself but if I get stuck i know where to come! Anyways, Im gonna go see if I can get it to do a couple other things and hopefully it will work! Thanks again!

Have you fueled the turtle? Your code has a couple other issues, but that would prevent it from moving at all.
If you label the turtle, it will retain its fuel level and any programs you've stored on it when you pick it up to move it.

Thank you too, because I completely forgot to check the fuel level and I was so confused as to why it wouldnt move at all because it was moving before and then it just stopped, thanks! I now have 5 turtles all labelled individually based on what their purpose is (i.e. MiningTurtle)

Thank you two for all the help, I have a feeling I will be back soon, and one more question, if I get stuck on something else that doesnt have anything to do with this topic title (Turtle wont move) should I post again here? or make a new topic about that problem?
KingofGamesYami #9
Posted 06 August 2015 - 10:28 PM
Thank you two for all the help, I have a feeling I will be back soon, and one more question, if I get stuck on something else that doesnt have anything to do with this topic title (Turtle wont move) should I post again here? or make a new topic about that problem?

Typically, if it involves the same piece of code (even if it was edited), you should post in the same thread with the updated code and the new problem.

Otherwise, you should make a new topic.
Mickle23 #10
Posted 06 August 2015 - 11:02 PM
Typically, if it involves the same piece of code (even if it was edited), you should post in the same thread with the updated code and the new problem.

Otherwise, you should make a new topic.

ok, and if I just want advice? Say there is no problem I just want to ask for some tips or a little help figuring out how to do something?
KingofGamesYami #11
Posted 06 August 2015 - 11:07 PM
ok, and if I just want advice? Say there is no problem I just want to ask for some tips or a little help figuring out how to do something?

If it pertains to the OP, you could put it in this thread. Or you could make a new topic. I'm not an admin, but generally Lyqyd will merge threads or split posts if they should obviously be somewhere else.
Mickle23 #12
Posted 07 August 2015 - 06:40 AM
If it pertains to the OP, you could put it in this thread. Or you could make a new topic. I'm not an admin, but generally Lyqyd will merge threads or split posts if they should obviously be somewhere else.

oh ok good to know, thanks!