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

Loop question on turtle

Started by Cota, 05 June 2012 - 09:52 PM
Cota #1
Posted 05 June 2012 - 11:52 PM
So i keep getting this "too long without yielding" on my turtle, i had read that i need a OS Event to keep this from happening, but how is it applied on this code? i use C# but only 3 days on this language :)/>/>


This particular code is executed after my turtle docks to a load/unload station, 1st is drained and then is filled whit stone so this "icount" is to ensure that all spaces are empty.


while icount>0 do
icoun=0
icount=icount +turtle.getItemCount(1)
icount=icount +turtle.getItemCount(2)
icount=icount +turtle.getItemCount(3)
icount=icount +turtle.getItemCount(4)
icount=icount +turtle.getItemCount(5)
icount=icount +turtle.getItemCount(6)
icount=icount +turtle.getItemCount(7)
icount=icount +turtle.getItemCount(8)
icount=icount +turtle.getItemCount(9)
end

*puts puppy eyes*
Pinkishu #2
Posted 06 June 2012 - 12:16 AM
add a sleep(0) or longer, sleep calls coroutine.yield() internally
PixelToast #3
Posted 06 June 2012 - 12:34 AM
use this code instead to find out if all spaces are empty:

function isempty()
for l1=1,9 do
if turtle.getItemCount(l1)~=0 then return false end
end
return true
end
Cota #4
Posted 06 June 2012 - 12:51 AM
Thant you guys, didn't know the sleep function did that, also that code save me lines =D

Its now time to get my quarry to bi dimensional scales :)/>/>