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

Debug and Efficiency Check of Miner turtle code

Started by dom123, 28 October 2013 - 10:35 AM
dom123 #1
Posted 28 October 2013 - 11:35 AM
Title: Debug and Efficiency Check of Miner turtle code

I am working on a Mining turtle code that will strip mine an area with using minimal fuel needs

please review my code I have the problem that when he runs into a mob his count is effected. As a novice to computer craft if you can suggest any changes to my code feel free. I can use all the guidance you are willing to offer.

http://pastebin.com/PzMpQ01b
sens #2
Posted 28 October 2013 - 11:55 AM
Note: I've since been reminded not to post answers on this thread (sorry!) - so what you see below is not an answer, just a musing…

My first thought on this is that you're losing count because of the scope of loop counter "i". Instead of having one declaration at the top of the file, try declaring it separately in every function that uses it.

My second thought is that ReduceLevel() will not work because turtle.detect() detects blocks in front, not below. Suggest replacing

while turtle.detect() == true do
with

while turtle.down() == false do
in that function, and removing the turtle.down() below that loop.
dom123 #3
Posted 28 October 2013 - 12:58 PM
Title: Debug and Efficiency Check of Miner turtle code

I am working on a Mining turtle code that will strip mine an area with using minimal fuel needs

please review my code I have the problem that when he runs into a mob his count is effected. As a novice to computer craft if you can suggest any changes to my code feel free. I can use all the guidance you are willing to offer.

http://pastebin.com/PzMpQ01b
Note: I've since been reminded not to post answers on this thread (sorry!) - so what you see below is not an answer, just a musing…

My first thought on this is that you're losing count because of the scope of loop counter "i". Instead of having one declaration at the top of the file, try declaring it separately in every function that uses it.

My second thought is that ReduceLevel() will not work because turtle.detect() detects blocks in front, not below. Suggest replacing

while turtle.detect() == true do
with

while turtle.down() == false do
in that function, and removing the turtle.down() below that loop.


i have fixed the ReduceLevel() function

what would be your suggestion recording the movement with a second declaration?
–add code?–
– this would change the for loop in the MineForward() function

replace this
###
for i = 1, 25 do
while turtle.detect() == true do
turtle.dig()
turtle.attack()
end
turtle.forward()
###

with this

local v = 0
while v < 26 do
  while turtle.detect() do
	turtle.dig()
	turtle.attack()
  end
  if turtle.forward() then
	v = v + 1
  end
end

do you think this would work?
{updated pastebin with the above code inplanted}
http://pastebin.com/yGG3irGN
Bomb Bloke #4
Posted 28 October 2013 - 05:33 PM
It'll move ahead 26 blocks, but it should do it reliably.

You could shrink it a little further:

for i=1,25 do
  while not turtle.forward() do  -- This is the same as saying "while turtle.forward() == false do"
    turtle.dig()
    turtle.attack()
  end
end

Every time the "while" loop repeats, the turtle tries to move forward. The loop ends when that movement succeeds.