Jump to content




Crafting pure certus quartz with a turtle


5 replies to this topic

#1 astonish01

  • Members
  • 33 posts

Posted 29 July 2015 - 06: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


#2 jerimo

  • Members
  • 74 posts

Posted 29 July 2015 - 06: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 by jerimo, 29 July 2015 - 07:02 AM.


#3 astonish01

  • Members
  • 33 posts

Posted 29 July 2015 - 07:05 AM

View Postjerimo, on 29 July 2015 - 06:59 AM, said:

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

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 29 July 2015 - 05: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


#5 astonish01

  • Members
  • 33 posts

Posted 29 July 2015 - 08:37 PM

View PostKingofGamesYami, on 29 July 2015 - 05:30 PM, said:

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 by astonish01, 29 July 2015 - 08:38 PM.


#6 flaghacker

  • Members
  • 655 posts

Posted 29 July 2015 - 08:41 PM

A complete tutorial:
http://www.computerc...w-is-it-useful/

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

A good example program tutorial with extra explenation on os.pullEvent:
http://www.computerc...-on-a-terminal/

Edited by flaghacker, 29 July 2015 - 08:42 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users