I use this function in one of my programs. it does the following.
1: mines a block
2: mines column of falling blocks
3: pulls one slot of items from an inventory (if present)
4: Sucks up entities on the ground.
5: attacks a player/mob that gets in it's way (if present)
6: it also counts it's actions, I have those set in certain variables, so there are things in here that call other functions that you don't need to worry about.
This might be a bad way to do this. I have fiddled with this code many times, I recently had to format my HDD and reinstall windows, so I don't know if this is my latest version. But as far as I know it's functional.
also I have been preoccupied so it's been awhile since I've seen this program.
local function checkdig()
[indent=1]x = 0[/indent]
[indent=1]attacknumber = 0 -- counts the amount of turtle.attack() actions[/indent]
[indent=1]if turtle.detect() == true then -- checks for block[/indent]
[indent=2]if turtle.suck() == true then -- checks for an inventory with something in it, if nothing is in the inventory, it will mine[/indent]
[indent=3]lastbutton = "got an item from inventory" -- think of last button as a print(). It's called elsewhere. [/indent]
[indent=3]infoget = false -- think of this as another print()[/indent]
[indent=2]elseif turtle.detect() and turtle.dig() == true then [/indent]
[indent=3]x = x+1[/indent]
[indent=3]lastbutton = "mined "..x.." blocks"[/indent]
[indent=3]infoget = false[/indent]
[indent=3]movementdisplay() -- this is where my "lastbutton" and "infoget" are called[/indent]
[indent=3]sleep(.5)[/indent]
[indent=3]while turtle.dig() == true do -- this section mines the gravel[/indent]
[indent=4]x = x+1[/indent]
[indent=4]lastbutton = "mined "..x.." blocks"[/indent]
[indent=4]movementdisplay()[/indent]
[indent=4]sleep(.5)[/indent]
[indent=3]end[/indent]
[indent=2]elseif turtle.detect() and turtle.dig() == false then -- detects if it can break the block in front of it.[/indent]
[indent=3]lastbutton = "attempted to break block"[/indent]
[indent=3]infoget = "failed to break"[/indent]
[indent=3]movementdisplay()[/indent]
[indent=2]end[/indent]
[indent=1]elseif turtle.detect() == false then -- if there isn't a block[/indent]
[indent=2]while turtle.attack() == true do -- checks to attack[/indent]
[indent=3]turtle.attack()[/indent]
[indent=3]attacknumber = attacknumber+1[/indent]
[indent=3]lastbutton = "attacked: "..attacknumber[/indent]
[indent=3]infoget = false[/indent]
[indent=3]movementdisplay()[/indent]
[indent=2]end[/indent]
[indent=2]if turtle.suck() then -- sucks from the ground[/indent]
[indent=3]lastbutton = "sucked up an entity"[/indent]
[indent=3]while turtle.suck() == true do[/indent]
[indent=3]turtle.suck()[/indent]
[indent=2]end[/indent]
[indent=1]elseif turtle.suck() == false and x == 0 and attacknumber == 0 then -- if nothing was there[/indent]
[indent=2]lastbutton = "had nothing to mine"[/indent]
[indent=2]infoget = false[/indent]
[indent=1]end[/indent]
end