Posted 29 March 2014 - 08:24 AM
Hello, I'm trying to make a script for branch mining, and if it detects a diamond ore, it should print the coordinates. So I choose the facing of the turtle (north, west, south or east). If I try for example west it compares the block and says "trying to compare nil with number on line 293". But if I try south it works :(/>
Here's part of my code:
Here's part of my code:
local tCoordinates = {...}
term.clear()
term.setCursorPos(1,1)
print("What are the coordinates?")
print("X: ")
term.setCursorPos(3,2)
tCoordinates[1] = read()
print("Z: ")
term.setCursorPos(3,3)
tCoordinates[2] = read()
repeat
term.clear()
term.setCursorPos(1,1)
print("Please input the facing of the turtle: n / e / s / w")
event, param1 = os.pullEvent("char")
if event == "char" then
if param1 == "n" then
dirnum = 1
elseif param1 == "e" then
dirnum = 2
elseif param1 == "s" then
dirnunm = 3
elseif param1 == "w" then
dirnum = 4
end
end
term.clear()
term.setCursorPos(1,1)
until param1 == "n" or
param1 == "e" or
param1 == "s" or
param1 == "w"
local function getCoordinates()
if dirnum == 1 then
if countRight > 0 then
xCoordinate = tCoordinates[1] + countLeft + 1
elseif countLeft > 0 then
xCoordinate = tCoordinates[1] - countLeft - 1
end
zCoordinate = tCoordinates[2] + mForward - countForward
elseif dirnum == 2 then
xCoordinate = tCoordinates[1] + countForward - mForward
if countRight > 0 then
zCoordinate = tCoordinates[2] + countRight + 1
elseif countLeft > 0 then
zCoordinate = tCoordinates[2] - countLeft - 1
end
elseif dirnum == 3 then
if countRight > 0 then
xCoordinate = tCoordinates[1] - countLeft - 1
elseif countLeft > 0 then
xCoordinate = tCoordinates[1] + countLeft + 1
end
zCoordinate = tCoordinates[2] + countForward - mForward
elseif dirnum == 4 then
xCoordinate = tCoordinates[1] + mForward - countForward
if countRight > 0 then
zCoordinate = tCoordinates[2] - countRight - 1
elseif countLeft > 0 then
zCoordinate = tCoordinates[2] + countLeft + 1
end
end
end
local function sendCoordinates()
turtle.select(1)
if turtle.compare() == true then
term.clear()
term.setCursorPos(1,1)
print(getCoordinates())
end
end
function branchLeft()
countLeft = 0
for i = 1,tArgs[2] do
checkdig()
turtle.up()
checkdig()
checkDown()
checkDown()
checkdig()
turtle.up()
checkdig()
checkForward()
countLeft = countLeft + 1
inventoryFull()
fuelLow()
sendCoordinates()
end
countLeft = 0
end
function branchRight()
countRight = 0
for i = 1,tArgs[2] do
checkdig()
turtle.up()
checkdig()
checkDown()
checkDown()
checkdig()
turtle.up()
checkdig()
checkForward()
countRight = countRight + 1
inventoryFull()
fuelLow()
sendCoordinates()
end
countRight = 0
end