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

Help with a stripmining code

Started by pieisnotpi, 01 August 2013 - 09:22 PM
pieisnotpi #1
Posted 01 August 2013 - 11:22 PM
Thanks for the help! One last error: when I enter in the lengths, it runs the main mining script. I set up the main mining script to recognize the 3 potential lengths and mine based on that. The problem is that my if then statements are not executing the lines below them. For example, this script below will not execute anything even if the input is 3.

if input == 3 then
   loop1 = 3
end --if 
Pastebin: http://pastebin.com/dce5aszc


-- Script for turning around

function turnAround()
  turtle.turnRight(2)
end --turnAround()

-- Script for placing torches

function torch()
  turtle.select(16)
  turnAround()
  turtle.place()
  turtle.select(1)
  turnAround()
end --torch()

-- Script for primary digging

function dig()
  turtle.dig()
  turtle.forward()
  turtle.digUp()
end --dig()

-- Script for Forward mining

function mineForward()
  dig(3)
end --mineForward()

--Sub script for digging sides

function mineSides1()
  if dig2 == 5 then
	dig(5)
	turnAround()
	turtle.forward(5)
  end --if
  if dig2 == 3 then
	dig(3)
    turnAround()
    turtle.forward(3)
  end --if
  if dig == 1 then
	dig()
    turnAround()
    turtle.forward()
  end --if
end --mineSides1

--Script for digging sides

function mineSides2()
  turtle.turnLeft()
  mineSides1
  mineSides1
  turtle.turnRight()
end --mineSides2()

-- Script for all mining

function mine()
  mineForward()
  mineSides2()
end --mine()

-- Script for everything

function main()
  if dig1 == 12 then
	mine(12)
  end --if
  if dig1 == 6 then
	mine(6)
  end --if
  if dig1 == 3 then
	mine(3)
  end --if
end --main()

--Actual program script

term.clear()
print("Hello.")
print("Please enter the tunnel length (3,6,12)")
dig1 = read()
tonumber(dig1)
print("Please enter the side tunnel length (1,3,5)")
dig2 = read()
tonumber(dig2)
term.clear()
print("Mining will now commence.")
main()
print("Done.")
Edited by
Bubba #2
Posted 01 August 2013 - 11:37 PM
Split into new topic.
Bubba #3
Posted 02 August 2013 - 12:30 AM
Look at your if statements a bit more carefully:

  if loop1 == 12 then do
	mine(12)
  end --if
  if loop1 == 6 then do
	mine(6)
  end --if
  if loop1 == 3 then do
	mine(3)
  end --if

You have "if [stuff] then do". The "do" is the important bit there. Only loops have the "do" keyword. You need to change it to:

if loop1 == 12 then
  mine(12)
elseif loop1 == 6 then
  mine(6)
elseif loop1 == 3 then
  --etc. etc.
end
pieisnotpi #4
Posted 02 August 2013 - 09:27 AM
Ok. Let me try that now. EDIT: It worked, but still some issues (that are not errors).
pieisnotpi #5
Posted 04 August 2013 - 04:35 PM
Anyone got anything?
immibis #6
Posted 04 August 2013 - 07:55 PM
read() returns a string, such as "5", "3" or "blurgh".
Strings are never equal to numbers ("5" == 5 is not true).
You can convert a string to a number using the tonumber function.
tonumber("5") returns 5.
tonumber(read()) asks for a line of input and then converts it to a number and returns the number.
tonumber returns nil if the string wasn't a number (tonumber("blurgh") == nil)
pieisnotpi #7
Posted 05 August 2013 - 01:49 PM
How could I get that to work with my dig1 and dig2 variables?
Sheefou #8
Posted 05 August 2013 - 03:33 PM
Cant split i topics but i wanna know how to edit a start up program from another coumputer because i did os.pullEvent = os.pullEventRaw and the program is not responding the right way i want it to