8 posts
Posted 31 March 2017 - 08:42 PM
Hello everyone,
First i need to mention that i'm new to computercraft also to programming and sorry if this problems seems a bit silly.
I'm trying to create a monitor that manages my storage on minecraft. I'm using openPeripherals on JABBA Barrels the problem is whenever i use the getStoredItems function it returns a function instead of a table i've been searching for hours now and it really buggs me , thanks for help <3
local brl = peripheral.wrap("top")
local infbrl = brl.getStoredItems
for k,v in pairs(infbrl) do
print(k.." = "..v)
end
8543 posts
Posted 01 April 2017 - 02:14 AM
You have to actually call the function.
local infbrl = brl.getStoredItems()
Notice the parentheses.
8 posts
Posted 02 April 2017 - 01:36 PM
You have to actually call the function.
local infbrl = brl.getStoredItems()
Notice the parentheses.
Thanks a lot , i figured it out yet is there a documentation for Openperipherals events ? I'm sort of trying to make my program dynamic ==> whenever i pull items from the barrel the monitor screen changes, again thanks a lot!
7083 posts
Location
Tasmania (AU)
Posted 02 April 2017 - 03:58 PM
No, I don't believe there's any documentation for the events you might get back from OpenPeripheral peripherals. You might try running a loop like this:
while true do print(os.pullEvent()) end
… then messing with your peripheral to see if you can trigger any lines of text.
8 posts
Posted 02 April 2017 - 07:46 PM
Well sadly the peripherals seem only to pull an attach or detach event , yet i'm thinking of creating a loop that continuously checks if the quantity has changed if so the program triggers an event that i'll use to update the text is that possible ?
Edited on 02 April 2017 - 06:34 PM
8 posts
Posted 02 April 2017 - 09:24 PM
I finally solved it , Thanks Lyqyd and Bomb Bloke
local brl = peripheral.wrap("bottom")
local mon = peripheral.wrap("top")
local infbrl = {}
local name = ""
local qty = 0
local div = 0
local mod = 0
local inf = true
repeat
infbrl = brl.getStoredItems()
name = infbrl.display_name
qty = infbrl.qty
mod = qty%64
if mod > 1 then
div = math.ceil(qty/64)-1
else
div = math.ceil(qty/64)
end
mon.clear()
mon.setCursorPos(1,1)
mon.setTextColor(colors.blue)
mon.write(name.." = "..qty.." ("..div.." x 64 + "..mod..")")
os.sleep(3)
until inf == false
ScreenshotSpoiler