This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Brian87's profile picture

Branch-mining

Started by Brian87, 29 March 2014 - 07:24 AM
Brian87 #1
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:

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
Lyqyd #2
Posted 29 March 2014 - 08:35 AM
Please post the full code. If it's too large for the forums, put it up on pastebin and post a link to it. The line number of the error doesn't do us much good without the full code, and the full code is important to gain context about the program anyhow.
Bomb Bloke #3
Posted 29 March 2014 - 09:20 AM
Presumably you never set countRight / countLeft to anything before this code block runs - that'd leave 'em as nil.

Using "south" doesn't "work" so much as it bypasses the problem due to you mistyping "dirnum" as "dirnunm" on a certain line.
Brian87 #4
Posted 29 March 2014 - 09:39 AM
Here's the link to the full code:
http://pastebin.com/9rHGqCTq

The error is at the function "sendCoordinates()"
Brian87 #5
Posted 29 March 2014 - 11:40 AM
never mind, I got it to work now :)/>