Update lib

This commit is contained in:
Kai Vogelgesang 2020-07-07 02:30:49 +02:00
parent 5ac9658c3a
commit b54c2f2257

View File

@ -22,7 +22,12 @@ state = (function ()
end)()
if state.x == nil or state.y == nil or state.z == nil or state.o == nil then
print("[WARNING] position is not set")
printError("[lib] position is not set")
printError("[lib] defaulting to 0, 0, 0, +z")
state.x = 0
state.y = 0
state.z = 0
state.o = 0
end
--[[
@ -33,6 +38,10 @@ end
3 = East (+x)
]]
function getOrientation()
return ({"+z", "-x", "-z", "+x"})[1 + state.o]
end
function move(raw_move, position_update)
return function()
success, err = raw_move()
@ -40,12 +49,15 @@ function move(raw_move, position_update)
return false, err
end
position_update()
return true
end
end
return {
state = state,
getOrientation = getOrientation,
fwd = move(turtle.forward, function()
if state.o == 1 or state.o == 3 then
state.x = state.x + ((state.o == 1) and -1 or 1)