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

Crafting pure certus quartz with a turtle

Started by astonish01, 29 July 2015 - 05:34 AM
astonish01 #1
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
jerimo #2
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
astonish01 #3
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
KingofGamesYami #4
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
astonish01 #5
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
flaghacker #6
Posted 29 July 2015 - 09:41 PM
A complete tutorial:
http://www.computercraft.info/forums2/index.php?/topic/1516-ospullevent-what-is-it-and-how-is-it-useful/

The (more technical) documentation:
http://computercraft.info/wiki/Os.pullEvent

A good example program tutorial with extra explenation on os.pullEvent:
http://www.computercraft.info/forums2/index.php?/topic/16925-how-to-create-a-touch-screen-on-a-terminal/
Edited on 29 July 2015 - 07:42 PM