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

repeat until ends early

Started by XDaWNeDX, 17 March 2013 - 10:40 PM
XDaWNeDX #1
Posted 17 March 2013 - 11:40 PM
I'm making my wood cutter, and I'm trying to make the turtle wait until the tree has grown. I'm just using a repeat until to check when there's no longer a sapling in front of it. But the problem is, is it eventually stops repeating. It doesn't harm anything in my program, nor does it break the turtle. But it does make the turtle break the saplings and replant them, despite there not being a tree there.

I attempted to debug this using the following code:


count=0
repeat
print(count)
count=count+1
until not turtle.compare()

It's currently at 6000 repeats, without any problems. With the code in the actual turtle, that would be about 500 minutes - far more than the amount of time it took the repeat to break.

The code that is breaking in the turtle:


repeat
 sleep(5)
until not turtle.compare()


So I'm wondering if there is any problems with the turtle.compare command, the repeat until loop, or if there is a better way to wait until a tree has grown.
theoriginalbit #2
Posted 17 March 2013 - 11:45 PM
shouldn't be any problems… this is the code I used in my own logger and it works perfectly

print("Waiting for sapling to grow.")

while turtle.compare() do
  sleep(0.1)
end
logically it is no different to yours. the only difference is that a repeat loop will run the instructions inside at least once, a while loop will only run if the condition is met.
Lyqyd #3
Posted 18 March 2013 - 06:11 AM
Saplings' metadata changes as they grow, so this is detecting the change in metadata. Change it to use a log block to compare instead of a sapling.
XDaWNeDX #4
Posted 19 March 2013 - 06:46 PM
Saplings' metadata changes as they grow, so this is detecting the change in metadata. Change it to use a log block to compare instead of a sapling.


Sorry, I wasn't able to reply when I got your answer earlier, but I'll do so now.

A. First off, I'd like to thank you for your answer. Helped a lot, and it fixed my program.
B. Redwood trees, from whatever mod they're in occasionally have different block IDs, according to turtles. For whatever reason. I'm assuming it's the orientation, but even then, it's not 100%. Fortunately, I don't use redwood trees, I use fir trees which have no problems. However; the problem still lies with the redwood trees, and I intend to eventually release the script once it's completed. (It's not a generic logger. It's quite advanced.)

I'll be fixing the program by making the turtle check the block above the sapling, rather than the saplings themselves. Though, for a more visually appealing, and - though rather miniscule - better fuel efficiency, it'd be nice if I could keep the turtle at the sapling level. Is there any other way, besides comparing for logs/saplings to check if the tree has grown? I'm assuming not, but I'm still rather new to ComputerCraft.