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

To people who can actually use computercraft, I need your skill

Started by legoatoom, 30 June 2016 - 02:48 PM
legoatoom #1
Posted 30 June 2016 - 04:48 PM
First off, what is my goal.

My goal is to have an enderchest always have a stack of steak in a slot, but to do that I need to know if I have steak in that chest.

That is where you come in, I am totally new to computercraft and found out that you can to this with openperipheral. After 2 hours I got nothing and I gave up."Never give up" I hear you say, but this is not something I wanna get into and I would love to get a code from a pro if it is not mutch to ask.

If you have question ask them.
Lupus590 #2
Posted 30 June 2016 - 06:11 PM
what code do you have so far? (don't forget
 [./code] tags)
legoatoom #3
Posted 30 June 2016 - 07:07 PM
Well you see, everything I have done, nothing worked. So I deleted it :\
Lupus590 #4
Posted 30 June 2016 - 08:36 PM
  • start small, write a program which prints the name of the first item in the chest.
  • from there, get the stack count of that item, print this out too
  • then add your logic, when the stack size is below a number, print a message "stack low"
  • then make sure that what you are looking at is the item you are interested in, adjust your logic as needed
  • change the stack low message so that it adds more of the low items
  • add a check for if the item is not in the chest, display a message
  • replace this message so that your program restocks the missing items
if you get stuck, post your code in this thread
Edited on 30 June 2016 - 06:37 PM
The_Cat #5
Posted 30 June 2016 - 10:57 PM
What mod pack are you using? You don't have to use CC.
legoatoom #6
Posted 01 July 2016 - 09:55 AM
lupus59 where can I lern this stuff?

The_ Cat I use Inventions FTB

I got this code so far

chest = peripheral.wrap("right")
slot = chest.getStackInSlot(9)

if slot = nil then
 redstone.setAnalogOutput("back",true)
 sleep(1,01)
 redstone.setAnalogOutput("back",false)
else
 print(slot.name.." is in slot "..i)
end
Edited on 01 July 2016 - 09:51 AM
The_Cat #7
Posted 01 July 2016 - 11:53 AM

chest = peripheral.wrap("back") --# Change this to whatever

for i=1,chest.getInventorySize() do
    local slot = chest.getStackInSlot(i)
    --# Basicly what lupus59 said, you need your logic so it knows when to put more in the chest
    if slot then --# If something in the slot if you don't do this it will crash as slot.name won't exist
        --# Add if slot.name equals to food then
        --# And if the quantity is less than whatever emit a redstone signal?
        print("There are "..slot.qty.. " " ..slot.name.." in slot "..i)
    end
end
legoatoom #8
Posted 01 July 2016 - 12:29 PM
The_Cat I only want it to check if there is steak in the bag or not, and if there is not steak in the bag it give an output for an amount of time.
The_Cat #9
Posted 01 July 2016 - 12:35 PM
legoatoom, Do you want to learn to code for CC? or someone to make it for you?
legoatoom #10
Posted 01 July 2016 - 12:43 PM
Someone make it, but if that is hard to do. then teach me.

I mad this, but it doesnot give an error, and it does not work


chest= peripheral.wrap("right")

for i=9,9 do
local slot = chest.getStackInSlot(i)

if slot then
if slot.name == cooked_beef then
redstone.setAnallogOutput("back",true)
sleep(1,01)
redstone.setAnalogOutput("back",false)
end
end
end
Edited on 01 July 2016 - 10:56 AM
The_Cat #11
Posted 01 July 2016 - 01:04 PM
This is crude but it works, so the chest is behind the computer and I have it emit a redstone signal if the beef is below 60. (64 causes a bug I can't be bothered to fix) Which is connected to an enderio item conduit which is only active on a redstone signal and connected to a different chest with lots of steak.

chest = peripheral.wrap("back")
while true do
local found = false
for i=1,chest.getInventorySize() do
  local slot = chest.getStackInSlot(i)

  if slot then
   --#print("There are "..slot.qty.. " " ..slot.name.." in slot "..i)
   if slot.name == "cooked_beef" then
	found = true
	if slot.qty < 60 then
	 rs.setOutput("right", true)
	else
	 rs.setOutput("right", false)
	end
   end
   print("There are "..slot.qty.. " " ..slot.name.." in slot "..i)
  end
end
if not found then
  rs.setOutput("right", true)
end
os.sleep(0.1)
end
Edited on 01 July 2016 - 11:05 AM
legoatoom #12
Posted 01 July 2016 - 01:39 PM
it has no getInventorySize() option

IT WORKS, but one problem, it only gives a redstone signal if there is 59 steak of less. but if there is 0 it does not work:(
The_Cat #13
Posted 01 July 2016 - 02:08 PM
It should work with none. Works for me.
legoatoom #14
Posted 01 July 2016 - 02:11 PM
It checks if there is steak first, if there is non, it does nothing
Edited on 01 July 2016 - 12:12 PM
The_Cat #15
Posted 01 July 2016 - 02:22 PM
If there are non it will set the right side redstone to true as found == false, if you want it to write somthing to the screen, in the:

if not found then
  rs.setOutput("right", true)
  print("No Food, setting output to true")
end
When you say there is no getInventorySize()? So you are not using an ender chest?
legoatoom #16
Posted 01 July 2016 - 02:23 PM
Sorry me fail
I forgot to change right to back
but it still doesnot work, gonna trythe code
Edited on 01 July 2016 - 12:24 PM
Lupus590 #17
Posted 01 July 2016 - 02:55 PM
the problem with open peripherals is that almost every version gives a different table format and provides different function names.

try this: http://www.computerc...openperipheral/
Edited on 01 July 2016 - 12:55 PM
legoatoom #18
Posted 01 July 2016 - 03:05 PM
Its fine! please dont make this more complicated :o/>