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

Mining program

Started by grand_mind1, 04 May 2013 - 08:04 PM
grand_mind1 #1
Posted 04 May 2013 - 10:04 PM
I've recently run into a problem with my turtle strip mine program.
Code:
http://pastebin.com/bmsyqq5w

I just implemented the placeChest() function in which the turtle chooses between which type of chest the user decided and either places it down or goes back to the beginning of the mine and places all of it's items in the chest. My problem is with the last option. The turtles gets to the chest and drops off it's items perfectly but when it tries to go back to where it was, it goes on forever. I don't understand why because it should only go forward however long the tunnel was (as defined by 'totforw') When looking inside the console I can see that the turtle is still adding 'totforw' even though 'inMainTunnel' was declared as false on line 64 right before it goes back. I have no idea why but I think it either has something to do with the lop I am using to get back or I am somehow declaring 'inMainTunnel' as true. Also, a lot of the code is unused and unfinished at the moment. I am also new to programming and a lot of my code is quite sloppy and not thought through very well. Sorry, if it's hard to understand.
Help is appreciated!
Thanks! :D/>
The_Awe35 #2
Posted 05 May 2013 - 12:37 AM
You are right, it is about "inMainTunnel" variable. In your forward() function, you tell it to increase toforw by one if it is in the main tunnel. Except it looks like you missed an end, (I think) and it is part of the for loop. I think a for loop would only loop up to the original variable amount, whether or not it changes, so it will work fine, until it tries to come back. Just add a end right after the end of the while loop (and remove one from the end of the forward() function).
grand_mind1 #3
Posted 05 May 2013 - 12:49 AM
I'm not sure exactly what you mean. The if statement that determines if 'inMainTunnel' is true is supposed to be inside the for loop. Otherwise 'totforw' would only increase by one every time the function was called rather than increasing by one every time the turtle moved forward.
The_Awe35 #4
Posted 05 May 2013 - 11:38 AM
Okay, well I really don't know what you were trying to acompliish there anyway, but how I see it, on its way over to the chest, totforw get increased many, many times. And on the way back, it is know going to move that many more times. If you print totforw on your way back from the chest, or even in the for loop itself, you should see that it keeps getting bigger.
I guess one way to fix that is to set inMainMine to false as soon as you start the function, and make it true only once it is back again.