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

Getting function instead of table

Started by xFreak666, 31 March 2017 - 06:42 PM
xFreak666 #1
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
Lyqyd #2
Posted 01 April 2017 - 02:14 AM
You have to actually call the function.


local infbrl = brl.getStoredItems()

Notice the parentheses.
xFreak666 #3
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!
Bomb Bloke #4
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.
xFreak666 #5
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
xFreak666 #6
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
Screenshot
Spoiler