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

Finding Table Structures

Started by Fousicek, 14 October 2015 - 07:52 PM
Fousicek #1
Posted 14 October 2015 - 09:52 PM
Hi, i started looking into this, because i want to keep specifick number of items in system and i dont want to use level emiter setup, too easy.

What i want to do is that the computer will check number of items in the system and then export needed items for crafting into difrent (non AE2 ) crafting system and then put them back.

I will just use the interface a way to communicate with AE 2 and exporting and importing into the AE2.


But my question is. I am not still able to understand how exavtly i can find the structure of tables when i call methods which returns tables. Or how i can identify the key in the tabels ? how do i find the structure as is in the 3rd spoiler in the first post ?

Sorry might be very unsorted thoughts.

I will be happy for any help.

thank you
Bomb Bloke #2
Posted 14 October 2015 - 10:19 PM
Split from this topic.

The textutils API has a number of functions that are handy for listing out table contents:

textutils.pagedTabulate(myTable)

For especially large tables, I like to write out the content to a file, using a pairs loop (as discussed in this tutorial) and fs.open():

local output = fs.open("myTable.txt", "w")

for key, value in pairs(myTable) do
  output.writeLine(key .. " is a " .. type(value))
end

output.close()
Fousicek #3
Posted 15 October 2015 - 04:06 PM
Thank you, i was able to get this advice working.
For especially large tables, I like to write out the content to a file, using a pairs loop (as discussed in this tutorial) and fs.open():

local output = fs.open("myTable.txt", "w")

for key, value in pairs(myTable) do
  output.writeLine(key .. " is a " .. type(value))
end

output.close()

i am now able to get the
 item.fingerprint.id
to actualy show id but every
item.fingerprint.nbt_hash
is showing only nill.
And i am still not able find out why.

And also textutils.pagedTabulate(myTable) did nothing for me.

thank you

EDIT: Figured it out. Not everz item stores data as NBT .
item.fingerprint.dmg is metadata .

in SSP the
 item.fingerprint 
is nowhere to be found. it just says
 item. name,dmg,size,qtu ...... 

is it bcs SSP and SMP is difrent tabels ?
Edited on 15 October 2015 - 04:35 PM
Bomb Bloke #4
Posted 15 October 2015 - 10:13 PM
item.fingerprint.dmg is metadata .

Sort of; it's the damage value (which only applies to items in an inventory). While interchangeable for many items, metadata is something different, and only applies to blocks that've been placed within the world.

in SSP the
 item.fingerprint 
is nowhere to be found. it just says
 item. name,dmg,size,qtu ...... 

is it bcs SSP and SMP is difrent tabels ?

Could be! I suspect it might be more likely to have something to do with mod versions, though, or perhaps the way the storage system was built. It'd ultimately depend on the mod which is producing the tables (which'll either be OpenPeripheral or AE2, as ComputerCraft has no Applied Energistics compatibility built into it).
Fousicek #5
Posted 16 October 2015 - 12:20 PM
Ok it might be bug inside the advanced computer. Because when i use normal computer then every single item is with the table
item.fingerprint
found it when i was getting error
window: 94 : Arguments must be the same length 
.

In this post http://forum.feed-th...omputer.102138/ , thez saz that use normla computer. So i did and it is working.


Another question.

If i have program called keeplist and inside it table like
Spoiler

purequartz{
   ["id"] ,
   ["dmg"] ,
   ["nbt_hash"],
   ["keep"],
   ["craft"] = { ["id"]= something,
                     ["dmg"], 
                     ["nbt_hash"], 
                     ["takeqty"]
				   }
				}

can i use in difrent program this ?


if keeplist.purequartz.craft["id"] == something then ....
Edited on 16 October 2015 - 12:09 PM
Bomb Bloke #6
Posted 16 October 2015 - 03:25 PM
Ok it might be bug inside the advanced computer. Because when i use normal computer then every single item is with the table
item.fingerprint
found it when i was getting error
window: 94 : Arguments must be the same length 
.

In this post http://forum.feed-th...omputer.102138/ , thez saz that use normla computer. So i did and it is working.

That's related to a certain bug where CC 1.74's new term.blit() function can't properly tell the length of strings containing unicode characters. If you stick a "term.redirect(term.native())" up the top of your script, it should avoid the issue when running it on an advanced computer.

(Advanced computers use multishell, which renders everything through windows, which render everything through term.blit(). "Normal" computers don't have multishell and render everything through their native terminal directly by default.)

If i have program called keeplist and inside it table … can i use in difrent program this ?

Well, if you loaded the script with the table as an API, yes, you'd be able to reference it like that.

Assuming you cleaned up the table declaration so it'd compile, anyway. I'm guessing you were just putting down pseudocode there.

It may be worth noting that you can save most tables to a file using fs.open() and textutils.serialise():

local output = fs.open("someFile", "w")
output.writeLine(textutils.serialise(myTable))
output.close()

… and then read them back like so:

local input = fs.open("someFile", "r")
local myTable = textutils.unserialise(input.readAll())
input.close()
Edited on 16 October 2015 - 01:26 PM
Fousicek #7
Posted 16 October 2015 - 06:09 PM
Thank you very much. i was finaly able to do what i wanted and now i have to write the whole code.

For that file thing. It would be awesome but on the server it is not alowing me to do that.Probably bcs of the server. Or i am doing something wrong.

If i will have more questions " i ll be back " .

Thank you