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

Program getting stuck on .getStackInSlot(i)

Started by aelund, 09 March 2014 - 12:27 AM
aelund #1
Posted 09 March 2014 - 01:27 AM
Hi everyone, so I've basically had this issue when after rebooting a computer my startup program gets stuck on p.getStackInSlot().
Here is all the code, nothing advanced, just a checking if there is something in slot 1 of the ender chest above the computer:

local p = peripheral.wrap("top")
while true do
	if p.getStackInSlot(1) then
		print("true")
		shell.run("mine")
	else
		print("false")
		sleep(5)
	end
end
As you might've guessed this computer is on my MFFS mining machine, so the computer is getting moved by Force Manipulator which is activated by the Mine program. But this shouldn't matter because computer just reboots every time it's moved. When i terminate the program it prints out the line on which program was terminated so that's how i know that it gets stuck on p.getStackInSlot(1).
So can anyone say what i did wrong and how to fix it, or if it's a bug and it can't be helped suggest another method of turning this on/off without using p.getStackInSlot(1) or wireless redstone(wireless receivers get knocked off when force manipulators move them, sadly)?
adencraft2000 #2
Posted 11 March 2014 - 02:13 AM
The code you are using works IF you have "open peripherals" installed as an ender chest is not a regular computercraft peripheral.
Another option is to use a turtle rather than a computer and use this script (Slightly different but will do the job I think):

while true do -- Loop
  if turtle.suckUp() == true then -- If the turtle can suck an item (From ANY SLOT) of the inventory above
	print("true")
	turtle.dropUp() -- Put the item back in the inventory above
	shell.run("mine") -- Run "mine"
  else -- If it can not suck an item
	print("false")
	sleep(5) -- Wait 5 seconds
  end
end
pastebin get Y8vjwwwE startup

Hope this helps :)/>
aelund #3
Posted 11 March 2014 - 09:00 AM
The code you are using works IF you have "open peripherals" installed as an ender chest is not a regular computercraft peripheral.
Another option is to use a turtle rather than a computer and use this script (Slightly different but will do the job I think):

while true do -- Loop
  if turtle.suckUp() == true then -- If the turtle can suck an item (From ANY SLOT) of the inventory above
	print("true")
	turtle.dropUp() -- Put the item back in the inventory above
	shell.run("mine") -- Run "mine"
  else -- If it can not suck an item
	print("false")
	sleep(5) -- Wait 5 seconds
  end
end
pastebin get Y8vjwwwE startup

Hope this helps :)/>/>

Yes, I do have Open Peripherals(thought i mentioned that, sorry). I'll try using this method with a turtle, thanks. :)/>/>

Just tried this with the turtle, and it did the same thing, but now it got stuck with an item in it's inventory. I think it's all because of MFFS, and I think only I have it since I didn't find anyone with this issue. I'll make it with just a redstone circuit for now and will detect an item in the chest using a vanilla comparator.
Goof #4
Posted 12 March 2014 - 09:44 PM
Hi everyone, so I've basically had this issue when after rebooting a computer my startup program gets stuck on p.getStackInSlot().
Here is all the code, nothing advanced, just a checking if there is something in slot 1 of the ender chest above the computer:

local p = peripheral.wrap("top")
while true do
	if p.getStackInSlot(1) then
		print("true")
		shell.run("mine")
	else
		print("false")
		sleep(5)
	end
end
As you might've guessed this computer is on my MFFS mining machine, so the computer is getting moved by Force Manipulator which is activated by the Mine program. But this shouldn't matter because computer just reboots every time it's moved. When i terminate the program it prints out the line on which program was terminated so that's how i know that it gets stuck on p.getStackInSlot(1).
So can anyone say what i did wrong and how to fix it, or if it's a bug and it can't be helped suggest another method of turning this on/off without using p.getStackInSlot(1) or wireless redstone(wireless receivers get knocked off when force manipulators move them, sadly)?


(Sorry for bumping a day old post)

I also ran into such a problem, and i seem to fix it by adding a sleep(1) at the top of your startup code.

This problem occurred because Java is running into a bug'ish thingy, which is causing the startup program to freeze, and tell the computer to say that p.getStackInSlot(1) is the cause.
The really problem is though that the computer is being moved 0.005 seconds before the enderchest above is getting moved( i assume its on top since you wrap it on the top side xD )
So the computer is actually wrapping a "nil" side, and p.getStackInSlot(1) will return an error, due to java and computercraft

So yeah, you only need to add a sleep(1) to the startup file

Hope this helps :D/>/>/>/>
Edited on 12 March 2014 - 08:45 PM
kain184 #5
Posted 24 July 2014 - 09:04 AM
you should avoid moving the computer at all as it causes a thread overflow issue as the processing thread does not get deleted from each move and sucks more of your memory away. i would have the computer move itself outside of the field and check that way. otherwise you will eventually crash your game from low memory.