Jump to content




Turtle wont move

turtle lua

11 replies to this topic

#1 Mickle23

  • Members
  • 6 posts

Posted 05 August 2015 - 11:25 PM

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


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 06 August 2015 - 12:15 AM

Have you fueled the turtle? Your code has a couple other issues, but that would prevent it from moving at all.

#3 safetyscissors

  • Members
  • 24 posts

Posted 06 August 2015 - 02: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


#4 Mickle23

  • Members
  • 6 posts

Posted 06 August 2015 - 05:18 AM

View Postsafetyscissors, on 06 August 2015 - 02:52 AM, said:

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?

#5 Mickle23

  • Members
  • 6 posts

Posted 06 August 2015 - 05:31 AM

View PostLyqyd, on 06 August 2015 - 12:15 AM, said:

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....

#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 06 August 2015 - 03: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.

#7 safetyscissors

  • Members
  • 24 posts

Posted 06 August 2015 - 05:49 PM

View Postsafetyscissors, on 06 August 2015 - 02:52 AM, said:

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


#8 Mickle23

  • Members
  • 6 posts

Posted 06 August 2015 - 08:56 PM

View Postsafetyscissors, on 06 August 2015 - 05:49 PM, said:

View Postsafetyscissors, on 06 August 2015 - 02:52 AM, said:

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

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!

View PostLyqyd, on 06 August 2015 - 12:15 AM, said:

Have you fueled the turtle? Your code has a couple other issues, but that would prevent it from moving at all.

View PostLyqyd, on 06 August 2015 - 03:30 PM, said:

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?

#9 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 06 August 2015 - 09:28 PM

View PostMickle23, on 06 August 2015 - 08:56 PM, said:

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.

#10 Mickle23

  • Members
  • 6 posts

Posted 06 August 2015 - 10:02 PM

View PostKingofGamesYami, on 06 August 2015 - 09:28 PM, said:

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?

#11 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 06 August 2015 - 10:07 PM

View PostMickle23, on 06 August 2015 - 10:02 PM, said:

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.

#12 Mickle23

  • Members
  • 6 posts

Posted 07 August 2015 - 05:40 AM

View PostKingofGamesYami, on 06 August 2015 - 10:07 PM, said:

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users