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

Tekkit IC2 quarry back-up miner, not completely perfect, oddly prints "178" and quits working

Started by dtdsora, 08 December 2012 - 04:37 PM
dtdsora #1
Posted 08 December 2012 - 05:37 PM
to further explain the code, it is supposed to mine all the ores, gems, etc, that the Industrial Craft quarries in Tekkit miss. However, I have already noted some problems.
first, it doesn't work right on corners
second, after a while it prints "178" even though i don't have any print commands in there, and none of the variables should even be able to get up to 178, unless there just so happens to be a 178 block line of dirt underground
third, it won't automatically empty the chest, so you would have to manually
and fourth, it has to start on a layer of complete stone to be able to work, without going kilometers away, but that is acceptable.
anyone have any tips on fixing problems 1 through 3?
EDIT: also, it sometimes alternates between 178 and "bios:15: vm error: java.lang.ArrayIndexOutOfBoundsException: 256" so I changed one line in the code
Spoiler
i = 0
j = 0
function check()
		if turtle.compare() then
  turtle.turnRight()
  if turtle.compare() then
   turtle.turnRight()
   turtle.forward()
   turtle.turnLeft()
   j = j + 1
   if j == 4 then
	turtle.down()
	j = 0
	check()
   else
	check()
   end
  else
   turtle.forward()
   turtle.turnLeft()
   check()
  end
else
  mineore()
end
end
function reverse()
while i ~= 0 do
  turtle.back()
  i = i - 1
  reverse()
end
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
check()
end
function mineore()
turtle.dig()
turtle.forward()
i = i + 1
  if turtle.compare() then
   reverse()
  else
   mineore()
  end
end
check()
the edited code is this:
Spoiler
   if j == 4 then
	turtle.down()
	j = 0
	check()
to this:
Spoiler
   while j == 4 do
	turtle.down()
	j = 0
   end
but there was no change in-game, same errors
OmegaVest #2
Posted 08 December 2012 - 06:08 PM
You've caused the lua. . . "box", so to speak, to run out of memory.

This is directly caused by recursive looping, that being, coding a program or function to call itself while still "open".


Maybe a visual would be better.
This causes the program to eventually run out of memory:
Spoiler

function run()
   for i = 1, 10 do
      print("This will eventually cause a problem.")
   end
   run()
end

run()

The proper way to write this would be:
Spoiler

function run()
   print("This will never run out.")
end
while true do
   run()
end'
As will this:
Spoiler

function run()
   print("This is not ideal, but will work.")
   return run()
end
run()
Now, before you go pointing to your change, that did not actually change anything, because a)It doesn't do what you want, and b)You've changed one conditional for another. Even removing the ONE recursive call, you haven't changed anything. It is still gonna open more instances of check() once it gets past 4.