-- S++: nicked from the standard go, but replaced handlers with own versions
local tArgs = { ... }
if #tArgs < 1 then
	print( "Usage: go <direction> <distance>" )
	return
end

local tHandlers = {
	["fd"] = tx.forward,
	["fw"] = tx.forward,
	["forward"] = tx.forward,
	["forwards"] = tx.forward,
	["bk"] = tx.back,
	["back"] = tx.back,
	["up"] = tx.up,
	["dn"] = tx.down,
	["down"] = tx.down,
	["lt"] = tx.left,
	["left"] = tx.left,
	["rt"] = tx.right,
	["right"] = tx.right,
}

local nArg = 1
while nArg <= #tArgs do
	local sDirection = tArgs[nArg]
	local nDistance = 1
	if nArg < #tArgs then
		local num = tonumber( tArgs[nArg + 1] )
		if num then
			nDistance = num
			nArg = nArg + 1
		end
	end
	nArg = nArg + 1

	local fnHandler = tHandlers[string.lower(sDirection)]
	if fnHandler then
		while nDistance > 0 do
			if fnHandler() then
				nDistance = nDistance - 1
			elseif turtle.getFuelLevel() == 0 then
				print( "Out of fuel" )
				return
			else
				sleep(0.5)
			end
		end
	else
		print( "No such direction: "..sDirection )
		print( "Try: forward, back, up, down" )
		return
	end

end