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

why will this not work?

Started by webb9, 16 August 2012 - 04:41 PM
webb9 #1
Posted 16 August 2012 - 06:41 PM
i found a cool excavating program and wanted to try it out but after 15 minutes of typing this into my mining turtle all that happened was that an error came up.

Here is the program:


local size = tonumber( tArgs[1] )
if size < 1 then
print( "Excavate radius must be positive" )
return
end

local depth = 0
local collected = 0
local xPos,zPos = 0,0
local xDir,zDir = 0,1
local function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
print( "Mined "..collected.." blocks." )
end

for n=1,9 do
if turtle.getItemCount(n) == 0 then
return true
end
end

print( "No empty slots left." )
return false
end
local function tryForwards()
while not turtle.forward() do
if turtle.dig() then
if not collect() then
return false
end
else
– give sand a chance to fall
sleep(0.8)
if turtle.dig() then
if not collect() then
return false
end
else
return false
end
end
end
xPos = xPos + xDir
zPos = zPos + zDir
return true
end
local function tryDown()
if not turtle.down() then
if turtle.digDown() then
if not collect() then
return false
end
end
if not turtle.down() then
return false
end
end
depth = depth + 1
if math.fmod( depth, 10 ) == 0 then
print( "Descended "..depth.." metres." )
end
return true
end
local function turnLeft()
turtle.turnLeft()
xDir, zDir = -zDir, xDir
end
local function turnRight()
turtle.turnRight()
xDir, zDir = zDir, -xDir
end
print( "Excavating…" )
local reseal = false
if turtle.digDown() then
reseal = true
end
local alternate = 0
local done = false
while not done do
for n=1,size do
for m=1,size-1 do
if not tryForwards() then
done = true
break
end
end
if done then
break
end
if n<size then
if math.fmod(n + alternate,2) == 0 then
turnLeft()
if not tryForwards() then
done = true
break
end
turnLeft()
else
turnRight()
if not tryForwards() then
done = true
break
end
turnRight()
end
end
end
if done then
break
end

if size > 1 then
if math.fmod(size,2) == 0 then
turnRight()
else
if alternate == 0 then
turnLeft()
else
turnRight()
end
alternate = 1 - alternate
end
end

if not tryDown() then
done = true
break
end
end
print( "Returning to surface…" )
– Return to where we started
while depth > 0 do
if turtle.up() then
depth = depth - 1
elseif turtle.digUp() then
collect()
else
sleep( 0.5 )
end
end
if xPos > 0 then
while xDir ~= -1 do
turnLeft()
end
while xPos > 0 do
if turtle.forward() then
xPos = xPos - 1
elseif turtle.dig() then
collect()
else
sleep( 0.5 )
end
end
end
if zPos > 0 then
while zDir ~= -1 do
turnLeft()
end
while zPos > 0 do
if turtle.forward() then
zPos = zPos - 1
elseif turtle.dig() then
collected = collected + 1
else
sleep( 0.5 )
end
end
end
while zDir ~= 1 do
turnLeft()
end
– Seal the hole
if reseal then
turtle.turnLeft(0)
turtle.turnLeft(0)
sleep( 0.5 )
turtle.drop()
sleep( 1.0 )
turtle.placeDown()
end
print( "Mined "..collected.." blocks total." )


and the error says attempt to compare __lt on nil and number



I tried looking for mistakes but it looked fine.

the program should act like a quarry and dig until finding something it cant dig and then going up and dumping its inventory at the top by an obsidian pipe.
LucasUK #2
Posted 16 August 2012 - 06:45 PM
thats the actual error message, not a number? The number is important.

PS I copied the code and it ran fine apart from the size variable.
webb9 #3
Posted 16 August 2012 - 06:49 PM
no that is what is said

p.s sorry about the layout of the coding it pasted wierdly
webb9 #4
Posted 16 August 2012 - 06:51 PM
i named the program d and at the start of the error it says d:2: but i thought that was just telling me the program going wrong.
is that the number you were talking about ( d:2:)
LucasUK #5
Posted 16 August 2012 - 06:52 PM
yeah sometimes, its usually the line number it fails on., ps i edited my post above to say it works except the size variable, I set it to 4 in the code (line 1) and its mining now. local size = 4
webb9 #6
Posted 16 August 2012 - 06:54 PM
how did you copy it?
LucasUK #7
Posted 16 August 2012 - 06:58 PM
ok to update, u missed a line similar to this Im guessing at the start of your code. correct?

local tArgs = { … }

I now get your error so will try to fix. , u got skype to chat on if u like by msg
LucasUK #8
Posted 16 August 2012 - 07:01 PM
ok lol.

To run the code, add that line I said to the top as line 1, and then you can run the code by typing the program and the width as a single command. Im not sure how it was meant to work.

local tArgs = { … }

i.e

d 3

Will make a 3 wide quarry.


Are you on Singleplyer or server? are you able to access the server world files if so?
webb9 #9
Posted 16 August 2012 - 07:03 PM
on singleplayer for testing but i was hopefully going to try it later on a server
webb9 #10
Posted 16 August 2012 - 07:04 PM
how do you copy the coding?
LucasUK #11
Posted 16 August 2012 - 07:06 PM
if you know where your .minecraft folder is?

Go to it, then to C:UsersLukeAppDataRoaming.minecraftmodsComputerCraftluarom

and you can edit the programs that are on every computer by default or add new ones. (Using notepad but then removing the file extensions)/


You can also go to the world save itself and look in the computer folder there to edit files unique to each computer. (It may be in the default "New World" save) You have to place the pc first and type ID to find which folder is each PC,
webb9 #12
Posted 16 August 2012 - 07:08 PM
: )
webb9 #13
Posted 16 August 2012 - 07:15 PM
it works but then halfway through it gives me an error.

thankyou about the copying. it is really useful
webb9 #14
Posted 16 August 2012 - 07:19 PM
thank you for all the help Lucas
LucasUK #15
Posted 16 August 2012 - 07:53 PM
Happy Coding :)/>/> ;)/>/> :P/>/> :D/>/> :)/>/> B)/>/> :(/>/> :wub:/>/> :)/>/>
webb9 #16
Posted 16 August 2012 - 08:43 PM
it works completely except for the fact that it doesn't empty its inventory i think there may be too many ends somewhere
Laserman34170 #17
Posted 17 August 2012 - 12:28 AM
The problem is that tArgs doesn't exist yet, and that you didn't use "shell.resolve" on the argument".

local tArgs = {...}
local size = tonumber(shell.resolve(tArgs[1]))
webb9 #18
Posted 17 August 2012 - 01:56 PM
this has the exact same effect as before.
Grim Reaper #19
Posted 17 August 2012 - 02:06 PM
How far did you attempt to dig down? I tried it with a 3 x 3 x 3 area (dig 3) and it completed with no issues whatsoever.