diff --git a/mystical-upgrader.lua b/mystical-upgrader.lua index 93a08ba..c7f2194 100644 --- a/mystical-upgrader.lua +++ b/mystical-upgrader.lua @@ -59,31 +59,29 @@ local refuel = function() end end -local goToTheLeft = function() - turtle.turnLeft() - local ok, reason = turtle.forward() - - if not ok then - error('cannot forward because ' .. tostring(reason), 0) - end - - turtle.turnRight() -end - -local goToTheRight = function() - turtle.turnRight() - local ok, reason = turtle.forward() - - if not ok then - error('cannot forward because ' .. tostring(reason), 0) - end - - turtle.turnLeft() -end - local MOVES = { - left = goToTheLeft, - right = goToTheRight, + left = function(strictMode) + turtle.turnLeft() + local ok, reason = turtle.forward() + + if strictMode and not ok then + error('cannot forward because ' .. tostring(reason), 0) + end + + turtle.turnRight() + return ok, reason + end, + right = function(strictMode) + turtle.turnRight() + local ok, reason = turtle.forward() + + if strictMode and not ok then + error('cannot forward because ' .. tostring(reason), 0) + end + + turtle.turnLeft() + return ok, reason + end, } local getTierFromLevel = function(level) @@ -262,7 +260,9 @@ local main = function() upgradeProcedure() if i ~= NB_ROWS then - MOVES[DIRECTION]() + MOVES[DIRECTION](true) + else + MOVES[DIRECTION](false) -- do not throw if cannot move forward end end