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

How to use this string/table/array

Started by Delapid, 01 July 2013 - 02:53 PM
Delapid #1
Posted 01 July 2013 - 04:53 PM
Hello I have been really enjoying computer craft for a number of weeks (my first exposure to coding) and have been playing around with openccsensors. One the features of openccsensors is the card that can retrieve all sorts of information about players. I have wrote a program to store all of the information retrieved from the card onto a floppy disk. Each player has his relevant information stored within a directory on the disk. Within those files such as the file "IsSneaking" the file simply reads "true" or "false". I can cope with using this information using:

x = fs.open("disk/Username/IsSneaking", "r")
info  = x.readLine()
x.close()
print(info)
Giving me true or false.

My problem is for some files("/Inventory") I get an output like this :

{40.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 3.0={Name=Networking Cable, DamageValue=0.0, MaxStack=64.0, RawName=item.cccable, Size=47.0}, 15.0={Name=Glowstone Illuminator, DamageValue=0.0, MaxStack=64.0, RawName=device.lamp, Size=62.0}, 31.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 32.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 13.0={Name=Seeds, DamageValue=0.0, MaxStack=64.0, RawName=item.seeds, Size=17.0}, 27.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 11.0={Name=Proximity Sensor Card, DamageValue=4.0, MaxStack=64.0, RawName=item.openccsensors.proximitycard, Size=64.0}, 2.0={Name=Floppy Disk, DamageValue=0.0, MaxStack=1.0, RawName=item.ccdisk, Size=1.0}, 1.0={Name=Water, DamageValue=0.0, MaxStack=64.0, RawName=tile.water, Size=1.0}, 23.0={Name=Proximity Sensor Card, DamageValue=4.0, MaxStack=64.0, RawName=item.openccsensors.proximitycard, Size=63.0}, 33.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 9.0={Name=Fence, DamageValue=0.0, MaxStack=64.0, RawName=tile.fence, Size=1.0}, 19.0={Name=Lever, DamageValue=0.0, MaxStack=64.0, RawName=tile.lever, Size=61.0}, 30.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 6.0={Name=Etheric Sword, DamageValue=2.0, MaxStack=1.0, RawName=item.extrautils:ethericsword, Size=1.0}, 34.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 26.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 7.0={Name=Oak Wood Planks, DamageValue=0.0, MaxStack=64.0, RawName=tile.wood.oak, Size=4.0}, 4.0={Name=Advanced Computer, DamageValue=16384.0, MaxStack=64.0, RawName=item.ccadvancedcomputer, Size=62.0}, 22.0={Name=Proximity Sensor Card, DamageValue=1.0, MaxStack=64.0, RawName=item.openccsensors.proximitycard, Size=1.0}, 35.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 5.0={Name=Chainsaw, DamageValue=2.0, MaxStack=1.0, RawName=ic2.itemtoolchainsaw, Size=1.0}, 18.0={Name=Monitor, DamageValue=2.0, MaxStack=64.0, RawName=item.ccmonitor, Size=64.0}, 29.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 14.0={Name=Sensor, DamageValue=0.0, MaxStack=64.0, RawName=tile.openccsensors.sensor, Size=64.0}, 25.0={Name=Floppy Disk, DamageValue=0.0, MaxStack=1.0, RawName=item.ccdisk, Size=1.0}, 36.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 12.0={Name=Proximity Sensor Card, DamageValue=1.0, MaxStack=64.0, RawName=item.openccsensors.proximitycard, Size=63.0}, 21.0={Name=Potato, DamageValue=0.0, MaxStack=64.0, RawName=item.potato, Size=31.0}, 10.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 17.0={Name=Disk Drive, DamageValue=0.0, MaxStack=64.0, RawName=item.ccdiskdrive, Size=64.0}, 37.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 8.0={Name=Rose, DamageValue=0.0, MaxStack=64.0, RawName=tile.rose, Size=3.0}, 28.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 24.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 38.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}, 20.0={Name=Wheat, DamageValue=0.0, MaxStack=64.0, RawName=item.wheat, Size=12.0}, 16.0={Name=Wired Modem, DamageValue=1.0, MaxStack=64.0, RawName=item.ccwiredmodem, Size=63.0}, 39.0={Name=empty, MaxStack=64.0, Damagevalue=0.0, Size=0.0}}

This is one single line and I do not have a clue how to use this kind of information. I have tried things like print(info[3.0]) but they don't seem to work. If I were able to print all the items they have as a list (ignoring the other bits of information like MaxStack) that would be great. Any help would be greatly appreciated!
Lyqyd #2
Posted 02 July 2013 - 01:50 PM
Split into new topic.
theoriginalbit #3
Posted 02 July 2013 - 08:42 PM
Ok so after you have read the line from the file, use textutils.unserialize, this will make that string into a table, where you can then use info[3] etc for accessing the table.