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

[LUA][QUESTION] How do I get my program to recgonize the difference between "string.string@0" and "string.string@1" as different Items?

Started by tedraic, 18 November 2012 - 09:17 AM
tedraic #1
Posted 18 November 2012 - 10:17 AM
ok. I have been trying to learn LUA and it is coming along but I am having a problem with getting my program to recgonize the difference between designated strings as different items.

I am using Technic SSP and am trying to make a program that I can customize as the need asrises for different things but for right now I am in need of the program to be able to get the contents of the chest that I have set up for my Quarry to dump its resources into and then tell me what items are in there. I do not however want the standard item designation but rather a more simpliflied one.

Example.
Standard Designation: item.emerald@0
Simplified Output: Diamond

I have already been able to get the basics done with respect to normal items that have a @0 but anything that uses @1 or more I can not get the program to realize that this is a different Item. It will still count it as the @0 item.

Example.
Standard Designation ——- Simplified Output ——— Amount
item.tcicrystals@0 Vis Crystals 4
item.tcicrystals@1 Vaporous crystals 0

The program is not meant to output the Standard Designation at all but only the Simplified Designation and the amount of that item in the chest. and it auto updates every second.

It does work however, Even though I have 1 Vis Crystal, 1 Vaporous Crystal, 1 Firey Crystal, and 1 Tainted Crystal in the chest, it reads them all as item.tcicrystals@0 rather then 1 of each tcicrystals@0, @1, @4, and @5. So i get an output of 4 Vis Crystals.

In my code I do have some things commented out, which in on purpose until I am able to get the items that I am having problems with working and know how to fix the rest of them.

Any help would be greatly appreciated. Thank you all in advance


------------- Load API for sensors ------------
os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")

------------- Dictionary Printer --------------
function printDict(data)
for i,v in pairs(data) do
  print(tostring(i).." - "..tostring(v))
  end
end

----------------Table Sum Function-------------------------------
function sum(data)
		local sum = 0
		for k,v in pairs(data) do
				sum = sum + v
		end
		return sum
end

------------- TheCode -------------------------
--Specify Monitor Position
mon = peripheral.wrap('top')
--what side is controller on?
ctrl = sensors.getController()
--Specify the sensor
data = sensors.getSensors(ctrl)
quarrySensor = data[1]
--specify the probe(s)
data = sensors.getProbes(ctrl,quarrySensor)
inventoryContent = data[3]
--specify sensor target
data = sensors.getAvailableTargetsforProbe(ctrl,quarrySensor,inventoryContent)
quarryChest = data[5]
local pattern = "^(%d+)%*(%a+%.?%a+)@(%d+)"
local g = 0
local h = 1
while g ~= h do
local tableDirt = {}
local tableCobblestone = {}
--local tableMossStone = {}
local tableSand = {}
--local tableSandStone = {}
local tableGravel = {}
local tableObsidian = {}
local tableLapis = {}
local tableIronOre = {}
local tableGoldOre = {}
local tableCopperOre = {}
local tableTinOre = {}
local tableSilverOre = {}
local tableCoal = {}
local tableDiamond = {}
local tableRedstone = {}
local tableClay = {}
local tableFlint = {}
local tableUraniumOre = {}
--local tableEmerald = {}
local tableRuby = {}
--local tableSapphire = {}
local tableMarble = {}
--local tableBasaltCobble = {}
local tableVisCrystal = {}
--local tableVaporousCrystal = {}
--local tableAquaousCrystal = {}
--local tableFireyCrystal = {}
--local tableEarthenCrystal = {}
--local tableTaintedCrystal = {}
--local tableTungstonOre = {}
--local tableCinnabarOre = {}
--local tableNikolite = {}
data = sensors.getSensorReadingAsDict(ctrl,quarrySensor,quarryChest,inventoryContent)
--printDict(data)
mon.setTextScale(0.5)
mon.clear()
mon.setCursorPos(1,1)
term.redirect(mon)
term.clear()
--term.setCursorPos(2,2)
for i = 1, #data do
  local amount, item, slot = string.match( data[i], pattern )
  if item == "tile.dirt" then
   table.insert(tableDirt,amount)
  end
  if item == "tile.stonebrick" then
   table.insert(tableCobblestone,amount)
  end
  if item == "tile.sand" then
   table.insert(tableSand,amount)
  end
  if item == "tile.gravel" then
   table.insert(tableGravel,amount)
  end
  if item == "tile.obsidian" then
   table.insert(tableObsidian,amount)
  end
  if item == "item.coal" then
   table.insert(tableCoal,amount)
  end
  if item == "item.emerald" then
   table.insert(tableDiamond,amount)
  end
  if item == "item.redstone" then
   table.insert(tableRedstone,amount)
  end
  if item == "item.clay" then
   table.insert(tableClay,amount)
  end
  if item == "item.itemOreUran" then
   table.insert(tableUraniumOre,amount)
  end
--  if item == "item.dyepowder@4" then
--   table.insert(tableLapis,amount)
--  end
--  if item == "null@1" then
--   table.insert(tableEmerald,amount)
--  end
  if item == "null" then
   table.insert(tableRuby,amount)
  end
--  if item == "null@2" then
--   table.insert(tableSapphire,amount)
--  end
  if item == "tile.rpstone" then
   table.insert(tableMarble,amount)
  end
  if item == "tile.rpstone@3" then
   table.insert(tableBasaltCobble,amount)
  end
  if item == "item.tcicrystals" then
   table.insert(tableVisCrystal,amount)
  end
--  if item == "item.tcicrystals@1" then
--   table.insert(tableVaporousCrystal,amount)
--  end
--  if item == "item.tcicrystals@2" then
--   table.insert(tableAquaousCrystal,amount)
--  end
--  if item == "item.tcicrystals@3" then
--   table.insert(tableEarthenCrystal,amount)
--  end
--  if item == "item.tcicrystals@4" then
--   table.insert(tableFireyCrystal,amount)
--  end
--  if item == "item.tcicrystals@5" then
--   table.insert(tableTaintedCrystal,amount)
--  end
  if item == "tile.tcbcinnabarore" then
   table.insert(tableCinnarbarOre,amount)
  end
--  if item == "null@6" then
--   table.insert(tableNikolite,amount)
--  end
  if item == "tile.oreIron" then
   table.insert(tableIronOre,amount)
  end
  if item == "tile.oreGold" then
   table.insert(tableGoldOre,amount)
  end
  if item == "tile.oreCopper" then
   table.insert(tableCopperOre,amount)
  end
  if item == "tile.blockOreTin" then
   table.insert(tableTinOre,amount)
  end
  if item == "tile.rpores@3" then
   table.insert(tableSilverOre,amount)
end
		--print(tostring( item ).." "..tostring(amount))
end
print("Amount")
write(" Dirt:			  ")
data = tableDirt
print(sum(data))
write(" Cobblestone:	   ")
data = tableCobblestone
print(sum(data))
write(" Sand:			  ")
data = tableSand
print(sum(data))
write(" Gravel:			")
data = tableGravel
print(sum(data))
write(" Obsidian:		  ")
data = tableObsidian
print(sum(data))
write(" Coal:			  ")
data = tableCoal
print(sum(data))
write(" Diamonds:		  ")
data = tableDiamond
print(sum(data))
write(" Redstone:		  ")
data = tableRedstone
print(sum(data))
write(" Clay:			  ")
data = tableClay
print(sum(data))
write(" Uranium Ore:	   ")
data = tableUraniumOre
print(sum(data))
write(" Lapis Lazuli:	  ")
data = tableLapis
print(sum(data))
--write(" Emeralds:		  ")
--data = tableEmerald
--print(sum(data))
write(" Rubies:			")
data = tableRuby
print(sum(data))
--write(" Sapphires:		 ")
--data = tableSapphire
--print(sum(data))
write(" Marble:			")
data = tableMarble
print(sum(data))
--write(" BasaltCobble:	  ")
--data = tableBasaltCobble
--print(sum(data))
write(" Vis Crystals:	  ")
data = tableVisCrystal
print(sum(data))
--write(" Vaporous Crystals: ")
--data = tableVaporousCrystal
--print(sum(data))
--write(" Aquaous Crystals:  ")
--data = tableAquaousCrystal
--print(sum(data))
--write(" Earthen Crystals:	")
--data = tableEarthenCrystal
--print(sum(data))
--write(" Firey Crystals:	  ")
--data = tableFireyCrystal
--print(sum(data))
--write(" Tainted Crystals:  ")
--data = tableTaintedCrystal
--print(sum(data))
write(" Iron Ore:		  ")
data = tableIronOre
print(sum(data))
write(" Gold Ore:		  ")
data = tableGoldOre
print(sum(data))
write(" Copper Ore:		")
data = tableCopperOre
print(sum(data))
write(" Tin Ore:		   ")
data = tableTinOre
print(sum(data))
write(" Silver Ore:		")
data = tableSilverOre
print(sum(data))


sleep(1)
end

Edited by
remiX #2
Posted 18 November 2012 - 10:19 AM
Can you please use
[*code][*/code]
tags so it keeps the indentation and it's easier to read.
tedraic #3
Posted 18 November 2012 - 11:58 AM
ok.. Is that any better? Honestly, It looks the same to me but.. Oh well….
billysback #4
Posted 19 November 2012 - 01:04 AM
you could clean this up by doing:

database = {}
instead of all of those functions then run this function everytime you want to insert something in to the database:

local function insertData(data_type, amount)
local n = database[data_type]
if n = nil then database[data_type] = amount else
database[data_type] = n+amount
end
end
so run that instead of

table.insert()

then for printing the values of the data base you can just do:

local line = "					  "
for k,v in pairs(database) do
local fline = k..string.sub(line, string.len(k)+1, -1)..":"
print(fline.." "..v)
end

just doing some cleaning, you don't HAVE to do it like this but it would make it so much cleaner :)/>/>
tedraic #5
Posted 19 November 2012 - 08:36 AM
Hey billysback,

I wanted to thank you for the suggestions and I have been trying to figure out where to insert the code that you provided and what it replaces but, I am at a loss… Not exactly sure what replaces what…

Like I had said in my original post. I am learning but do not really know alot about the Language as of yet.. And I just found out from my brother-in-law that it is different for different games which might be why It has taken me 3 months to get to this point as I have been looking mostly at the basic Language rather then the MineCraft, ComuterCraft specific functions and such.. Hopefully with this new found information I will be further along in my learning within the next month or so.. :)/>/>

Also, to anyone and everyone else… I still have not heard anything about my original question… Could someone please offer some assistance? I am not looking for someone to write the code for me but rather give me ideas and suggestions that would help me to be able to get the results that I am looking for. Thanks in advance for any assistance..

And thanks again billysback.
Orwell #6
Posted 19 November 2012 - 08:46 AM
Could you post the complete format of a string in data? If it's like this: 3*item.tcicrystals@1 then I think what your problem is.
You define the pattern as follows:

local pattern = "^(%d+)%*(%a+%.?%a+)@(%d+)"
Then you parse the formatted string in this line:

local amount, item, slot = string.match( data[i], pattern )
So what comes after the @ symbol gets put in the variable slot. But if I get it right, the number after @ is the metadata (damage value) of the item. So, wouldn't this work?

local amount, item, meta = string.match( data[i], pattern )
meta = tonumber(meta)
...
if item == "item.tcicrystals" and meta == 1 then
  ...
end

Also, read up about elseif, it'll help you making this shorter and cleaner. :)/>/>
tedraic #7
Posted 19 November 2012 - 09:01 AM
Yes, the complete string in data would be as follows: tile.rpores@3 .. and yes. the @3 does indeed signify the damage value. so,

you would have something like this..

ITEM ITEM DESIGNATION
Vis Crystal = item.tcicrystals@0 – (Undamaged Base Item)
Vaporous Crystal = item.tcicrystals@1 – (base item damage value 1 as different item)

And yes.. looking at the code.. I do believe that would work.. I had not even thought about that option.. lol …. thanks and I will let you know if it does in fact give the desired results.

And as far as the elseif statement goes. I am basically trying to get the desired results then I was going to be working with the elseif to clean it up.. LOL .. I kinda do things oddly when I program.. Sort of like writing a book.. What you are looking at right now it the rough draft and I will be fine tuning it once the rough draft is finished. At the same time condensing it and maybe even tweaking it a bit in the process… :)/>/> ..

I do appreciate the input and will be taking a look at elseif within the next hour or so… thanks again Orwell.
billysback #8
Posted 19 November 2012 - 09:26 AM
Do:

database = {}

local function insertData(data_type, amount)
   local n = database[data_type]
   if n = nil then database[data_type] = amount else
	  database[data_type] = n+amount
   end
end

for i = 1, #data do
  local amount, item, slot = string.match( data[i], pattern )
  if item == "tile.dirt" then
   insertData("dirt",amount)
  end
  if item == "tile.stonebrick" then
   insertData("stonebrick",amount)
  end
  if item == "tile.sand" then
   insertData("sand",amount)
  end
  --etc
end


local line = "	          		    "
for k,v in pairs(database) do
local fline = k..string.sub(line, string.len(k)+1, -1)..":"
print(fline.." "..v)
end

instead of:
Spoiler

local tableDirt = {}
local tableCobblestone = {}
--local tableMossStone = {}
local tableSand = {}
--local tableSandStone = {}
local tableGravel = {}
local tableObsidian = {}
local tableLapis = {}
local tableIronOre = {}
local tableGoldOre = {}
local tableCopperOre = {}
local tableTinOre = {}
local tableSilverOre = {}
local tableCoal = {}
local tableDiamond = {}
local tableRedstone = {}
local tableClay = {}
local tableFlint = {}
local tableUraniumOre = {}
--local tableEmerald = {}
local tableRuby = {}
--local tableSapphire = {}
local tableMarble = {}
--local tableBasaltCobble = {}
local tableVisCrystal = {}
--local tableVaporousCrystal = {}
--local tableAquaousCrystal = {}
--local tableFireyCrystal = {}
--local tableEarthenCrystal = {}
--local tableTaintedCrystal = {}
--local tableTungstonOre = {}
--local tableCinnabarOre = {}
--local tableNikolite = {}
data = sensors.getSensorReadingAsDict(ctrl,quarrySensor,quarryChest,inventoryContent)
--printDict(data)
mon.setTextScale(0.5)
mon.clear()
mon.setCursorPos(1,1)
term.redirect(mon)
term.clear()
--term.setCursorPos(2,2)
for i = 1, #data do
  local amount, item, slot = string.match( data[i], pattern )
  if item == "tile.dirt" then
   table.insert(tableDirt,amount)
  end
  if item == "tile.stonebrick" then
   table.insert(tableCobblestone,amount)
  end
  if item == "tile.sand" then
   table.insert(tableSand,amount)
  end
  if item == "tile.gravel" then
   table.insert(tableGravel,amount)
  end
  if item == "tile.obsidian" then
   table.insert(tableObsidian,amount)
  end
  if item == "item.coal" then
   table.insert(tableCoal,amount)
  end
  if item == "item.emerald" then
   table.insert(tableDiamond,amount)
  end
  if item == "item.redstone" then
   table.insert(tableRedstone,amount)
  end
  if item == "item.clay" then
   table.insert(tableClay,amount)
  end
  if item == "item.itemOreUran" then
   table.insert(tableUraniumOre,amount)
  end
--  if item == "item.dyepowder@4" then
--   table.insert(tableLapis,amount)
--  end
--  if item == "null@1" then
--   table.insert(tableEmerald,amount)
--  end
  if item == "null" then
   table.insert(tableRuby,amount)
  end
--  if item == "null@2" then
--   table.insert(tableSapphire,amount)
--  end
  if item == "tile.rpstone" then
   table.insert(tableMarble,amount)
  end
  if item == "tile.rpstone@3" then
   table.insert(tableBasaltCobble,amount)
  end
  if item == "item.tcicrystals" then
   table.insert(tableVisCrystal,amount)
  end
--  if item == "item.tcicrystals@1" then
--   table.insert(tableVaporousCrystal,amount)
--  end
--  if item == "item.tcicrystals@2" then
--   table.insert(tableAquaousCrystal,amount)
--  end
--  if item == "item.tcicrystals@3" then
--   table.insert(tableEarthenCrystal,amount)
--  end
--  if item == "item.tcicrystals@4" then
--   table.insert(tableFireyCrystal,amount)
--  end
--  if item == "item.tcicrystals@5" then
--   table.insert(tableTaintedCrystal,amount)
--  end
  if item == "tile.tcbcinnabarore" then
   table.insert(tableCinnarbarOre,amount)
  end
--  if item == "null@6" then
--   table.insert(tableNikolite,amount)
--  end
  if item == "tile.oreIron" then
   table.insert(tableIronOre,amount)
  end
  if item == "tile.oreGold" then
   table.insert(tableGoldOre,amount)
  end
  if item == "tile.oreCopper" then
   table.insert(tableCopperOre,amount)
  end
  if item == "tile.blockOreTin" then
   table.insert(tableTinOre,amount)
  end
  if item == "tile.rpores@3" then
   table.insert(tableSilverOre,amount)
end
				--print(tostring( item ).." "..tostring(amount))
end
print("Amount")
write(" Dirt:					 ")
data = tableDirt
print(sum(data))
write(" Cobblestone:	   ")
data = tableCobblestone
print(sum(data))
write(" Sand:					 ")
data = tableSand
print(sum(data))
write(" Gravel:				 ")
data = tableGravel
print(sum(data))
write(" Obsidian:				 ")
data = tableObsidian
print(sum(data))
write(" Coal:					 ")
data = tableCoal
print(sum(data))
write(" Diamonds:				 ")
data = tableDiamond
print(sum(data))
write(" Redstone:				 ")
data = tableRedstone
print(sum(data))
write(" Clay:					 ")
data = tableClay
print(sum(data))
write(" Uranium Ore:	   ")
data = tableUraniumOre
print(sum(data))
write(" Lapis Lazuli:	 ")
data = tableLapis
print(sum(data))
--write(" Emeralds:			   ")
--data = tableEmerald
--print(sum(data))
write(" Rubies:				 ")
data = tableRuby
print(sum(data))
--write(" Sapphires:			 ")
--data = tableSapphire
--print(sum(data))
write(" Marble:				 ")
data = tableMarble
print(sum(data))
--write(" BasaltCobble:   ")
--data = tableBasaltCobble
--print(sum(data))
write(" Vis Crystals:	 ")
data = tableVisCrystal
print(sum(data))
--write(" Vaporous Crystals: ")
--data = tableVaporousCrystal
--print(sum(data))
--write(" Aquaous Crystals:  ")
--data = tableAquaousCrystal
--print(sum(data))
--write(" Earthen Crystals:	 ")
--data = tableEarthenCrystal
--print(sum(data))
--write(" Firey Crystals:		 ")
--data = tableFireyCrystal
--print(sum(data))
--write(" Tainted Crystals:  ")
--data = tableTaintedCrystal
--print(sum(data))
write(" Iron Ore:				 ")
data = tableIronOre
print(sum(data))
write(" Gold Ore:				 ")
data = tableGoldOre
print(sum(data))
write(" Copper Ore:			 ")
data = tableCopperOre
print(sum(data))
write(" Tin Ore:				   ")
data = tableTinOre
print(sum(data))
write(" Silver Ore:			 ")
data = tableSilverOre
print(sum(data))



EDIT:
btw where the line value is initialized the amount of spaces in that string is how long you want each line to be before the number is inputted, this is there so that all numbers are at the same x point in the terminal/monitor…
tedraic #9
Posted 19 November 2012 - 09:30 AM
Ok, Orwell,

I changed the code and implemented your suggestion and not only did that do the trick but it also took care of another problem that I was having in compensating for null items.. such as null@6 which is the designation for Nikolite. Now it works perfectly… :)/>/> …

thanks Billsback… I am just now reading your post so if you can give me a few minutes to make the changes and incorporate it into the new code.. I will let you know how it works.. and if i can figure out how to take a screen shot and post it here, I will let you all see the results so far.. :D/>/>
Orwell #10
Posted 19 November 2012 - 09:35 AM
Billysback has a good point in simplifying your code (it was quite elaborate :)/>/> ). Only, you'd want to change this line:

if n = nil then database[data_type] = amount else
into this:

if n == nil then database[data_type] = amount else
(Everyone makes that mistake once in a while.)
tedraic #11
Posted 19 November 2012 - 09:56 AM
LOL .. Yep yep.. I already caught that and fixed it when I started making the changes to the code.. :)/>/> .. Thanks for the heads up though.
tedraic #12
Posted 19 November 2012 - 11:39 AM
ok.. I think that I have figured out how to add the screen shots so.. here goes..

for the code update that was done with Orwells suggestion here is the results and the code.

I get the results that I am looking for: A self updating, readings output of the container information at the top with a sorted and parsed,(to simplified format), list of the items in the chest as they come in or go out. self Updating every second

Spoiler

Spoiler————- Load API for sensors ————
os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")

————- Dictionary Printer ————–
function printDict(data)
for i,v in pairs(data) do
print(tostring(i).." - "..tostring(v))
end
end

—————-Table Sum Function——————————-
function sum(data)
local sum = 0
for k,v in pairs(data) do
sum = sum + v
end
return sum
end

————- TheCode ————————-
————- Specify Monitor Position ————————-
mon = peripheral.wrap('top')

————- Get Controller side ————————-
ctrl = sensors.getController()

————- Specify the Sensor ————————-
data = sensors.getSensors(ctrl)
quarrySensor = data[1]

————- Specify the Probe(s) ————————-
data = sensors.getProbes(ctrl,quarrySensor)
inventoryInfo = data[2]
inventoryContent = data[3]

————- Specify Sensor Target ————————-
data = sensors.getAvailableTargetsforProbe(ctrl,quarrySensor,inventoryInfo)
quarryChest = data[5]
data = sensors.getAvailableTargetsforProbe(ctrl,quarrySensor,inventoryContent)
quarryChest = data[5]

————- Redirect Terminal to monitor ————————-
term.redirect(mon)
mon.setTextScale(0.5)
mon.clear()

————- Pattern & table Declarations ————————-
local pattern = "^(%d+)%*(%a+%.?%a+)@(%d+)"
local g = 0
local h = 1
while g ~= h do
local tableObsidian = {}
local tableLapis = {}
local tableCoal = {}
local tableDiamond = {}
local tableRedstone = {}
local tableRuby = {}
local tableEmerald = {}
local tableSapphire = {}
local tableVisC = {}
local tableVapC = {}
local tableAquC = {}
local tableEarC = {}
local tableFirC = {}
local tableTaiC = {}
local tableTungstonOre = {}
local tableCinnabarOre = {}
local tableNikolite = {}
local tableIronOre = {}
local tableGoldOre = {}
local tableCopperOre = {}
local tableTinOre = {}
local tableSilverOre = {}
local tableUraniumOre = {}

ICdata = sensors.getSensorReadingAsDict(ctrl,quarrySensor,quarryChest,inventoryContent)

for i = 0, #ICdata do
local amount, item, meta = string.match( ICdata, pattern )
meta = tonumber(meta)

if item == "tile.obsidian" and meta == 0 then
table.insert(tableObsidian,amount)
end
if item == "item.coal" and meta == 0 then
table.insert(tableCoal,amount)
end
if item == "item.emerald" and meta == 0 then
table.insert(tableDiamond,amount)
end
if item == "item.redstone" and meta == 0 then
table.insert(tableRedstone,amount)
end
if item == "item.dyepowder" and meta == 4 then
table.insert(tableLapis,amount)
end
if item == "null" and meta == 0 then
table.insert(tableRuby,amount)
end
if item == "null" and meta == 1 then
table.insert(tableEmerald,amount)
end
if item == "null" and meta == 2 then
table.insert(tableSapphire,amount)
end
if item == "item.tcicrystals" and meta == 0 then
table.insert(tableVisC,amount)
end
if item == "item.tcicrystals" and meta == 1 then
table.insert(tableVapC,amount)
end
if item == "item.tcicrystals" and meta == 2 then
table.insert(tableAquC,amount)
end
if item == "item.tcicrystals" and meta == 3 then
table.insert(tableEarC,amount)
end
if item == "item.tcicrystals" and meta == 4 then
table.insert(tableFirC,amount)
end
if item == "item.tcicrystals" and meta == 5 then
table.insert(tableTaiC,amount)
end
if item == "tile.tcbcinnabarore" and meta == 0 then
table.insert(tableCinnabarOre,amount)
end
if item == "null" and meta == 6 then
table.insert(tableNikolite,amount)
end
if item == "tile.oreIron" and meta == 0 then
table.insert(tableIronOre,amount)
end
if item == "tile.oreGold" and meta == 0 then
table.insert(tableGoldOre,amount)
end
if item == "tile.blockOreCopper" and meta == 0 then
table.insert(tableCopperOre,amount)
end
if item == "tile.blockOreTin" and meta == 0 then
table.insert(tableTinOre,amount)
end
if item == "tile.rpores" and meta == 3 then
table.insert(tableSilverOre,amount)
end
if item == "item.itemOreUran" and meta == 0 then
table.insert(tableUraniumOre,amount)
end
if item == "item.tungstoneOre" and meta == 0 then
table.insert(tableTungstoneOre,amount)
end
–print(tostring( item ).." "..tostring(amount))
end

————- Print Inventory Info ————————-
mon.setCursorPos(1,1)
IIdata = sensors.getSensorReadingAsDict(ctrl,quarrySensor,quarryChest,inventoryInfo)
printDict(IIdata)

————- Print Inventory Content ————————-
mon.setCursorPos(1,6)
print("ORES:")
write(" Iron: ")
data = tableIronOre
print(sum(data))
write(" Gold: ")
data = tableGoldOre
print(sum(data))
write(" Copper: ")
data = tableCopperOre
print(sum(data))
write(" Tin: ")
data = tableTinOre
print(sum(data))
write(" Silver: ")
data = tableSilverOre
print(sum(data))
write(" Cinnabar: ")
data = tableCinnabarOre
print(sum(data))
write(" Tungston: ")
data = tableTungstonOre
print(sum(data))
print("FUELS:")
write(" Coal: ")
data = tableCoal
print(sum(data))
write(" Uranium: ")
data = tableUraniumOre
print(sum(data))
print("DUSTS/POWDERS:")
write(" Redstone: ")
data = tableRedstone
print(sum(data))
write(" Nikolite: ")
data = tableNikolite
print(sum(data))
write(" Lapis: ")
data = tableLapis
print(sum(data))
print("BLOCKS:")
write(" Obsidian: ")
data = tableObsidian
print(sum(data))

mon.setCursorPos(19,6)
print("CRYSTALS:")
mon.setCursorPos(19,7)
write(" Vis: ")
data = tableVisC
print(sum(data))
mon.setCursorPos(19,8)
write(" Vaporous: ")
data = tableVapC
print(sum(data))
mon.setCursorPos(19,9)
write(" Aquaous: ")
data = tableAquC
print(sum(data))
mon.setCursorPos(19,10)
write(" Earthen: ")
data = tableEarC
print(sum(data))
mon.setCursorPos(19,11)
write(" Firey: ")
data = tableFirC
print(sum(data))
mon.setCursorPos(19,12)
write(" Tainted: ")
data = tableTaiC
print(sum(data))
mon.setCursorPos(19,13)
print("GEMS:")
mon.setCursorPos(19,14)
write(" Diamonds: ")
data = tableDiamond
print(sum(data))
mon.setCursorPos(19,15)
write(" Rubies: ")
data = tableRuby
print(sum(data))
mon.setCursorPos(19,16)
write(" Emeralds: ")
data = tableEmerald
print(sum(data))
mon.setCursorPos(19,17)
write(" Sapphires: ")
data = tableSapphire
print(sum(data))

sleep(1)
end

And for the code update done with Billysback suggestion and trying to implement it along with Orwells suggestion, here is the results and code.

Honestly, not what I was looking for but, I am sure that with a little bit of practice and some major editing, I will be able to get the two codes to work together and still give me the desired results. So far with this code I have the Container Info at the top, and the parsed, (simplified form,) item info but, it is not self updating, nor am I able to get it to sort the items as of yet.

Spoiler

Spoiler————- Load API for sensors ————
os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")

————- Dictionary Printer ————–
function printDict(data)
for i,v in pairs(data) do
print(tostring(i).." - "..tostring(v))
end
end

—————-Table Sum Function——————————-
function sum(data)
local sum = 0
for k,v in pairs(data) do
sum = sum + v
end
return sum
end

————- TheCode ————————-
————- Specify Monitor Position ————————-
mon = peripheral.wrap('top')

————- Get Controller side ————————-
ctrl = sensors.getController()

————- Specify the Sensor ————————-
data = sensors.getSensors(ctrl)
quarrySensor = data[1]

————- Specify the Probe(s) ————————-
data = sensors.getProbes(ctrl,quarrySensor)
inventoryInfo = data[2]
inventoryContent = data[3]

————- Specify Sensor Target ————————-
data = sensors.getAvailableTargetsforProbe(ctrl,quarrySensor,inventoryInfo)
quarryChest = data[5]
data = sensors.getAvailableTargetsforProbe(ctrl,quarrySensor,inventoryContent)
quarryChest = data[5]

————- Redirect Terminal to monitor ————————-
term.redirect(mon)
mon.setTextScale(0.5)
mon.clear()

————- Pattern & table Declarations ————————-
local pattern = "^(%d+)%*(%a+%.?%a+)@(%d+)"

database = {}
local function insertData(data_type, amount)
local n = database[data_type]
if n == nil then database[data_type] = amount else
database[data_type] = n+amount
end
end

ICdata = sensors.getSensorReadingAsDict(ctrl,quarrySensor,quarryChest,inventoryContent)

for i = 1, #ICdata do
local amount, item, meta = string.match( ICdata, pattern )
meta = tonumber(meta)

if item == "tile.obsidian" and meta == 0 then
insertData("Obsidian",amount)
end
if item == "item.coal" and meta == 0 then
insertData("Coal",amount)
end
if item == "item.emerald" and meta == 0 then
insertData("Diamond",amount)
end
if item == "item.redstone" and meta == 0 then
insertData("Redstone",amount)
end
if item == "item.dyepowder" and meta == 4 then
insertData("Lapis",amount)
end
if item == "null" and meta == 0 then
insertData("Ruby",amount)
end
if item == "null" and meta == 1 then
insertData("Emerald",amount)
end
if item == "null" and meta == 2 then
insertData("Sapphire",amount)
end
if item == "item.tcicrystals" and meta == 0 then
insertData("VisC",amount)
end
if item == "item.tcicrystals" and meta == 1 then
insertData("VapC",amount)
end
if item == "item.tcicrystals" and meta == 2 then
insertData("AquC",amount)
end
if item == "item.tcicrystals" and meta == 3 then
insertData("EarC",amount)
end
if item == "item.tcicrystals" and meta == 4 then
insertData("FirC",amount)
end
if item == "item.tcicrystals" and meta == 5 then
insertData("TaiC",amount)
end
if item == "tile.tcbcinnabarore" and meta == 0 then
insertData("CinnabarOre",amount)
end
if item == "null" and meta == 6 then
insertData("Nikolite",amount)
end
if item == "tile.oreIron" and meta == 0 then
insertData("IronOre",amount)
end
if item == "tile.oreGold" and meta == 0 then
insertData("GoldOre",amount)
end
if item == "tile.blockOreCopper" and meta == 0 then
insertData("CopperOre",amount)
end
if item == "tile.blockOreTin" and meta == 0 then
insertData("TinOre",amount)
end
if item == "tile.rpores" and meta == 3 then
insertData("SilverOre",amount)
end
if item == "item.itemOreUran" and meta == 0 then
insertData("UraniumOre",amount)
end
if item == "item.tungstoneOre" and meta == 0 then
insertData("TungstoneOre",amount)
end
–print(tostring( item ).." "..tostring(amount))
end

————- Print Inventory Info ————————-
mon.setCursorPos(1,1)
IIdata = sensors.getSensorReadingAsDict(ctrl,quarrySensor,quarryChest,inventoryInfo)
printDict(IIdata)

————- Print Inventory Content ————————-
mon.setCursorPos(1,6)
print("ORES:")

local line = " "
for k,v in pairs(database) do
local fline = k..string.sub(line, string.len(k)+1, -1)..":"
print(fline.." "..v)
sleep(1)
end


I do want to thank you both for your help, and if either of you or anyone else has anything else to offer or suggest to make this work better, cleaner code, etc. All while giving me the results that I am looking for, (1st results and code section here), then I would greatly appreciate it.

thanks again..
billysback #13
Posted 19 November 2012 - 11:45 AM
That actually looks really good to me, what did you want this to turn out like?
tedraic #14
Posted 19 November 2012 - 12:23 PM
I am going to be setting up several buildings in my area of the world.. Each will be housing it's own thing.. Such as a Power Plant, Mass Factory, Resource Sorting and Distribution Center, Etc. Etc. Etc..

the idea behind this program is something that can be tweaked with as little code as possible to conform to each buildings function.. This specific code is going to be for the resource Sorting / Distribution Center..

When I set up a Quarry the quarry's mined resources will go into a chest in the Resource center, From there I will get the readout showing what has been mined… When the chest is almost full, something will activate to pump the items out and into a sorter, from there they will get sorted into their own respective chests.. From that point, when I need say…. Iron Ore for something, I can send a request and the Iron Ore will be sent to a Furnace, be smelted, and Smelted again if it is Refined Iron that I requested, then sent to the Resource Deliver chest.

The building that you see in the Screen Shots is my Control Center, This is where I will be able to go to see all of the info on all of the different buildings, as well as the creatures that are within range of my building's perimeter defenses. It is going to look very similar to a large Military base control room when I am finished with it.. The Building's will all have a perimeter of about 6 - 8 meters with sensors set up to pick up any entity within range, and defenses, (Tesla Coils), set up so that they will be able to hit ANYTHING within range of the sensors… Basically, nothing will be able to get close to my buildings as long as the Defenses are active.. I may make it all automated but, I am not sure about that part yet as I really do not want to be walking by a defense post then have a creeper or something else sneak up on me then we both get zapped by my defense grid.. LOL

But yeah… that is the basic Idea.. I will be fine tuning it as I play though.
Orwell #15
Posted 19 November 2012 - 12:26 PM
Indeed, I'm impressed, I'm going to use your program as when it's finished. :)/>/>

[don't mind what I was doing here, didn't find the error >.<]
tedraic #16
Posted 19 November 2012 - 12:36 PM
Thanks Orwell, and you are more then welcome to use it.. I will actually post it under the APIs section of this forums for anyone to use when it is finished and will send you the link to it if you would like..

the only issue that I seem to be having right at the moment is that from time to time, I have not yet narrowed down what is causing it to happen, but from time to time the program stops running and returns the Error: string expected on line 80


79 for i = 0, #ICdata do
80  local amount, item, meta = string.match( ICdata[i], pattern )
81  meta = tonumber(meta)

As you can see in the code excerpt above, Line 80 should not be giving me that error.. So yeah.. As soon as I trace down the cause of it, that might give me a clue as to how to fix it.. LOL
Orwell #17
Posted 19 November 2012 - 12:44 PM
Thanks Orwell, and you are more then welcome to use it.. I will actually post it under the APIs section of this forums for anyone to use when it is finished and will send you the link to it if you would like..

the only issue that I seem to be having right at the moment is that from time to time, I have not yet narrowed down what is causing it to happen, but from time to time the program stops running and returns the Error: string expected on line 80


79 for i = 0, #ICdata do
80  local amount, item, meta = string.match( ICdata[i], pattern )
81  meta = tonumber(meta)

As you can see in the code excerpt above, Line 80 should not be giving me that error.. So yeah.. As soon as I trace down the cause of it, that might give me a clue as to how to fix it.. LOL
You should let the for loop start at 1, zero is not a valid index in lua. :)/>/> So ICdata is actually nil when i==0.
tedraic #18
Posted 19 November 2012 - 12:48 PM
ok.. dugh…. I feel stupid now.. LOL … I should have figured that out.. Oh well… pain meds must be kicking in.. Sorry, I recently had Major surgery and the doc. said that I will not be healed enough to even think about look for any kind of work for at least 3 months after.. it has been slightly less then a month at this point.. LOL …
tedraic #19
Posted 19 November 2012 - 07:30 PM
Umm, I am getting ready to head to bed at the moment but, I do have another question of some import about the program… Is there any way to make it an auto start program on world load perhaps?? So that when I load up my world I do not have to run around and start all the different programs that should be running through out my session?

This would be really awesome if there is… Any help with this one by any chance?

Thanks in advance.
remiX #20
Posted 19 November 2012 - 09:52 PM
When you exit the chunk stops and therefor PC in game shutsdown. Name the program startup within the computer and all you have to open it. I'm not sure there is any other way
MaHuJa #21
Posted 20 November 2012 - 01:38 AM
When a computer is started - such as when its chunk is loaded - it will run the /startup program. This program can then start your program using dofile() shell.run() os.exec() or similar - or even BE your program.
If there's a disk drive with a disk in it, /disk/startup takes priority.
tedraic #22
Posted 20 November 2012 - 08:57 AM
Hey Guys and or Girls,

I have another conundrum that I have been pondering and experimenting with but am so far unable to get the desired results.. To be honest, I am unable to get any results other then 'bad argument' or some other such error message.

not sure if I can post it here or if I need to start a new thread as it is on the same program that I originally posted this thread about but a different problem.. i will post the question, code, and desired results here but, if i should open a new thread then please let me know and I will do so.. thanks in advance for any help and or suggestions.

Desired results: Add in the blank top right portion of my monitor a couple of different lines that show specific information from a BuildCraft Sensor. I don't need all of the info from the Sensor that getReadings provides however, just the things listed below. It should look like this:

Active: Yes – (if active), No (in not active)
H.Pos: X:###, Y:###, Z:### – (H.Pos = Head Position of the Quarry.)

These are things that the specific Probe can provide but, I am having a major problem parsing the specific info and returning it as a string that can then be printed out on to the monitor.

Spoiler

Spoiler

------------- Program Information ------------------------------------
-- Auto Running on Chunk / Game Load					 		 --
-- Auto updating Information												 --
-- Info printed to 2*2 monitor												 --
-- Info currently included:													  --
-- Quarry Resource Collection Point Info							  --
-- Resource Collection Point contents Info					   	 --
-- Info currently working on:												  --
-- Quarry Active / Not Active status,									  --
-- Quarry Head Position X, Y, Z Coords.								--
--																						   --
-- Program written by: Tedraic											   --
-- Current contributors; computercraft.info							--
-- ComputerCraft | Programmable Computers for Minecraft  --
-- | ComputerCraft | Ask a Pro: Orwell								   --
-----------------------------------------------------------------------------

------------- Load API for sensors ------------
os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")

------------- Dictionary Printer --------------
function printDict(data)
  for i,v in pairs(data) do
	print(tostring(i).." - "..tostring(v))
  end
end

----------------Table Sum Function-------------------------------
function sum(data)
  local sum = 0
	for k,v in pairs(data) do
	  sum = sum + v
	end
  return sum
end

------------- TheCode -------------------------
------------- Specify Monitor Position -------------------------
mon = peripheral.wrap('top')

------------- Get Controller side -------------------------
ctrl = sensors.getController()

------------- Specify the Sensor -------------------------
data = sensors.getSensors(ctrl)
  QuarrySensorA = data[2]
  QuarrySensorB = data[1]

------------- Specify the Probe(s) -------------------------
data = sensors.getProbes(ctrl,QuarrySensorA)
  Quarry = data[5]
data = sensors.getProbes(ctrl,QuarrySensorB)
  inventoryInfo = data[2]
  inventoryContent = data[3]

------------- Specify Sensor Target -------------------------
data = sensors.getAvailableTargetsforProbe(ctrl,QuarrySensorA,Quarry)
  QuarryInfo = data[4]
data = sensors.getAvailableTargetsforProbe(ctrl,QuarrySensorB,inventoryInfo)
  QuarryChest = data[5]
data = sensors.getAvailableTargetsforProbe(ctrl,QuarrySensorB,inventoryContent)
  QuarryChest = data[5]

------------- Redirect Terminal to monitor -------------------------
term.redirect(mon)
mon.setTextScale(0.5)
mon.clear()

------------- Pattern &amp; table Declarations -------------------------
local pattern = "^(%d+)%*(%a+%.?%a+)@(%d+)"
  local g = 0
  local h = 1
	while g ~= h do
---- Ores ----
	  local tableIronOre = {}
	  local tableGoldOre = {}
	  local tableCopperOre = {}
	  local tableTinOre = {}
	  local tableSilverOre = {}
	  local tableCinnabarOre = {}
	  local tableTungstonOre = {}
---- Crystals ----
	  local tableVisC = {}
	  local tableVapC = {}
	  local tableAquC = {}
	  local tableEarC = {}
	  local tableFirC = {}
	  local tableTaiC = {}
---- Blocks ----
	  local tableDirt = {}
	  local tableCobblestone = {}
	  local tableObsidian = {}
	  local tableMarble = {}
---- Fuels ----
	  local tableCoal = {}
	  local tableUraniumOre = {}
---- Dusts &amp; Powders ----
	  local tableRedstone = {}
	  local tableNikolite = {}
	  local tableLapis = {}
---- Gems ----
	  local tableDiamond = {}
	  local tableRuby = {}
	  local tableEmerald = {}
	  local tableSapphire = {}

------------- Table Information Insertion -------------------------
ICdata = sensors.getSensorReadingAsDict(ctrl,QuarrySensorB,quarryChest,inventoryContent)

for i = 1, #ICdata do
  local amount, item, meta = string.match( ICdata[i], pattern )
  meta = tonumber(meta)
---- Ores ----
  if item == "tile.oreIron" and meta == 0 then
	table.insert(tableIronOre,amount)
  end
  if item == "tile.oreGold" and meta == 0 then
	table.insert(tableGoldOre,amount)
  end
  if item == "tile.blockOreCopper" and meta == 0 then
	table.insert(tableCopperOre,amount)
  end
  if item == "tile.blockOreTin" and meta == 0 then
	table.insert(tableTinOre,amount)
  end
  if item == "tile.rpores" and meta == 3 then
	table.insert(tableSilverOre,amount)
  end
  if item == "tile.tcbcinnabarore" and meta == 0 then
	table.insert(tableCinnabarOre,amount)
  end
  if item == "item.tungstoneOre" and meta == 0 then
	table.insert(tableTungstoneOre,amount)
  end
---- Crystals ----
  if item == "item.tcicrystals" and meta == 0 then
	table.insert(tableVisC,amount)
  end
  if item == "item.tcicrystals" and meta == 1 then
	table.insert(tableVapC,amount)
  end
  if item == "item.tcicrystals" and meta == 2 then
	table.insert(tableAquC,amount)
  end
  if item == "item.tcicrystals" and meta == 3 then
	table.insert(tableEarC,amount)
  end
  if item == "item.tcicrystals" and meta == 4 then
	table.insert(tableFirC,amount)
  end
  if item == "item.tcicrystals" and meta == 5 then
	table.insert(tableTaiC,amount)
  end
---- Blocks ----
  if item == "tile.dirt" and meta == 0 then
	table.insert(tableDirt,amount)
  end
  if item == "tile.stonebrick" and meta == 0 then
	table.insert(tableCobblestone,amount)
  end
  if item == "tile.obsidian" and meta == 0 then
	table.insert(tableObsidian,amount)
  end
  if item == "tile.rpstone" and meta == 0 then
	table.insert(tableMarble,amount)
  end
---- Fuels ----
  if item == "item.coal" and meta == 0 then
	table.insert(tableCoal,amount)
  end
  if item == "item.itemOreUran" and meta == 0 then
	table.insert(tableUraniumOre,amount)
  end
---- Dusts &amp; Powders ----
  if item == "item.redstone" and meta == 0 then
	table.insert(tableRedstone,amount)
  end
  if item == "null" and meta == 6 then
	table.insert(tableNikolite,amount)
  end
  if item == "item.dyepowder" and meta == 4 then
	table.insert(tableLapis,amount)
  end
---- Gems ----
  if item == "item.emerald" and meta == 0 then
	table.insert(tableDiamond,amount)
  end
  if item == "null" and meta == 0 then
	table.insert(tableRuby,amount)
  end
  if item == "null" and meta == 1 then
	table.insert(tableEmerald,amount)
  end
  if item == "null" and meta == 2 then
	table.insert(tableSapphire,amount)
  end
	--print(tostring( item ).." "..tostring(amount))
end

------------- Print Inventory Info -------------------------
mon.setCursorPos(1,1)
  IIdata = sensors.getSensorReadingAsDict(ctrl,QuarrySensorB,quarryChest,inventoryInfo)
  printDict(IIdata)
mon.setCursorPos(1,5)
  print("-----Quarry Chest Contents-----")

------------- Print Quarry Info / On/Off Status ---------------
--To be worked out, (--QuarrySensorA + Quarry + QuarryInfo
--(Info Needed:inProcess(Active):True(Yes)/False(No), HeadPosX:###(X:###), HeadPos:###(Y:###), HeadPosZ:###(Z:###)
--(Info Not Needed: MAX_ENERGY, Speed)


------------- Print Inventory Content Left side ---------------------
mon.setCursorPos(1,6)
  print("ORES:")
	write(" Iron:	 ")
	data = tableIronOre
	  print(sum(data))
	write(" Gold:	 ")
	data = tableGoldOre
	  print(sum(data))
	write(" Copper:   ")
	data = tableCopperOre
	  print(sum(data))
	write(" Tin:	  ")
	data = tableTinOre
	  print(sum(data))
	write(" Silver:   ")
	data = tableSilverOre
	  print(sum(data))
	write(" Cinnabar: ")
	data = tableCinnabarOre
	  print(sum(data))
	write(" Tungston: ")
	data = tableTungstonOre
	  print(sum(data))
  print("CRYSTALS:")
	write(" Vis:	  ")
	data = tableVisC
	  print(sum(data))
	write(" Vaporous: ")
	data = tableVapC
	  print(sum(data))
	write(" Aquaous:  ")
	data = tableAquC
	  print(sum(data))
	write(" Earthen:  ")
	data = tableEarC
	  print(sum(data))
	write(" Firey:	")
	data = tableFirC
	  print(sum(data))
	write(" Tainted:  ")
	data = tableTaiC
	  print(sum(data))

------------- Print Inventory Content Right side --------------------
mon.setCursorPos(17,6)
  print("BLOCKS:")
mon.setCursorPos(17,7)
	write(" Dirt:		")
	data = tableDirt
	  print(sum(data))
mon.setCursorPos(17,8)
	write(" Cobblestone: ")
	data = tableCobblestone
	  print(sum(data))
mon.setCursorPos(17,9)
	write(" Obsidian:	")
	data = tableObsidian
	  print(sum(data))
mon.setCursorPos(17,10)
	write(" Marble:	  ")
	data = tableMarble
	  print(sum(data))
mon.setCursorPos(17,11)
  print("FUELS:")
mon.setCursorPos(17,12)
	write(" Coal:		")
	data = tableCoal
	  print(sum(data))
mon.setCursorPos(17,13)
	write(" Uranium:	 ")
	data = tableUraniumOre
	  print(sum(data))
mon.setCursorPos(17,14)
  print("DUSTS/POWDERS:")
mon.setCursorPos(17,15)
	write(" Redstone:	")
	data = tableRedstone
	  print(sum(data))
mon.setCursorPos(17,16)
	write(" Nikolite:	")
	data = tableNikolite
	  print(sum(data))
mon.setCursorPos(17,17)
	write(" Lapis:	   ")
	data = tableLapis
	  print(sum(data))
mon.setCursorPos(17,18)
  print("GEMS:")
mon.setCursorPos(17,19)
	write(" Diamonds:	")
	data = tableDiamond
	  print(sum(data))
mon.setCursorPos(17,20)
	write(" Rubies:	  ")
	data = tableRuby
	  print(sum(data))
mon.setCursorPos(17,21)
	write(" Emeralds:	")
	data = tableEmerald
	  print(sum(data))
mon.setCursorPos(17,22)
	write(" Sapphires:   ")
	data = tableSapphire
	  print(sum(data))

sleep(1)
end

Cloudy #23
Posted 20 November 2012 - 09:06 AM
When you exit the chunk stops and therefor PC in game shutsdown. Name the program startup within the computer and all you have to open it. I'm not sure there is any other way

In the most recent version of CC Computers do start up on world load if they were off before.
tedraic #24
Posted 21 November 2012 - 03:51 AM
Hey all, Any help with this one or do I need to make a new thread for this one specifically?
Lyqyd #25
Posted 21 November 2012 - 04:30 AM
Try using string.match to pull the various values out. And don't start a new topic for a question on the same piece of code.
tedraic #26
Posted 21 November 2012 - 06:58 AM
Thanks Lyqyd, I will try that. and also thanks for the info about new or old thread on the same program code. I just was not sure if, Considering it was a different question if I would need to do a new thread.. :(/>/> .. Thanks again.
tedraic #27
Posted 22 November 2012 - 04:43 PM
Try using string.match to pull the various values out. And don't start a new topic for a question on the same piece of code.

ok, I have been messing around with this code and the suggestion made by Lyqyd in the quote above for the past couple of days now and I just can not seem to get it to work. I have gone as far as to grab a LUA Editor in hope that would help me to figure out what I am doing wrong but as of yet, I still have no clue what I am doing wrong, nor do I have a clue as to how to get the code to work. ;)/>/>

The full code:

Spoiler


------------- Program Information ------------------------
-- Auto Running on Chunk / Game Load				    --
-- Auto updating Information						    --
-- Info printed to 2*2 monitor						  --
-- Info currently included:							 --
-- Quarry Resource Collection Point Info			    --
-- Resource Collection Point contents Info			  --
-- Info currently working on:						   --
-- Quarry Active / Not Active status,				   --
-- Quarry Head Position X, Y, Z Coords.				 --
--													  --
-- Program written by: Tedraic						  --
-- Current contributors; computercraft.info			 --
-- ComputerCraft | Programmable Computers for Minecraft --
-- | ComputerCraft | Ask a Pro: Orwell				  --
----------------------------------------------------------

------------- Load API for sensors ------------
os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")

------------- Dictionary Printer --------------
function printDict(data)
  for i,v in pairs(data) do
    print(tostring(i).." - "..tostring(v))
  end
end
function printDict(qadata)
  for qai,qav in pairs(qadata) do
    print(tostring(qai).." - "..tostring(qav))
  end
end

----------------Table Sum Function-------------------------------
function sum(data)
  local sum = 0
    for k,v in pairs(data) do
	  sum = sum + v
    end
  return sum
end

------------- TheCode -------------------------
------------- Specify Monitor Position -------------------------
mon = peripheral.wrap('top')

------------- Get Controller side -------------------------
ctrl = sensors.getController()

------------- Specify the Sensor -------------------------
data = sensors.getSensors(ctrl)
  QuarrySensorA = data[2]
  QuarrySensorB = data[1]

------------- Specify the Probe(s) -------------------------
qadata = sensors.getProbes(ctrl,QuarrySensorA)
  Quarry = qadata[5]
data = sensors.getProbes(ctrl,QuarrySensorB)
  inventoryInfo = data[2]
  inventoryContent = data[3]

------------- Specify Sensor Target -------------------------
qadata = sensors.getAvailableTargetsforProbe(ctrl,QuarrySensorA,Quarry)
  QuarryInfo = qadata[4]
data = sensors.getAvailableTargetsforProbe(ctrl,QuarrySensorB,inventoryInfo)
  QuarryChest = data[4]
data = sensors.getAvailableTargetsforProbe(ctrl,QuarrySensorB,inventoryContent)
  QuarryChest = data[3]

------------- Redirect Terminal to monitor -------------------------
term.redirect(mon)
mon.setTextScale(0.5)
mon.clear()

------------- Pattern &amp; table Declarations -------------------------
local pattern = "^(%d+)%*(%a+%.?%a+)@(%d+)"
local qapattern = "(?%a+)-_-/>/>?%a+)"

    while true do
---- Ores ----
	  local tableIronOre = {}
	  local tableGoldOre = {}
	  local tableCopperOre = {}
	  local tableTinOre = {}
	  local tableSilverOre = {}
	  local tableCinnabarOre = {}
	  local tableTungstonOre = {}
---- Crystals ----
	  local tableVisC = {}
	  local tableVapC = {}
	  local tableAquC = {}
	  local tableEarC = {}
	  local tableFirC = {}
	  local tableTaiC = {}
---- Blocks ----
	  local tableDirt = {}
	  local tableCobblestone = {}
	  local tableObsidian = {}
	  local tableMarble = {}
---- Fuels ----
	  local tableCoal = {}
	  local tableUraniumOre = {}
---- Dusts &amp; Powders ----
	  local tableRedstone = {}
	  local tableNikolite = {}
	  local tableLapis = {}
---- Gems ----
	  local tableDiamond = {}
	  local tableRuby = {}
	  local tableEmerald = {}
	  local tableSapphire = {}


------------- Table Information Insertion -------------------------
ICdata = sensors.getSensorReadingAsDict(ctrl,QuarrySensorB,QuarryChest,inventoryContent)

for i = 1, #ICdata do
  local amount, item, meta = string.match( ICdata[i], pattern )
  meta = tonumber(meta)

---- Ores ----
  if item == "tile.oreIron" and meta == 0 then
    table.insert(tableIronOre,amount)
  end
  if item == "tile.oreGold" and meta == 0 then
    table.insert(tableGoldOre,amount)
  end
  if item == "tile.blockOreCopper" and meta == 0 then
    table.insert(tableCopperOre,amount)
  end
  if item == "tile.blockOreTin" and meta == 0 then
    table.insert(tableTinOre,amount)
  end
  if item == "tile.rpores" and meta == 3 then
    table.insert(tableSilverOre,amount)
  end
  if item == "tile.tcbcinnabarore" and meta == 0 then
    table.insert(tableCinnabarOre,amount)
  end
  if item == "item.rpores" and meta == 6 then
    table.insert(tableTungstoneOre,amount)
  end
---- Crystals ----
  if item == "item.tcicrystals" and meta == 0 then
    table.insert(tableVisC,amount)
  end
  if item == "item.tcicrystals" and meta == 1 then
    table.insert(tableVapC,amount)
  end
  if item == "item.tcicrystals" and meta == 2 then
    table.insert(tableAquC,amount)
  end
  if item == "item.tcicrystals" and meta == 3 then
    table.insert(tableEarC,amount)
  end
  if item == "item.tcicrystals" and meta == 4 then
    table.insert(tableFirC,amount)
  end
  if item == "item.tcicrystals" and meta == 5 then
    table.insert(tableTaiC,amount)
  end
---- Blocks ----
  if item == "tile.dirt" and meta == 0 then
    table.insert(tableDirt,amount)
  end
  if item == "tile.stonebrick" and meta == 0 then
    table.insert(tableCobblestone,amount)
  end
  if item == "tile.obsidian" and meta == 0 then
    table.insert(tableObsidian,amount)
  end
  if item == "tile.rpstone" and meta == 0 then
    table.insert(tableMarble,amount)
  end
---- Fuels ----
  if item == "item.coal" and meta == 0 then
    table.insert(tableCoal,amount)
  end
  if item == "item.itemOreUran" and meta == 0 then
    table.insert(tableUraniumOre,amount)
  end
---- Dusts &amp; Powders ----
  if item == "item.redstone" and meta == 0 then
    table.insert(tableRedstone,amount)
  end
  if item == "null" and meta == 6 then
    table.insert(tableNikolite,amount)
  end
  if item == "item.dyepowder" and meta == 4 then
    table.insert(tableLapis,amount)
  end
---- Gems ----
  if item == "item.emerald" and meta == 0 then
    table.insert(tableDiamond,amount)
  end
  if item == "null" and meta == 0 then
    table.insert(tableRuby,amount)
  end
  if item == "null" and meta == 1 then
    table.insert(tableEmerald,amount)
  end
  if item == "null" and meta == 2 then
    table.insert(tableSapphire,amount)
  end


    --print(tostring( item ).." "..tostring(amount))
end

------------- Print Inventory Info -------------------------
mon.setCursorPos(1,1)
mon.clear()
  IIdata = sensors.getSensorReadingAsDict(ctrl,QuarrySensorB,QuarryChest,inventoryInfo)
  printDict(IIdata)
mon.setCursorPos(1,5)
  print("-----Quarry Chest Contents-----")

------------- Print Quarry Info / On/Off Status ---------------
--To be worked out, (--QuarrySensorA + Quarry + QuarryInfo
--(Info Needed:inProcess(Active):True(Yes)/False(No), HeadPosX:###(X:###), HeadPos:###(Y:###), HeadPosZ:###(Z:###)
--(Info Not Needed: MAX_ENERGY, Speed)

--    local tableActive = {}
--    local tableHPosX = {}
--    local tableHPosY = {}
--    local tableHPosZ = {}

--QAdata = sensors.getSensorReadingAsDict(ctrl,QuarrySensorA,Quarry,QuarryInfo)

--  local qaActive, qaYesNo = string.match( QAdata )

--  if qaActive == "inProcess" and qaYesNo == "true" then
--    table.insert(tableActive)
--	  mon.setCursorPos(17,1)
--	    write(" Active:	 ")
--		  data = tableActive
--		    print(data)
--  else if qaActive == "inProcess" and qaYesNo == "false" then
--    table.insert(tableActive)
--	  mon.setCursorPos(17,1)
--	    write(" Active:	 ")
--		  data = tableActive
--		    print(data)

--speed:0.0
--headPosX:000.0
--headPosY:000.0
--headPosZ:000.0
--MAX_ENERGY:0000
--inProcess:false / true

------------- Print Inventory Content Left side ---------------------
mon.setCursorPos(1,6)
  print("ORES:")
    write(" Iron:	 ")
    data = tableIronOre
	  print(sum(data))
    write(" Gold:	 ")
    data = tableGoldOre
	  print(sum(data))
    write(" Copper:   ")
    data = tableCopperOre
	  print(sum(data))
    write(" Tin:	  ")
    data = tableTinOre
	  print(sum(data))
    write(" Silver:   ")
    data = tableSilverOre
	  print(sum(data))
    write(" Cinnabar: ")
    data = tableCinnabarOre
	  print(sum(data))
    write(" Tungston: ")
    data = tableTungstonOre
	  print(sum(data))
  print("CRYSTALS:")
    write(" Vis:	  ")
    data = tableVisC
	  print(sum(data))
    write(" Vaporous: ")
    data = tableVapC
	  print(sum(data))
    write(" Aquaous:  ")
    data = tableAquC
	  print(sum(data))
    write(" Earthen:  ")
    data = tableEarC
	  print(sum(data))
    write(" Firey:    ")
    data = tableFirC
	  print(sum(data))
    write(" Tainted:  ")
    data = tableTaiC
	  print(sum(data))

------------- Print Inventory Content Right side --------------------
mon.setCursorPos(17,6)
  print("BLOCKS:")
mon.setCursorPos(17,7)
    write(" Dirt:	    ")
    data = tableDirt
	  print(sum(data))
mon.setCursorPos(17,8)
    write(" Cobblestone: ")
    data = tableCobblestone
	  print(sum(data))
mon.setCursorPos(17,9)
    write(" Obsidian:    ")
    data = tableObsidian
	  print(sum(data))
mon.setCursorPos(17,10)
    write(" Marble:	  ")
    data = tableMarble
	  print(sum(data))
mon.setCursorPos(17,11)
  print("FUELS:")
mon.setCursorPos(17,12)
    write(" Coal:	    ")
    data = tableCoal
	  print(sum(data))
mon.setCursorPos(17,13)
    write(" Uranium:	 ")
    data = tableUraniumOre
	  print(sum(data))
mon.setCursorPos(17,14)
  print("DUSTS/POWDERS:")
mon.setCursorPos(17,15)
    write(" Redstone:    ")
    data = tableRedstone
	  print(sum(data))
mon.setCursorPos(17,16)
    write(" Nikolite:    ")
    data = tableNikolite
	  print(sum(data))
mon.setCursorPos(17,17)
    write(" Lapis:	   ")
    data = tableLapis
	  print(sum(data))
mon.setCursorPos(17,18)
  print("GEMS:")
mon.setCursorPos(17,19)
    write(" Diamonds:    ")
    data = tableDiamond
	  print(sum(data))
mon.setCursorPos(17,20)
    write(" Rubies:	  ")
    data = tableRuby
	  print(sum(data))
mon.setCursorPos(17,21)
    write(" Emeralds:    ")
    data = tableEmerald
	  print(sum(data))
mon.setCursorPos(17,22)
    write(" Sapphires:   ")
    data = tableSapphire
	  print(sum(data))

--------------------------------------------------------------------------------

---- Quarry Info Table Decleration ----
	 local tableQAActive = {}
	 local tableQAHPosX = {}
	 local tableQAHPosY = {}
	 local tableQAHPosZ = {}

QAdata = sensors.getSensorReadingAsDict(ctrl,QuarrySensorA,Quarry,QuarryInfo)

for qai = 1, #QAdata do
  local qaActive, qaYesNo = string.match( QAdata[qai], qapattern )


---- Quarry Info ----
  if qaActive == "inProcess" and qaYesNo == "true" then
    table.insert(tableQAActive,qaYesNo)
mon.setCursorPos(17,1)
    write(" Active:	 ")
    QAdata = tableQAActive
	  print(QAdata)
  end
  if qaActive == "inProcess" and qaYesNo == "false" then
    table.insert(tableQAActive,qaYesNo)
  end

	  print(tostring( qaActive ).." "..tostring(qaYesNo))

mon.setCursorPos(17,1)
    write(" Active:	 ")
    QAdata = tableQAActive
	  print(QAdata)
  end

sleep(1)
end
 

The code above does work mind you, At least in part.. It does give me the Quarry Chest Information and it does give me the Quarry Chest Contents Information like I want with the exception of, it does not repeat. It runs one time then stops and gives me a prompt. What it does not do at all is give me the specific info that I am looking for which is: If the Quarry is Active or no, ie., "inProcess:true/false". I can not seem to pull that specific information from the readings no matter what I try.. What am I doing wrong?
Anyone have any ideas, suggestions? I would appreciate anything that you can offer. I would love to get this piece of code finished up so that I can move on to the next Building / Sensor combination.

Thanks in advance for any help that you can offer.
Lyqyd #28
Posted 22 November 2012 - 05:33 PM
I can help you construct the pattern to use with string.match(). I see that you don't have a pattern specified, so those return values aren't going to give you any useful information without it. Give us an example string that the quarry information returns (an actual one, copy/pasted in) and I or someone else can come up with a pattern to get whichever data points you need to use out of it.
tedraic #29
Posted 22 November 2012 - 06:03 PM
This is all of the information that the Quarry information returns just as it returns it and in the order that it is printed out.

MAX_ENERGY:7000 —- Have only ever seen 7000 here
inProcess:false —- can be either false, (Not Actively mining), or true, (Actively mining)
headPosY:4
headPosZ:283.95657
speed:0.0 —- Have never seen anything other then 0.0 here.
headPosZ:108.681145

The ONLY information that I need to get out of all of this is the inProcess information and the headPosY, X, Z Information. I really dont need anything else but, I can not figure out how to get the dang thing to pull and print just the info that I want in the format that I want it printed..

I am wanting:
Actual Info to be printed as:
inProcess Acitve: Yes(true), or No(false)
headPosY: Y: ##.##
headPosX: X:##.##
headPosZ: Z:##.##

.. This is really getting aggravating but, I am not one to just give up so.. Yeah… LMAO..

And thanks Lyqyd
Lyqyd #30
Posted 22 November 2012 - 06:24 PM
So you're saying that this line:


sensors.getSensorReadingAsDict(ctrl,QuarrySensorA,Quarry,QuarryInfo)

returns the string:

MAX_ENERGY:7000
inProcess:false
headPosY:4
headPosZ:283.95657
speed:0.0
headPosZ:108.681145

Or does it return several different strings (to several different return values), first with:

MAX_ENERGY:7000

and the next return value being:

inProcess:false

etc.?
tedraic #31
Posted 22 November 2012 - 07:36 PM
ok, In game.. from my code I can not seem to get it to print any kind of information out for the line: sensors.getSensorReadingAsDict(ctrl,QuarrySensorA,Quarry,QuarryInfo)

However, when I run ccSensors/console and select the exact same controller (ctrl), Sensor (QuarrySensorA), Target (Quarry), and Probe (QuarryInfo) I get the information returned as:


MAX_ENERGY:7000
inProcess:false
headPosY:4
headPosZ:283.95657
speed:0.0
headPosZ:108.681145

That is one of the problems with getting the code to work in game for me.. It is outputting Nothing but the rest of the code works… Now this is the really odd thing.. The rest of the code by itself runs perfectly.. and even auto updates.. (loops).. But, when I put the new code in, It stops working.. as in, It will print the information out for the Chest Info, and the Chest Contents like I want it to but, it does not print anything out for the Quarry Info nor does it auto update.. (loop).. It will print the Chest Info and Chest contents then stop.. giving me a prompt … Honestly.. I am really having problems getting the results that I am looking for but am sure that there is a way to do it….

It is a shame that it does not use Basic, or QBasic.. I can make a computer stand up and dance with either of them but, just do not seem to be getting LUA for some reason…
tedraic #32
Posted 27 November 2012 - 01:54 PM
Can anyone help me with this issue? I have seen a few videos on YouTube that is able to pull the specific information from the Sensors so, I know that it is possible.. I just have yet been able to do it my self.. I have now been at this for over a week and it is starting to drive me nuts..