33 posts
Posted 29 July 2015 - 07:34 AM
So, the code works perfectly, but the problem is that the AE system interface (the block) isn't fast enough to place all the quarts seeds inside the turtle before the part of the code that drops the seeds in the water starts, what I'm trying to do is make the turtle wait till no items enter its inventory in a period of 5 seconds or so, for example:
-items start entering turtle's inventory
-turtle notices items stop entering turtle's inventory
-waits 5 seconds to see if nothing enters turtle's inventory again (if items enter turtle's inventory, restart this part of the program)
-runs code
This is what I have atm:
while true do
repeat
sleep(1)
until turtle.getItemCount(1) > 0
sleep(10)
for x=1,16 do
turtle.select(x)
turtle.dropDown()
end
sleep(90)
for x=1,16 do
turtle.select(x)
turtle.suckDown()
turtle.dropUp()
end
end
81 posts
Posted 29 July 2015 - 07:59 AM
I'll stay in hypothetical here but it should be quite clear.
When you begin your program you launch a timer using is.syartTimer which will push an event into the stack after the determined amount of time, you then start checking for the timer event you created. If you receive that before any turtle_inventory events you know that there has been no additional items added to the turtle
Edit: just to be clear, if you receive a inventory event first you can use is.cancelTimer to stop it then starts new one and start looking for inventory events again
Edited on 29 July 2015 - 06:02 AM
33 posts
Posted 29 July 2015 - 08:05 AM
I'll stay in hypothetical here but it should be quite clear.
When you begin your program you launch a timer using is.syartTimer which will push an event into the stack after the determined amount of time, you then start checking for the timer event you created. If you receive that before any turtle_inventory events you know that there has been no additional items added to the turtle
Edit: just to be clear, if you receive a inventory event first you can use is.cancelTimer to stop it then starts new one and start looking for inventory events again
Sorry, but I know absolutely nothing about events
3057 posts
Location
United States of America
Posted 29 July 2015 - 06:30 PM
local id = os.startTimer( 5 )
while true do
local event, tid = os.pullEvent()
if event == "timer" and id == tid then
break
elseif event == "turtle_inventory" then --#turtle got an item
id = os.startTimer( 5 ) --#restart the timer
end
end
33 posts
Posted 29 July 2015 - 09:37 PM
local id = os.startTimer( 5 )
while true do
local event, tid = os.pullEvent()
if event == "timer" and id == tid then
break
elseif event == "turtle_inventory" then --#turtle got an item
id = os.startTimer( 5 ) --#restart the timer
end
end
Thx, it works fine, but do you have any links to something I could read that explains events?
Edited on 29 July 2015 - 07:38 PM
656 posts
Posted 29 July 2015 - 09:41 PM
Edited on 29 July 2015 - 07:42 PM