http://pastebin.com/6cTZgjG4 most recent version of the mining program
Don't use "else do", at least, not that way. You're making two blocks there:
else
-- I'm inside the "else" block.
do
-- I'm inside the "do" block inside the "else" block.
-- Local variables declared in this "do" block will only exist in this "do" block,
-- but otherwise it has no point.
end
-- "do" block has finished but I'm still in the "else" block.
end
It seems you're thinking the "else" blocks require the "do"s, but they really don't - hopefully understanding this you'll be able to fix your indentation.
Lines 107-135 will never execute because they rely on line 63 evaluating as false and 106 evaluating as true. This is not possible as they both check to see if z==0.
The loop started on line 173 reads "for i = 0 , z/2 do". Every iteration of the loop digs two blocks along the length of the tunnel (one starting at the bottom and digging up, one starting at the top and digging down).
If z is 2 then the loop will go from 0 to 1, hence performing two iterations. Each iteration digs two blocks along the tunnel meaning 4 blocks worth of length.
Using "for i =
1 , z/2 do" is closer to what you want, but still has obvious problems (it won't dig at all unless z starts out at at least 2). You might consider thinking about ditching the division (use "for i=1,z do") and making your loop either tunnel up
or down (instead of both) depending on what math.fmod(i,2) currently happens to be.