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

os.pullEvent never stops blocking for turtle_inventory events

Started by Yorae, 01 August 2013 - 10:05 PM
Yorae #1
Posted 02 August 2013 - 12:05 AM
Hi, I'm working on a bit of code that has my turtle place down a block and then signal another device using redstone to deal with it, which will break the block. It's intended to repeat this process until it runs out of blocks in its inventory, at which point it should block and wait until its inventory has received more blocks. I'm using os.pullEvent("turtle_inventory"), but changing the turtles inventory, whether by hand or by placing items into it with pipes or golems, doesn't wake up the turtle and cause it to continue. Here's what I've got:


function selectFirstItem()
  for i = 1, 16 do
	if turtle.getItemCount(i) ~= 0 then
	  turtle.select(i)
	  return true
	end
  end
  return false
end

local numProcessed = 0

while(true) do
  if (selectFirstItem()) then
	if(not turtle.detect()) then
	  turtle.place()
	  os.sleep(0.5)
	  redstone.setOutput("bottom", true)
	  os.sleep(0.5)
	  redstone.setOutput("bottom", false)
	  numProcessed = numProcessed + 1
	end
	os.sleep(5)
  else
	print("Process cycle complete - " .. numProcessed .. " ores processed.")
	numProcessed = 0
	print("Shutting down until I have more work.")
	os.pullEvent("turtle_inventory")
	print("I am awake!  Begining ore processing procedure!")
  end
end


If I use os.pullEvent("redstone"), it will properly wake on a redstone signal, but for some reason this event type isn't working correctly. Have I discovered a bug, or am I using the pullEvent function incorrectly?

Thank you very much for any help!

Edit: I'm running CC 1.53 on MC 1.5.2.
Bubba #2
Posted 02 August 2013 - 12:09 AM
Split into new topic.
Symmetryc #3
Posted 02 August 2013 - 12:19 AM
Just making sure, you're using Minecraft 1.6, right?
Yorae #4
Posted 02 August 2013 - 12:26 AM
Just making sure, you're using Minecraft 1.6, right?

I'm running 1.5.2 with ComputerCraft 1.53 - I'll make a note of it in the post.

If worse comes to worse, I suppose I can workaround the problem by using a BC logic gate and blocking on redstone events, but that feels a little inelegant.
Symmetryc #5
Posted 02 August 2013 - 12:29 AM
Just making sure, you're using Minecraft 1.6, right?
I'm running 1.5.2 with ComputerCraft 1.53 - I'll make a note of it in the post. If worse comes to worse, I suppose I can workaround the problem by using a BC logic gate and blocking on redstone events, but that feels a little hokey.
Sorry, the "turtle_inventory" event was added in 1.6.
Yorae #6
Posted 02 August 2013 - 12:47 AM
Just making sure, you're using Minecraft 1.6, right?
I'm running 1.5.2 with ComputerCraft 1.53 - I'll make a note of it in the post. If worse comes to worse, I suppose I can workaround the problem by using a BC logic gate and blocking on redstone events, but that feels a little hokey.
Sorry, the "turtle_inventory" event was added in 1.6.

Ahh, got it. I didn't realize and it wasn't on the API page. I'll just use the redstone workaround for now. Thanks!