Skip to content

Instantly share code, notes, and snippets.

@devsamuelv
Created July 18, 2021 03:32
Show Gist options
  • Save devsamuelv/b094a90323e445be4cb79fd3fc5b266e to your computer and use it in GitHub Desktop.
Save devsamuelv/b094a90323e445be4cb79fd3fc5b266e to your computer and use it in GitHub Desktop.
Computer Craft Hello World
local global_init = true
local lastTorch = 0
local currentTorch = 0
local totalSlots = 16
local currentSlot = 1
function attack()
turtle.attack()
end
function rotateBack()
turtle.turnRight()
turtle.turnRight()
end
function rotateFront()
turtle.turnLeft()
turtle.turnLeft()
end
function placeTorch()
local torchTime = (currentTorch - lastTorch) == 6
if torchTime then
getCurrentSlot()
rotateBack()
turtle.select(getCurrentSlot())
turtle.place()
rotateFront()
lastTorch = currentTorch
end
currentTorch = currentTorch + 1
end
function getCurrentSlot()
for i = currentSlot, totalSlots do
local remaing = turtle.getItemCount(i)
print(i, currentSlot, i + 1)
if remaing > 2 then
return i
end
if remaing == 2 then
local nextSlot = i + 1
currentSlot = nextSlot
return nextSlot
end
end
end
function forward()
turtle.forward()
local blockDected = turtle.detect()
if blockDected then
turtle.dig()
turtle.digUp()
placeTorch()
end
end
while true do
forward()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment