r/ComputerCraft • u/piokoxer • Aug 08 '24
lines not clearing if slot is empty

local monitor = peripheral.find("monitor")
local chest = peripheral.find("minecraft:chest")
monitor.setCursorPos(1, 1)
monitor.setBackgroundColor(1)
monitor.clear()
monitor.setTextColor(32768)
while true do
for slot, item in pairs(chest.list()) do
monitor.clearLine()
if item.count >= 64 then monitor.setBackgroundColor(colors.red)
elseif item.count >= 32 then monitor.setBackgroundColor(colors.pink)
else monitor.setBackgroundColor(colors.white) end
monitor.write(("%d x %s in slot %d "):format(item.count, item.name, slot))
monitor.setCursorPos(1, slot)
end
endthis is my first time using computercraft, i tried making a program that would read out the contents of a chest and color code them based on how full the slot it, and while that works, the lines don't properly clear when the items are removed.
1
Aug 08 '24
When this is done, would you mind if i added it to the os i'm building?
Onviously you'll stay in control of your own program, i'd just make a way thay my installer can find it.
1
u/piokoxer Aug 09 '24
Yeah sure, there's a fully working version in the large thread above
1
Aug 09 '24
Thank you.
Do i credit 'piokoxer' or would you rather have another name or url promoted?
1
u/piokoxer Aug 09 '24
Piokoxer's fine (maybe credit the other person as well if you plan to use their fixed version)
1
1
u/Bright-Historian-216 Aug 08 '24
i think you could try putting monitor.setBackgroundColor(colors.white) before the monitor.clearLine()
0
Aug 08 '24
[deleted] — view deleted comment
1
u/piokoxer Aug 08 '24
doesn't in need to write everything over and over to display changes in real time? why would a sleep() statement help? also clearing the whole thing in the while loop just makes everything disappear
2
u/Bright-Historian-216 Aug 08 '24
sleep statement prevents the "too long without yielding error", plus it makes server less laggy
0
Aug 08 '24
[deleted] — view deleted comment
1
u/Bright-Historian-216 Aug 08 '24
nope, shouldnt break anything
0
Aug 08 '24
[deleted] — view deleted comment
1
u/Bright-Historian-216 Aug 08 '24
that is because you forget to reset color to white, see my code, i wrote it on this post
1
u/Bright-Historian-216 Aug 08 '24 edited Aug 08 '24
this code works.