Update lib
This commit is contained in:
parent
5ac9658c3a
commit
b54c2f2257
14
kai/lib.lua
14
kai/lib.lua
@ -22,7 +22,12 @@ state = (function ()
|
|||||||
end)()
|
end)()
|
||||||
|
|
||||||
if state.x == nil or state.y == nil or state.z == nil or state.o == nil then
|
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
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
@ -33,6 +38,10 @@ end
|
|||||||
3 = East (+x)
|
3 = East (+x)
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
function getOrientation()
|
||||||
|
return ({"+z", "-x", "-z", "+x"})[1 + state.o]
|
||||||
|
end
|
||||||
|
|
||||||
function move(raw_move, position_update)
|
function move(raw_move, position_update)
|
||||||
return function()
|
return function()
|
||||||
success, err = raw_move()
|
success, err = raw_move()
|
||||||
@ -40,12 +49,15 @@ function move(raw_move, position_update)
|
|||||||
return false, err
|
return false, err
|
||||||
end
|
end
|
||||||
position_update()
|
position_update()
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
state = state,
|
state = state,
|
||||||
|
|
||||||
|
getOrientation = getOrientation,
|
||||||
|
|
||||||
fwd = move(turtle.forward, function()
|
fwd = move(turtle.forward, function()
|
||||||
if state.o == 1 or state.o == 3 then
|
if state.o == 1 or state.o == 3 then
|
||||||
state.x = state.x + ((state.o == 1) and -1 or 1)
|
state.x = state.x + ((state.o == 1) and -1 or 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user