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

How Would I Do This Code?

Started by TyDoesMC, 06 August 2013 - 08:52 PM
TyDoesMC #1
Posted 06 August 2013 - 10:52 PM
Hello I Need Help Making a Rabbit Hole Miner And Wanted To Know If This Little Bit Of Code Will Work? I Cant Test It, Unfortunately.



--[[ Testing ]]--
turtleReady = false
-----------------------------
function shouldRefuel()
if turtle.getFuelLevel() < 64 then
print("Refueling, Please Wait a Minute...")
sleep(2)
turtle.refuel( 10 )
print("Turtle Refueled!")
sleep(1)
turtleReady = true
end
function checkReady()
if turtle.down() == false then
turtleReady = false
end
function goDown()
shouldRefuel()
print("Going Down!")
while turtleReady = true do
turtle.digDown()
turtle.down()
end
Yevano #2
Posted 06 August 2013 - 11:53 PM
I formatted your code with indentation. Notice that the indentations don't go back to being on the first column, because of forgotten end tokens. Aside from that, line 20 is a syntax error because you are not allowed to do an assignment inside of expressions. You probably meant to use == instead of =. Instead, you can just get rid of the comparison since turtleReady == true evaluates to the same value as simply turtleReady.

--[[ Testing ]]--
turtleReady = false
-----------------------------
function shouldRefuel()
	if turtle.getFuelLevel() < 64 then
		print("Refueling, Please Wait a Minute...")
		sleep(2)
		turtle.refuel( 10 )
		print("Turtle Refueled!")
		sleep(1)
		turtleReady = true
	end
	function checkReady()
		if turtle.down() == false then
			turtleReady = false
		end
		function goDown()
			shouldRefuel()
			print("Going Down!")
			while turtleReady = true do
				turtle.digDown()
				turtle.down()
			end

I Cant Test It, Unfortunately.
So far, this seems to be the case with most of the code you've posted on the forums, at least from the posts of yours I've seen. Why can't you test it? Even if you can't run Minecraft, there are multiple options as far as emulators go.
subzero22 #3
Posted 07 August 2013 - 12:03 AM
Ok for one your not ending your funtions and loops. you have your function and then you got your loop which both need ends. as in here's how you have your functions and then how they should be.


function goDown()
  shouldRefuel()
  print("Going Down!")
  while turtleReady = true do
  turtle.digDown()
  turtle.down()
end

function goDown()
  shouldRefuel()
  print("Going Down!")
	 while turtleReady = true do
	   turtle.digDown()
	   turtle.down()
	 end
end

Anther thing I noticed is you have functions but nothing to call the functions. Also on your top part of the code it looks as if you wanted an else there but never put one. I think even if it didn't refuel it would still go down even if it had less than 64.


function shouldRefuel()  
   if turtle.getFuelLevel() < 64 then
	 print("Refueling, Please Wait a Minute...")
	 sleep(2)
	 turtle.refuel( 10 )
	 print("Turtle Refueled!")
	 sleep(1)
   else
	 turtleReady = true
   end
end

I'm not sure how deep you want the turtle to go but if you want the turtle to go down to bedrock lvl then this is how I would write it. I normally play on tekkit so don't use refuel part much so I'm sure you can put that part in. here's the code for the turtle to just dig down then return back up. I've used a code like this before to make a ladder system to bedrock but I also had added parts that are taken out so it's simpler for ya.


x = 0

if turtle.detectDown() == true then
turtle.digDown()
end

-- turtle digging down part
while turtle.down() do
turtle.digDown()
x = x + 1
end

-- turtle returning to top part
for i=1,x do
turtle.up()
end

print("Went " ..x.. " blocks down to bedrock")
TyDoesMC #4
Posted 07 August 2013 - 04:18 PM
What Do You Mean? Where Would I Test It?
TyDoesMC #5
Posted 07 August 2013 - 04:21 PM
Ok for one your not ending your funtions and loops. you have your function and then you got your loop which both need ends. as in here's how you have your functions and then how they should be.


function goDown()
  shouldRefuel()
  print("Going Down!")
  while turtleReady = true do
  turtle.digDown()
  turtle.down()
end

function goDown()
  shouldRefuel()
  print("Going Down!")
	 while turtleReady = true do
	   turtle.digDown()
	   turtle.down()
	 end
end

Anther thing I noticed is you have functions but nothing to call the functions. Also on your top part of the code it looks as if you wanted an else there but never put one. I think even if it didn't refuel it would still go down even if it had less than 64.


function shouldRefuel()  
   if turtle.getFuelLevel() < 64 then
	 print("Refueling, Please Wait a Minute...")
	 sleep(2)
	 turtle.refuel( 10 )
	 print("Turtle Refueled!")
	 sleep(1)
   else
	 turtleReady = true
   end
end

I'm not sure how deep you want the turtle to go but if you want the turtle to go down to bedrock lvl then this is how I would write it. I normally play on tekkit so don't use refuel part much so I'm sure you can put that part in. here's the code for the turtle to just dig down then return back up. I've used a code like this before to make a ladder system to bedrock but I also had added parts that are taken out so it's simpler for ya.


x = 0

if turtle.detectDown() == true then
turtle.digDown()
end

-- turtle digging down part
while turtle.down() do
turtle.digDown()
x = x + 1
end

-- turtle returning to top part
for i=1,x do
turtle.up()
end

print("Went " ..x.. " blocks down to bedrock")


if turtle.detectDown() == true then
turtle.digDown()
end

It Would Currupt Its Self, Meaning It Wouldent Be Able To Go Up Because Bedrock Gets Detected (As Far as I Know)
TyDoesMC #6
Posted 07 August 2013 - 04:23 PM
Ok So I Finished It Last Nigh B/c No One Was Answering.
It Might Not Work Can You Tell Me Whats Wrong With It,
Also I Made It Have The Functions Call Each Other In a Chain.

link: http://pastebin.com/bF44jEy4