Ok, had a bit of spare time so I tried running the script.
First issue I ran into was setting the initial co-ordinates - having no GPS system set up, I had to type them manually. Entering in the numbers was simple enough but when I pressed enter at the end nothing happened. I had to inspect the source a bit harder to get past that - it wanted me to enter a "y" figure between 1-255, though as far as the GPS API and many non-MineCraft-related conventions are concerned,
"z" handles height.
At this point it'd likely be easiest to changes lines 536 and 539 accordingly:
x,z,y = gps.locate(3)
local tmpx,tmpz,tmpy = gps.locate(3)
It's also not at all clear to the user that you want a number from 0-3 entered for "facing", especially given the complete lack of feedback when you type something wrong (and what regular user is going to know what those numbers mean?). I'd highly recommend that at the least you document these issues (no feedback when typing something wrong, potential confusion about y/z, how north=0 etc).
Anyway, once the turtle was moving I told it to exit the script and then re-launched it. It returned to the surface, moved four blocks to the south, then started digging downwards again.
I then fully rebooted the turtle and relaunched the script. It returned to the surface, moved four blocks to the south
and four blocks to the east, and started digging down again. :P/>
After a couple more tests it became clear that the further I allowed the turtle to wander from its starting position, the further away
again it'd wander when I
next started the script. This suggested it initially knew it was far away from home, and trying to get back there - only it had its directions confused, so instead of travelling "closer" to its starting point it was going in the opposite direction. Soon it was going dozens of blocks each restart and buried itself in a mountain - it had no idea where it was after having done so.
With the finger pointed squarely at the movement functions, I examined then re-wrote the following inside "loc":
facingToAxis = {
[0] = { axis = 'z', unit = -1 }, -- Moving north DECREASES your "z"
[1] = { axis = 'x', unit = 1 }, -- etc
[2] = { axis = 'z', unit = 1 },
[3] = { axis = 'x', unit = -1 }
},
movez = function(d)
if d < loc.z then loc.face(0) elseif d > loc.z then loc.face(2) end -- Face NORTH to decrease "z", etc.
return loc.moveForward()
end,
movex = function(d)
if d < loc.x then loc.face(3) elseif d > loc.x then loc.face(1) end -- Face EAST to increase "x", etc.
return loc.moveForward()
end,
On restarting the script again, the turtle dug its way out of the mountain back to the area where I'd initially started it.
While a rather verbose retelling, hopefully the above gives you some insight into how you might go about troubleshooting things in the future.