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

Help! Program wont work

Started by jell0zz, 10 October 2012 - 02:26 PM
jell0zz #1
Posted 10 October 2012 - 04:26 PM
Hey guys,

I'm very new to the computercraft mod and i've tried to get this branchmining script to work, i got it from this site: http://www.punchwood.com/index.php?/topic/5192-tekkit-computercraft/ (if linking is forbidden i'll edit it out) but I just cant get it to work…


height = 2  
length = 10
lengthCount = 0
heightCount = 1
function digHeight()
turtle.dig()
turtle.forward()
lengthCount = lengthCount + 1
while heightCount < height do
turtle.digUp()
turtle.up()
heightCount = heightCount + 1
end
while heightCount > 1 do
turtle.down()
heightCount = heightCount - 1
end
end
while lengthCount < length do
digHeight()
end
turtle.turnLeft()
digHeight()
digHeight()
digHeight()
turtle.turnLeft()
lengthCount = 0
while lengthCount < length do
digHeight()
end
turtle.turnLeft()
digHeight()
digHeight()
digHeight()


So the problem i've been experiencing is the return: branchmine:19: attempt to compare __lt on nil and nil

Any idea what i've been doing wrong?

-Jell0zz
Cozzimoto #2
Posted 10 October 2012 - 05:10 PM
instead of using while loops, just use for loops. they are more easily maintained and you can pass how long you want your tunnel straight into the program with the tArgs{ … } method which is a table with the program arguments that you type after the program.

example would be gps host 234 45 748 where gps is the program and tArgs[1] is host, tArgs[2] would be 234 and so on and so forth
jell0zz #3
Posted 10 October 2012 - 05:49 PM
instead of using while loops, just use for loops. they are more easily maintained and you can pass how long you want your tunnel straight into the program with the tArgs{ … } method which is a table with the program arguments that you type after the program.

example would be gps host 234 45 748 where gps is the program and tArgs[1] is host, tArgs[2] would be 234 and so on and so forth

I'm really new to this xD how would that look like?

All coding i've done is some basic HTML and CSS web pages xD
Cozzimoto #4
Posted 10 October 2012 - 05:56 PM
here is a snippet for the turtle to go down and make a tunnel of your length you describe when you call the program
so if you call this program test, the program to run it and dig a tunnel thats 15 long would look like [test 15]
you can name it what ever you like. but for the turtle to return, you would just have to add the code for him to turn around and run the for loop once more.

and if you want you can add another argument to make side tunnels for however long you make the original tunnel, but lets first focus on getting the turtle to do one thing at a time.


tArgs = { ... }

function digHeight()
  turtle.dig()
  turtle.digUp()
  turtle.forward()
end

for i=1,tArgs[1] do
  digHeight()
end
jell0zz #5
Posted 10 October 2012 - 06:49 PM
here is a snippet for the turtle to go down and make a tunnel of your length you describe when you call the program
so if you call this program test, the program to run it and dig a tunnel thats 15 long would look like [test 15]
you can name it what ever you like. but for the turtle to return, you would just have to add the code for him to turn around and run the for loop once more.

and if you want you can add another argument to make side tunnels for however long you make the original tunnel, but lets first focus on getting the turtle to do one thing at a time.


tArgs = { ... }

function digHeight()
  turtle.dig()
  turtle.digUp()
  turtle.forward()
end

for i=1,tArgs[1] do
  digHeight()
end

i'll have a look at it.

On a sidenote, how far from the player can the turtle go without despawning?
Cozzimoto #6
Posted 10 October 2012 - 06:51 PM
if you dont have a chunkloader i believe the turtle can go 16 blocks out safely, but i may be wrong on that it could be greater.
slango20 #7
Posted 11 October 2012 - 12:46 AM
Turtles don't despawn, they unload, like farm animals