Posted 12 September 2015 - 01:48 AM
Hey there all.
I'm a newbie, not only to ComputerCraft, but also to coding in general, so my work posted below will probably be of a very poor standard. But I am interested to learn, so any assistance you could give me would be greatly appreciated, thank you. I've done a lot of research on the wiki, on tutorial videos on Youtube, and reading through code snippets on this forum, and I've already learned a great deal. However I would ask that you try and make replies to this thread nice and simple, so I can understand them better, and if possible explain the logic behind them so that I can comprehend just how and why the code is working as it does.
EDIT: This first issue has now been solved, however as I progress I'm constantly running into errors which I may need assistance with. I'll be adding them to this thread as they arise, please check my last few posts here for the latest info..
=====
Old issue:
Onto my problem: I'm trying to write a mining code for a Turtle, to make it dig vertical columns from surface to bedrock, digging out any ores it finds on the way (I'm aware there are already many programs out there that do this, but as I said I want to learn how to do these codes myself). So far the Turtle will pickup fuel from a chest, then start digging down, refueling itself and picking up ores on the way. The problem is when it hits bedrock, it does not trigger the 'retstart()' function to return to the surface - instead it simply gets stuck in a loop spinning around and around at bedrock level, constantly checking the blocks around it over and over. It does not throw an error, just repeats the actions indefinitely.
Here's the code I have so far. I hope it isn't too long to post on the forum - if it is let me know and I'll host the file on Dropbox or somewhere instead. Also I hope the indentation is okay…like I said, newbie ;)/>
I'd be greatful for any aid you could give, thanks in advance.
~Burger
I'm a newbie, not only to ComputerCraft, but also to coding in general, so my work posted below will probably be of a very poor standard. But I am interested to learn, so any assistance you could give me would be greatly appreciated, thank you. I've done a lot of research on the wiki, on tutorial videos on Youtube, and reading through code snippets on this forum, and I've already learned a great deal. However I would ask that you try and make replies to this thread nice and simple, so I can understand them better, and if possible explain the logic behind them so that I can comprehend just how and why the code is working as it does.
EDIT: This first issue has now been solved, however as I progress I'm constantly running into errors which I may need assistance with. I'll be adding them to this thread as they arise, please check my last few posts here for the latest info..
=====
Old issue:
Onto my problem: I'm trying to write a mining code for a Turtle, to make it dig vertical columns from surface to bedrock, digging out any ores it finds on the way (I'm aware there are already many programs out there that do this, but as I said I want to learn how to do these codes myself). So far the Turtle will pickup fuel from a chest, then start digging down, refueling itself and picking up ores on the way. The problem is when it hits bedrock, it does not trigger the 'retstart()' function to return to the surface - instead it simply gets stuck in a loop spinning around and around at bedrock level, constantly checking the blocks around it over and over. It does not throw an error, just repeats the actions indefinitely.
Here's the code I have so far. I hope it isn't too long to post on the forum - if it is let me know and I'll host the file on Dropbox or somewhere instead. Also I hope the indentation is okay…like I said, newbie ;)/>
Spoiler
local posx = 0
local posy = 0
local posz = 0
local column = 0
local row = 0
local turn = 0
local invfull = false
local bed = false
local notores = {
"minecraft:dirt",
"minecraft:stone",
"minecraft:bedrock",
"minecraft:gravel",
"minecraft:cobblestone",
"minecraft:torch",
"minecraft:chest",
"minecraft:grass",
}
local function restock()
if turtle.getItemCount(16) <= 10 then
turtle.select(16)
turtle.suck(50)
end
end
local function fuel()
if turtle.getFuelLevel() < 10 then
turtle.select(16)
turtle.refuel(1)
end
end
local function invcheck()
if turtle.getItemCount(15) > 0 then
invfull = true
end
end
local function look()
for i=1,4 do
local success, data = turtle.inspect()
if success then
if data.name == notores[1] then
elseif data.name == notores[2] then
elseif data.name == notores[3] then
elseif data.name == notores[4] then
elseif data.name == notores[5] then
elseif data.name == notores[6] then
elseif data.name == notores[7] then
elseif data.name == notores[8] then
print("Nothing detected.")
else
print("Ore detected. Mining...")
turtle.dig()
end
end
turtle.turnRight()
turn = turn + 1
invcheck()
end
end
local function digdown()
look()
if turtle.detectDown() then
local bedcheck, data = turtle.inspectDown()
if bedcheck then
if data.name == notores[3] then
print("Bedrock detected. Quarry column complete.")
bed = true
else
turtle.digDown()
turtle.down()
invcheck()
fuel()
posz = posz + 1
end
end
else
turtle.down()
invcheck()
fuel()
posz = posz + 1
end
end
local function retstart()
while posz > 0 do
turtle.up()
posz = posz - 1
end
end
restock()
fuel()
if bed == false then
while invfull == false do
print("Inventory is not full")
digdown()
end
else
retstart()
end
I'd be greatful for any aid you could give, thanks in advance.
~Burger
Edited on 12 September 2015 - 05:56 PM