diff --git a/kai/lib.lua b/kai/lib.lua index 602567a..42e3ca4 100644 --- a/kai/lib.lua +++ b/kai/lib.lua @@ -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)