11 posts
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.
64 posts
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.
11 posts
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
11 posts
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:)
64 posts
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
11 posts
Posted 16 August 2012 - 06:54 PM
how did you copy it?
64 posts
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
64 posts
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?
11 posts
Posted 16 August 2012 - 07:03 PM
on singleplayer for testing but i was hopefully going to try it later on a server
11 posts
Posted 16 August 2012 - 07:04 PM
how do you copy the coding?
64 posts
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,
11 posts
Posted 16 August 2012 - 07:08 PM
: )
11 posts
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
11 posts
Posted 16 August 2012 - 07:19 PM
thank you for all the help Lucas
64 posts
Posted 16 August 2012 - 07:53 PM
Happy Coding :)/>/> ;)/>/> :P/>/> :D/>/> :)/>/> B)/>/> :(/>/> :wub:/>/> :)/>/>
11 posts
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
34 posts
Location
Programming Land
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]))
11 posts
Posted 17 August 2012 - 01:56 PM
this has the exact same effect as before.
504 posts
Location
Seattle, WA
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.