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

Program runs and ends without doing functions

Started by protexxi, 10 December 2013 - 04:33 PM
protexxi #1
Posted 10 December 2013 - 05:33 PM
heres the code

function mine()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.turnRight()
times = times + 1
rednet.send(1, "Tunnel is: " ..times" Blocks long")
end
function Empty()
for i=2,9 do
  turtle.select(i)
  turtle.dropDown()
end
end
function refuel()
print ("Please Put Ender Chest In slot 1")
rednet.open(Right)
while true do
turtle.getfuellevel(level)
if level >200 then
refuel()
rednet.send(1, "Refuelling... ")
else
rednet.send(1, "mining... ")
mine()
Empty()
end
end
end

dose not return any errors just runs then ends without moving
awsmazinggenius #2
Posted 10 December 2013 - 05:37 PM
Please indent your code. There are obvious mistakes in your code, such as rednet.open("right") (MUST be a string), and turtle.getFuelLevel (MUST be properly capitalized). I'm not sure about the functions however.
protexxi #3
Posted 10 December 2013 - 05:46 PM
Iv corrected the caps yet still fails


function mine()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.turnRight()
times = times + 1
rednet.send(1, "Tunnel is: " ..times" Blocks long")
end
function Empty()
for i=2,9 do
turtle.select(i)
turtle.dropDown()
end
end
function refuel()
print ("Please Put Ender Chest In slot 1")
rednet.open(Right)
while true do
turtle.getFuelLevel(level)
  if level >200 then
  refuel()
  rednet.send(1, "Refuelling... ")
   else
   rednet.send(1, "mining... ")
   mine()
   Empty()
  end
end
end

the end from the last function is missing and the whole function is missing


function refuel()
shell.run(refuel(2))
print ("Please Put Ender Chest In slot 1")
rednet.open(Right)
while true do
turtle.getFuelLevel(level)
  if level >200 then
  refuel()
  rednet.send(1, "Refuelling... ")
   else
   rednet.send(1, "mining... ")
   mine()
   Empty()
  end
end
end


should fix it?
Edited on 10 December 2013 - 04:44 PM
protexxi #4
Posted 10 December 2013 - 05:54 PM
fixed it however says

rednet:14: invalid side
oeed #5
Posted 10 December 2013 - 06:14 PM
You're using a variable, not string for the side.

rednet.open(Right)
--should be
rednet.open('right')

Also, I don't think you can use EnderChests. Unless you are using the mod of course.
Edited on 10 December 2013 - 05:19 PM
protexxi #6
Posted 10 December 2013 - 06:14 PM
i am using the modded chest
MR_nesquick #7
Posted 10 December 2013 - 06:33 PM
" turtle.getFuelLevel(level) " should be " level = turtle.getFuelLevel() "
awsmazinggenius #8
Posted 10 December 2013 - 06:45 PM
You're using a variable, not string for the side.

rednet.open(Right)
--should be
rednet.open('right')

Also, I don't think you can use EnderChests. Unless you are using the mod of course.
I have already stated this.

Iv corrected the caps yet still fails


function mine()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnLeft()
turtle.turnLeft()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.turnRight()
times = times + 1
rednet.send(1, "Tunnel is: " ..times" Blocks long")
end
function Empty()
for i=2,9 do
turtle.select(i)
turtle.dropDown()
end
end
function refuel()
print ("Please Put Ender Chest In slot 1")
rednet.open(Right)
while true do
turtle.getFuelLevel(level)
  if level >200 then
  refuel()
  rednet.send(1, "Refuelling... ")
   else
   rednet.send(1, "mining... ")
   mine()
   Empty()
  end
end
end

the end from the last function is missing and the whole function is missing


function refuel()
shell.run(refuel(2))
print ("Please Put Ender Chest In slot 1")
rednet.open(Right)
while true do
turtle.getFuelLevel(level)
  if level >200 then
  refuel()
  rednet.send(1, "Refuelling... ")
   else
   rednet.send(1, "mining... ")
   mine()
   Empty()
  end
end
end


should fix it?

When did I say that it would fix it? I also said something about indentation. Here is an indented version:

function mine()
  turtle.dig()
  turtle.forward()
  turtle.digUp()
  turtle.digDown()
  turtle.turnLeft()
  turtle.dig()
  turtle.forward()
  turtle.digUp()
  turtle.digDown()
  turtle.turnRight()
  turtle.turnRight()
  turtle.forward()
  turtle.dig()
  turtle.forward()
  turtle.digUp()
  turtle.digDown()
  turtle.turnLeft()
  turtle.turnLeft()
  turtle.turnRight()
  turtle.forward()
  turtle.turnRight()
  turtle.turnRight()
  times = times + 1
  rednet.send(1, "Tunnel is: " ..times" Blocks long")
end
function Empty()
  for i=2,9 do
    turtle.select(i)
    turtle.dropDown()
  end
end
function refuel()
  print ("Please Put Ender Chest In slot 1")
  rednet.open(Right)
  while true do
    turtle.getFuelLevel(level)
    if level >200 then
	  refuel()
	  rednet.send(1, "Refuelling... ")
    else
	  rednet.send(1, "mining... ")
	  mine()
	  Empty()
    end
  end
end
civilwargeeky #9
Posted 12 December 2013 - 08:01 PM
I'm sorry, but did I miss where someone told him that he wasn't calling any functions?

In this code as far as I have seen it, all you are doing is "declaring" functions. Doing this just makes a function that you can use later, it doesn't run it.
So you have
function doStuff()
  turtle.dig()
  turtle.forward()
end
But this doesn't actually do anything. This however
function doStuff()
  turtle.dig()
  turtle.forward()
end

doStuff() --This is "calling" the function
Will make the turtle dig, then move forward.

That is why your program isn't doing anything. Declaring functions doesn't run them, it just puts them there for you to use later.

Here is a more in depth tutorial if you want: http://computercraft...Function_(type)
Edited on 12 December 2013 - 07:02 PM