8 posts
Posted 18 June 2013 - 10:22 AM
Okay. So I am fairly new to ComputerCraft, I've made two small programs in the past but have no idea where to start with my new project.
What I want to do is be able to put a computer in my warehouse, next to a large monitor, and for the monitor to display each barrel (from factorization), what is in it, and how many of said item there are.
My question is, How do I get a computer to read how many items there are in a barrel and then display the name of the item and the number of said item on a monitor? If this is on the forum already then I apologize, I couldn't find it.
I am pretty sure to get it to detect the item in the barrel, I am going to have to code for every item in the game. (which is fine) I just need to know where to start.
Now, I don't want the code written for me. I just would like to know where I should start/how to do the above. Any help, or links to helpful posts/videos, will be greatly appreciated.
8543 posts
Posted 19 June 2013 - 09:40 AM
Split into new topic.
7508 posts
Location
Australia
Posted 19 June 2013 - 09:51 AM
If you're able to install mods then I suggest you install
OpenPeripheral as it gives support for reading barrels
I think OpenCCSensors can do the same, but I'm not positive on that…
As it stands though, there is no vanilla way to read the counts of the barrels, or the items, so that will all be manually coded if you do not install the a mod to help you.
In order to do this manual coding you will need to know…
Tables (storing the data)
FS API (saving that data so it isn't forgotten over restarts
Textutils API (also saving the table data) in particular textutils.serialize and textutils.unserialize
Term API (for displaying information) you can also use print and write which are not part of this API, but do use it
To learn about Lua and ComputerCraft specific APIs I suggest reading the following
http://www.lua.org/pil/1.htmlhttp://computercraft.info/wiki/index.php?title=Category:APIs[You saw nothing! :ph34r:/> -L]
7083 posts
Location
Tasmania (AU)
Posted 19 June 2013 - 09:53 AM
Check the inventory sensor from
OpenCCSensors. Apparently that supports Factorisation, which I assume includes barrels.
You may also find
peripheral.getMethods handy in working out how to use it.
Edit: Blah, ninja'd. :P/>
8 posts
Posted 21 June 2013 - 09:03 PM
Okay. So I looked into OpenCCSensors. I can get my computer to find the Sensor and detect that it is using the inventory sensor card. Can get the Sensor to find the barrel. and all I get back from both mySensor.getTargets() and mySensor.getTargetDetails() is the input code. I cannot for the life of me figure out how to get it to tell me how many items are in the barrel or WHAT item is in the barrel (or a regular chest for that matter either).. Any ideas? Any help? can't find a tutorial on the Inventory sensor card either…
Edit: Can't get OpenPeripheral mod to work.
112 posts
Posted 22 June 2013 - 01:19 AM
You wanted not to have a code for you but i think the following could be some kind of help with OCS, so notice a spoiler warning.
I'm a nerdy beginner with OCS, so if i can do it, everybody can! Maybe everyone in this forum does it better like me, but I'm not Lyqyd!
I think, that OpenCCSensors is the best way to archive this goal, and the best mod around for people that like factorizing, automated production and thinks like that
Get.taget.details returns every slot of the chest, the count of items in the slot and its maximum stacksize. It also returns the name of the item inside. For example: Crops can be stacked up to a maximum of 64. It will show: (maybe) Size: 24 of max. Stacksize 64. If the item can not be stacked, it will show, maybe with waterbarrels, one barrel with max. Stacksize of one. It gives all the data for the given question. With the inventory card, like any other sensor card, the difficulty is to work through the table it returns. There are tables nested inside the table for every slot inside tbe chest. Maybe you should note too that a big chest is splitted into two targets. Left chest is the upper inventory of the big chest, right chest is the lower so if you have items in the upper section of the big chest, target.details of the right chest does not return any item.
I've done a nerdy prog for my ingot chests, the mainpart of this looks nerdy like this:
don't forget to load the sensor API and to wrap your sensor, in this case it is wrapped to "chest"
local details1 = chest.getTargetDetails('3,1,-1') – left side of one big chest
for slotnumber1 = 1, 27 do
inname1=(details1.Slots[slotnumber1].Name)
stacksum1 = stacksum1 + (details1.Slots[slotnumber1].Size)
maxsum1 = maxsum1 + (details1.Slots[slotnumber1].MaxStack)
end
local details2 = chest.getTargetDetails('2,1,-1') – right side of the big chest
for slotnumber2 = 1, 27 do
inname2=(details2.Slots[slotnumber2].Name)
stacksum2 = stacksum2 + (details2.Slots[slotnumber2].Size)
maxsum2 = maxsum2 + (details2.Slots[slotnumber2].MaxStack)
end
proz1= math.ceil(100/(maxsumme1+maxsumme2) * (stacksumme1+stacksumme2))
Maybe you are able to print out the data for each variable, it should bring you the wanted data.
(details1.Slots[slotnumber1].Size) is the count inside a slot, stacksum is the count of all slots.
(details1.Slots[slotnumber1].MaxStack) gives the stacksize of the item, maxsum gives the overall intake of the chest (My chest has only one item. this can not work with a chest that takes several items randomly)
inname gives the name of the item per slot
I had done this for a computer without a monitor, because i rednet.send this data to another computer, controlling my Ore-Furnace melting system.
Note that i'm not a pro-coder so it could be made easier, but it works fine for me, Its hobby.
1 posts
Posted 22 June 2013 - 01:42 AM
Well i remember when i was starting if i were you i would look at all the Api's for ComputerCraft i would look at The Turtle API and also expirement with it you just got too try just remember that you can do it :D/>
8 posts
Posted 22 June 2013 - 10:40 AM
If someone would really like to help me. I would love a code. I cannot for the life of me (even with all the above help) get anything to work. :(/>
7508 posts
Location
Australia
Posted 22 June 2013 - 10:57 AM
If someone would really like to help me. I would love a code. I cannot for the life of me (even with all the above help) get anything to work. :(/>
Post the code that you have been trying and we can give you suggestions/pointers on that code :)/>
[You saw nothing! :ph34r:/> -L]
Oh but I did :P/> Also congrats on the promotion to Admin :)/>
112 posts
Posted 22 June 2013 - 12:06 PM
os.loadAPI("ocs/apis/sensor")
local chest = sensor.wrap("top") -- use as "top" the side, where your sensor is at
monitor = peripheral.wrap("front") -- use as "front" the side, where your monitor is at
monitor.setTextScale(0.5)
term.redirect(monitor)
while true do
term.clear()
local stacksum = 0
local maxsum = 0
local details = chest.getTargetDetails('3,1,-1') -- use as ('3,1,-1') the position where your chest is at
for slotnumber = 1, 27 do
stacksum = stacksum + (details.Slots[slotnumber].Size)
maxsum = maxsum + (details.Slots[slotnumber].MaxStack)
term.setCursorPos(1, slotnumber) print (("Slot ") .. (slotnumber))
term.setCursorPos(9, slotnumber) print ((" : ") .. (details.Slots[slotnumber].Size) )
term.setCursorPos(14, slotnumber) print (("/") .. (details.Slots[slotnumber].MaxStack))
term.setCursorPos(18, slotnumber) print ((" of Item: ") .. (details.Slots[slotnumber].Name) )
end
term.setCursorPos(1, 30) print ( ("Content of Chest is ") ..
(math.ceil(100/maxsum*stacksum)) .. (" %") )
sleep (1)
end
Be sure to give the correct position of the chest, you want to spot, to this line – "local details = chest.getTargetDetails('3,1,-1') "
The chest I locate here is 3 blocks to the left, on block up, and one block before (in front of) the sensor, if your standing in front of the computer, with the sensor on top of it.
Sorry for the english, i'm a kraut.
You also can take the position, of the wanted chest from the ocs/programs/sensorview program, you will see all available chests on the left side.
Edit: Use a 3x3 Monitor
8 posts
Posted 22 June 2013 - 08:55 PM
os.loadAPI("ocs/apis/sensor")
local chest = sensor.wrap("top") -- use as "top" the side, where your sensor is at
monitor = peripheral.wrap("front") -- use as "front" the side, where your monitor is at
monitor.setTextScale(0.5)
term.redirect(monitor)
while true do
term.clear()
local stacksum = 0
local maxsum = 0
local details = chest.getTargetDetails('3,1,-1') -- use as ('3,1,-1') the position where your chest is at
for slotnumber = 1, 27 do
stacksum = stacksum + (details.Slots[slotnumber].Size)
maxsum = maxsum + (details.Slots[slotnumber].MaxStack)
term.setCursorPos(1, slotnumber) print (("Slot ") .. (slotnumber))
term.setCursorPos(9, slotnumber) print ((" : ") .. (details.Slots[slotnumber].Size) )
term.setCursorPos(14, slotnumber) print (("/") .. (details.Slots[slotnumber].MaxStack))
term.setCursorPos(18, slotnumber) print ((" of Item: ") .. (details.Slots[slotnumber].Name) )
end
term.setCursorPos(1, 30) print ( ("Content of Chest is ") ..
(math.ceil(100/maxsum*stacksum)) .. (" %") )
sleep (1)
end
Be sure to give the correct position of the chest, you want to spot, to this line – "local details = chest.getTargetDetails('3,1,-1') "
The chest I locate here is 3 blocks to the left, on block up, and one block before (in front of) the sensor, if your standing in front of the computer, with the sensor on top of it.
Sorry for the english, i'm a kraut.
You also can take the position, of the wanted chest from the ocs/programs/sensorview program, you will see all available chests on the left side.
Edit: Use a 3x3 Monitor
I thank you very much, I copied and pasted it into my games folder. started it up, found the file on my computer, set up the sensor, monitor and chest. and whenever I use the program I get:
16: attempt to index ? (a nil value)
edit: line 16 is: stacksum = stacksum + (details.Slots[slotnumber].Size)
130 posts
Posted 22 June 2013 - 09:13 PM
That program only works with full chests.
Updated program:
Spoiler
os.loadAPI("ocs/apis/sensor")
local chest = sensor.wrap("top") -- use as "top" the side, where your sensor is at
monitor = peripheral.wrap("front") -- use as "front" the side, where your monitor is at
monitor.setTextScale(0.5)
term.redirect(monitor)
while true do
term.clear()
local stacksum = 0
local maxsum = 0
local details = chest.getTargetDetails('3,1,-1') -- use as ('3,1,-1') the position where your chest is at
for slotnumber = 1, 27 do
local slot = details.Slots[slotnumber]
if slot ~= nil then
stacksum = stacksum + (slot.Size)
maxsum = maxsum + (slot.MaxStack)
term.setCursorPos(1, slotnumber) print (("Slot ") .. (slotnumber))
term.setCursorPos(9, slotnumber) print ((" : ") .. (slot.Size) )
term.setCursorPos(14, slotnumber) print (("/") .. (slot.MaxStack))
term.setCursorPos(18, slotnumber) print ((" of Item: ") .. (slot.Name) )
end
end
term.setCursorPos(1, 30) print ( ("Content of Chest is ") .. (math.ceil(100/maxsum*stacksum)) .. (" %") )
sleep(1)
end
8 posts
Posted 22 June 2013 - 09:24 PM
That program only works with full chests.
Updated program:
Spoiler
os.loadAPI("ocs/apis/sensor")
local chest = sensor.wrap("top") -- use as "top" the side, where your sensor is at
monitor = peripheral.wrap("front") -- use as "front" the side, where your monitor is at
monitor.setTextScale(0.5)
term.redirect(monitor)
while true do
term.clear()
local stacksum = 0
local maxsum = 0
local details = chest.getTargetDetails('3,1,-1') -- use as ('3,1,-1') the position where your chest is at
for slotnumber = 1, 27 do
local slot = details.Slots[slotnumber]
if slot ~= nil then
stacksum = stacksum + (slot.Size)
maxsum = maxsum + (slot.MaxStack)
term.setCursorPos(1, slotnumber) print (("Slot ") .. (slotnumber))
term.setCursorPos(9, slotnumber) print ((" : ") .. (slot.Size) )
term.setCursorPos(14, slotnumber) print (("/") .. (slot.MaxStack))
term.setCursorPos(18, slotnumber) print ((" of Item: ") .. (slot.Name) )
end
end
term.setCursorPos(1, 30) print ( ("Content of Chest is ") .. (math.ceil(100/maxsum*stacksum)) .. (" %") )
sleep(1)
end
for this one I got: 12: attempt to index ? (a nil value)
edit: line 12 is: local slot = details.Slots[slotnumber]
8 posts
Posted 22 June 2013 - 09:34 PM
I THINK I may know what the problem is actually.. and I feel quite idiotic..
I am using 0.1.4b because of tekkitlite.. -_-/>/> I'm gonna go do some tweaking with my mods and I'll post back if I get any new results.
Edit: yup. Updated to 1.5.2 and it's all working. Thanks Guys!
Edit again: Do either of you (or anyone for that matter) know how to make this program work for a barrel? (would save monitor space and it is what I would prefer to use) Right now the monitor says that the barrel can only hold 409 items (can hold 4096 according to wiki). Thanks in advance!
5 posts
Posted 23 June 2013 - 12:14 AM
I think chest and barrel inventories are unique, and can't be read with the same program.
112 posts
Posted 23 June 2013 - 03:14 AM
That program only works with full chests.
is not true, it's working fine with me
I think the nil value depends on a coord, that is not proper given to the "chest.getTargetDetails('3,1,-1')"
if there is no chest, there is no data.
112 posts
Posted 23 June 2013 - 06:26 AM
I now loaded this mod and had another look.
The difference is, that the "barrel" has only one Slot with its maximum count and content. One Vanilla Chest is splitted into 27 Slots and every single Slot gets his maximum-Stacksize with the item that is deployed inside this one slot.
So the barrel acts for OCS like a chest with only one "very Big" Slot. It can take a maximum of 4096 parts of only one Item, if i got that right in the 2 minutes i tested it.
So for your monitor, you should be fine, using this :
os.loadAPI("ocs/apis/sensor")
local chest = sensor.wrap("top") -- use as "top" the side, where your sensor is at
monitor = peripheral.wrap("right") -- use as "front" the side, where your monitor is at
monitor.setTextScale(0.5)
term.redirect(monitor)
term.clear()
local details = chest.getTargetDetails('0,-1,-1') -- use as ('0,-1,-1') the position where your chest is at
print (("Content ") .. (" : ") .. (details.Slots[1].Size))
print (("Max. Content ") .. (" : ") .. (details.Slots[1].MaxStack))
print (("Name of Content") .. (" : ") .. (details.Slots[1].Name))
Maybe you put it inside a while loop so its reacting live to the barrel-input.
Don't forget to put the right coord to it…
The reason for showing 409 max in the first program is easy. It depends on the display structure of the term.setCursorPos. Positions. the 6 of 4096 was cutted by the next printout command.