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

OpenPeripheral Jabba Barrel mod Help with tabels.

Started by viking_petz, 03 January 2017 - 06:08 PM
viking_petz #1
Posted 03 January 2017 - 07:08 PM
So im back after a long time away from computercraft



I am playing a survival map i have wanted to create for a long time


the thing is i want to make to put onto screen what marterials i have in my storage in my secreet evil lair section.
Spoilerlocal barrel = {

peripheral.wrap("mcp_mobius_betterbarrel_0")
peripheral.wrap("mcp_mobius_betterbarrel_1")
peripheral.wrap("mcp_mobius_betterbarrel_2")
peripheral.wrap("mcp_mobius_betterbarrel_3")
peripheral.wrap("mcp_mobius_betterbarrel_4")
peripheral.wrap("mcp_mobius_betterbarrel_5")
peripheral.wrap("mcp_mobius_betterbarrel_6") }

–this one was the first and it displayed correctly in this code.
– barrel.wrap("mcp_mobius:betterbarrel_0")

local function write( … )
for _,mon in pairs( monitors ) do
mon.write( … )
end
end



mon = peripheral.wrap("monitor_9")


tbl = barrel.getStoredItems()
name= tbl.display_name
qty = tbl.qty




– while true do
mon.clear()
mon.setCursorPos(1,1)
mon.write(name)
mon.setCursorPos(12,1)
mon.write(qty)
– end



what i want to do is foloving.



while true do
mon.clear()
mon.setCursorPos(1,1)
mon.write(name)
mon.setCursorPos(12,1)
mon.write(qty)
end

and this should continue but on a new line and foreward like being


while true do
mon.clear()
mon.setCursorPos(1,2) + 1 for each barrel added to the table. etc
mon.write(name)
mon.setCursorPos(12,2) + 1 for each barrel added to the table. etc
mon.write(qty)



Hope someone can help me with this as this can help mee understand the table thingy better.


Petz
KingofGamesYami #2
Posted 03 January 2017 - 07:35 PM
What you want is a for loop.

This would do what you want, but only for the name:

mon.clear() --# surely you don't want to clear after each line is written!
for i = 1, #tbl do
  mon.setCursorPos( 1, 1 + i ) --#add i (which increments by one each loop) to the y value
  mon.write( tbl[ i ].display_name ) --#write the name of the current item to the monitor
end

..I'll leave it up to you to implement qty :)/>
viking_petz #3
Posted 03 January 2017 - 08:12 PM
and once again you have saved the day.. if i dont rememer wrong you helped mee when startet with this projekt.



if i wanted to put the barrels in a specifik order. should i then when putting them into the table do it in a specifik order or is that not possible ?


BTW you are awesome
KingofGamesYami #4
Posted 03 January 2017 - 11:50 PM
Yes, the order of entries in the table will affect how they are shown.

I do have quite a few posts, so it is very possible I've helped you before.