Created
July 18, 2021 03:32
-
-
Save devsamuelv/b094a90323e445be4cb79fd3fc5b266e to your computer and use it in GitHub Desktop.
Computer Craft Hello World
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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