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

[Error]Repeat not Working?

Started by Popretmaster, 16 December 2012 - 06:22 PM
Popretmaster #1
Posted 16 December 2012 - 07:22 PM
So I just wrote this scrip that is supposed to dig a path through Mountains, it works fine, until it comes to repeat, it will dig, dig up, go up, dig up again, then if there's no block it'll go down, go forward, and dig, but there it will just terminate the program, Please help
-Popretmaster

--Moutain Miner by Popretmaster
local goneUp=0
local opStatus=0
local randomVarPlaceHolder=0
local repeatEndVar=2
local detectBlock = turtle.detectUp()
local tArgs = {...}
if #tArgs ~= 1 then
print("Wrong Usage")
return
end
local distance = tonumber(tArgs[1])
repeat
distance = distance - 1
if turtle.detect() then
  turtle.dig()
  sleep(1)
  if detectBlock == true then
   repeat
	turtle.digUp()
	turtle.up()
	detectBlock = turtle.detectUp()
	sleep(5)
	goneUp=goneUp+1
   until detectBlock == false
   sleep(1)
   if detectBlock == false then
	repeat
	 turtle.down()
	 goneUp=goneUp-1
	until goneUp == 0
	 repeatEndVar = 0
	 opStatus = 2
	 sleep(1)
   end
  end
end
if opStatus == 2 then
  turtle.forward()
  opStatus = 0
end
until distance == 0
  
  
  

[EDIT] the sleep(5) in the middle was just because I almost lost my turtle before due to a bug where it traveled up forever, in this version it's fixed, the repeat error is not
theoriginalbit #2
Posted 16 December 2012 - 07:25 PM
are you wanting it to run infinitely? because if the problem is the termination its because your repeat condition is distance == 0 and you are decrementing distance each loop
Popretmaster #3
Posted 25 December 2012 - 08:22 PM
I want it to be able to run more than once no matter how many times I enter the distance so "MouMin 14" or whatever number I use it only goes once Please help