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

error:too long without yeilding.

Started by monte86, 23 December 2012 - 01:02 PM
monte86 #1
Posted 23 December 2012 - 02:02 PM
I don't know a lot about coding. My first progect was to make a mining/quarry turtle. I ended up scrapping my first code until I got the basics down with just up and down movements. I'm probably going to guess that the problem lies within the while loop and its not going to the top each time. When the items get to 20 is when I get the error. I have the item count on 20 so i dont have to keep going down as far each time to "test" the program. It probably has something to do with the double while loop.

What I am looking for is a to fix my problem or just someone to say a work around "look into this".
I don't expect anyone to build the code for me and i do appreciate all the feedback/extra help given.
Spoilerf = 64 – starting floor
b = 5 – bedrock

while f > 5 do
while turtle.getItemCount (2) < 20 do
turtle.digDown()
turtle.down()
f = f - 1
end

end

while b < 64 do
turtle.up()
b = b + 1

end

http://pastebin.com/KuNZb0Ns
Doyle3694 #2
Posted 23 December 2012 - 02:07 PM

    f = 64   -- starting floor
    b = 5    -- bedrock
	
	 while f > 5 do
	    while turtle.getItemCount (2) < 20 do
		 turtle.digDown()
		 turtle.down()
		 f = f - 1
	    end
	    sleep(0) -- you need to have a yield, aka a pullEvent, which is esiest made with sleep().
	 end
	
    while b < 64 do
	    turtle.up()
	    b = b + 1
	  
    end
monte86 #3
Posted 23 December 2012 - 02:57 PM
awesome thanks. So how does the sleep work. I added the sleep(0), that part works fine. However it doesn't go into the turtle.up command.
Doyle3694 #4
Posted 23 December 2012 - 03:02 PM
A turtle command works like a yield
ChunLing #5
Posted 23 December 2012 - 04:32 PM
You've done something funny to your rom/apis/turtle/turtle so that the java turtle functions don't get replaced with the versions that yield properly. Or you've somewhere else gone and replaced the turtle functions with the turtle.native backup of the java turtle functions.

At least, that's all I can think of to explain how this code could be generating a "too long without yielding error".
Cloudy #6
Posted 23 December 2012 - 10:18 PM
turtle.getItrmCount doesn't yield.
ChunLing #7
Posted 24 December 2012 - 12:18 AM
But turtle.down() should, right? It had to not yield twenty times for this error to occur. That's got to be the native java function, because the lua functions specifically yield to avoid this problem.
Cloudy #8
Posted 24 December 2012 - 12:25 AM
If slot 2 has more than 20 items in it what would happen?
ChunLing #9
Posted 24 December 2012 - 05:51 PM
Oh…derp.

What I mean to say is…

f = 64 -- starting floor
b = 5 -- bedrock

while f > 5 and turtle.getItemCount (2) < 20 do
    turtle.digDown()
    turtle.down()
    f = f - 1
end

while b < 64 do
    turtle.up()
    b = b + 1
end
The sleep avoided the error message, but didn't resolve your infinite loop problem.
Edited on 24 December 2012 - 04:55 PM
monte86 #10
Posted 25 December 2012 - 01:45 PM
thanks for all the help guys. I realized that even if would end the dig down loop and go up. The level would be wrong and it would be a lot higher then normal.

If slot 2 had more then 20 items in it. it would either go straight to sleep mode or into the up command. I'm not really sure. With the new modpacks and christmas. I've not had time to mess with it that much. As soon as we get our server up and running and i have enough items to play around with it. I'm going to start coding again.
ChunLing #11
Posted 26 December 2012 - 03:12 PM
Okay, then combine b and f into a single value that tracks your current position.
f = 64
while f > 5 and turtle.getItemCount (2) < 20 do
    turtle.digDown()
    turtle.down()
    f = f - 1
end
for i=f,63 do turtle.up() end
okay, the last bit doesn't update f on the way up, but it should return to the starting level.