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

Having Problems with my Mining Program

Started by superbaconstrip, 28 November 2015 - 10:31 PM
superbaconstrip #1
Posted 28 November 2015 - 11:31 PM
I have just recently started to write a vertical mining program, but it seems to have a bug with the function that I've made to check the walls for ores that are worthwhile (i.e. iron, coal, diamond, etc.). In this version of the code I'm not able to even get it to mine iron ore. Here's the pastebin: http://www.pastebin.com/UCuHTLc8 (some of the comments are wrong due to them being added prior to this version and not being fixed yet). Thank you for your help!
Bomb Bloke #2
Posted 29 November 2015 - 01:48 AM
Take another look at the documentation for turtle.inspect(): It doesn't just return a string, it returns a boolean (indicating whether a block was found) followed by a table (contain information about that block, if one was present).

local function junk() --defines function
        local found, block = turtle.inspect()

        if found and block.name == "minecraft:iron_ore" then --determines if item is valuable
                turtle.dig()   
        end
end

To expand on what we consider "valuable", we might implement a lookup table of blocks we're interested in:

local treasure = {["minecraft:iron_ore"] = true, ["minecraft:gold_ore"] = true, ["minecraft:etc"] = true}

local function junk() --defines function
        local found, block = turtle.inspect()

        if found and treasure[block.name] then --determines if item is valuable
                turtle.dig()   
        end
end
Edited on 29 November 2015 - 02:40 AM
superbaconstrip #3
Posted 29 November 2015 - 03:26 AM
I'm now getting a return of "bios:14 [string "mine"]:3: '}' expected", but as far as my eyes can see, it's fine, so it must be somewhere else in the code, but I can't find it, so I don't really know what to do…
pastebin: http://www.pastebin.com/BwcKAajF
Bomb Bloke #4
Posted 29 November 2015 - 03:41 AM
My bad - I left out some square brackets, which I've now edited into my above post.
superbaconstrip #5
Posted 29 November 2015 - 03:48 AM
Thank you, it works perfectly now. So that means I'm going to mess it up even more to try and make it suit my needs as I don't play on vanilla usually! Again, thank you!