Posted 26 September 2012 - 09:11 PM
I have just begun tot start making a simple program with the help of tutorials and this forum. I have set up a ccSensor to show the content of two chests to a 4*8 monitor. Learnt a lot from codes that are available. The code is below:
The problem is that the information shown is not the format i want. This:
1 - 35Xtile.Dirt@0
2 - 64Xitem.IngotGold@0
….
11 - 64Xtile.Log@2
12 - 34*tile.Rail@0
must go to:
35 Dirt
64 IngotGold
…
64 Log
34 Rail
I know there probably is a solution with 'string.match' but i think that does not go with 'print.Dict'.
Help is very much appreciated.
os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")
--------------
m1=peripheral.wrap("left")
----------------------------
function printDict(data)
for i,v in pairs(data) do
print(tostring(i).." - "..tostring(v))
end
end
--------------------------
while true do
------------------------
ctrl = sensors.getController()
data = sensors.getSensors(ctrl)
BB = data[1]
------------
data = sensors.getSensorInfo(ctrl,BB)
sensors.setSensorRange(ctrl,BB,"8")
-----------
data = sensors.getProbes(ctrl,BB)
InventoryContent = data [3]
-------------
data = sensors.getAvailableTargetsforProbe(ctrl,BB,InventoryContent)
--------------
BlueChest= data[1]
OrangeChest = data[2]
Redchest= data[3]
YellowChest= data[4]
--monitor left
term.redirect(m1)
term.clear()
m1.setCursorPos (1, 1)
m1.setTextScale(0.5)
--left up
data = sensors.getSensorReadingAsDict(ctrl,BB,BlueChest,InventoryContent)
printDict(data)
--left down
m1.setCursorPos (1, 25)
print"----------------------------------"
print" "
data = sensors.getSensorReadingAsDict(ctrl,BB,OrangeChest,InventoryContent)
printDict(data)
-------------------------------
sleep(.1)
end
-------------------------------
The problem is that the information shown is not the format i want. This:
1 - 35Xtile.Dirt@0
2 - 64Xitem.IngotGold@0
….
11 - 64Xtile.Log@2
12 - 34*tile.Rail@0
must go to:
35 Dirt
64 IngotGold
…
64 Log
34 Rail
I know there probably is a solution with 'string.match' but i think that does not go with 'print.Dict'.
Help is very much appreciated.