3 posts
Posted 02 April 2018 - 05:12 PM
Hi everyone! I decided I needed a new skill in life and over the weekend I dove into ComputerCraft for 1.12. I have Plethora Peripherals and PeripheralsPlusOne installed. My project goal is to get the contents of a chest to display on a monitor. I am using a chest on the left, a single (normal) computer in the middle, and 4 monitor screens on the right. I figured out how to wrap the chest as a peripheral and to display its contents as a list, but I ran into a road block using the monitors.
So far I have the following:
chest = peripheral.wrap("left")
monitor = peripheral.wrap("right")
monitor.write( "chest.list()" )
I know the chest.list() worked after wrapping the chest. How ever everytime I opened and closed the computer, the peripheral wrap disappeared? Do I need to save this as a program? I would appreciate any help, or nudges in the correct direction.
3 posts
Posted 04 April 2018 - 06:14 PM
While not a complete solve, I figured out my initial issue.
I erroneously put the quotations into the .write line
I was able to get a print on the monitor and figured out how to resize the text. Now I just need to figure out to only return name and qty from .list() rather than the default response.
1426 posts
Location
Does anyone put something serious here?
Posted 05 April 2018 - 09:15 AM
I was able to get a print on the monitor and figured out how to resize the text. Now I just need to figure out to only return name and qty from .list() rather than the default response.
.list() returns a table which looks something like this:
{
[1] = { name = "minecraft.dirt", count = 5, damage = 0 },
[12] = { name = "minecraft.sticks", count = 12, damage = 0 },
--# etc...
}
In order to print this to the monitor, you'll need to iterate over every slot and extract the relevant fields from the item data:
local y = 1
for slot, item in pairs(chest.list()) do
monitor.setCursorPos(1, y)
monitor.write(slot .. " " .. item.name .. " " .. item.count)
y = y + 1
end
3 posts
Posted 10 April 2018 - 06:09 PM
@SquidDev thank you for the reply! That worked splendidly, especially after I figured out how to remove the 'slot' data from the monitor.write. Makes the printed info more clean. :)/>
I have two more questions if you don't mind helping out. I made a simple program to clear my monitor screen, but it's time consuming to use my clear program and then re-run the chest.list program I have. Is there a function I could add in that would have the monitor.write line re-print any time I open or close the chest? (or if the qty of an item increases/decreases? Going to rewrite this program for YABBA barrels when I try to learn modems.)
I also noticed .list() only returns the item.name in it's table, I think I would prefer writing the displayName instead. I noticed your Plethora Peripherals mod has .getItemMeta(). I am struggling on how to get that peripheral to work in the manner we did the chest.list() loop.
Again I really appreciate the help.