Jump to content




Having Problems with my Mining Program


  • You cannot reply to this topic
4 replies to this topic

#1 superbaconstrip

  • Members
  • 3 posts

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!

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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 by Bomb Bloke, 29 November 2015 - 03:40 AM.


#3 superbaconstrip

  • Members
  • 3 posts

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

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 29 November 2015 - 03:41 AM

My bad - I left out some square brackets, which I've now edited into my above post.

#5 superbaconstrip

  • Members
  • 3 posts

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users