Posted 21 April 2013 - 11:26 AM
This program should be displaying the amount of materials and their corresponding sizes, however it should only display each material once in the list. However the output is just one line repeated throughout the display "Oak Wood Planks: 8" which is just the material size in the first slot, it does not even count any other materials. Can someone hlap me ploise?
os.loadAPI("ocs/apis/sensor")
local sensor = sensor.wrap("left")
local monitor = peripheral.wrap("right")
local targets = sensor.getTargets()
while true do
local details = sensor.getTargetDetails("-1,0,0")
loopcounter = 0
slot = details.Slots
x=0
i=0
currentMaterials = 0
materials = {27} --defining arrays with 27 slots
quantity = {27}
while x < 27 do
materials[x] = "nul" --filling materials and quantity with nul and 0
quantity[x] = 0
x=x+1 --increment x to fill all array slots
end
x=0 --reset x
while x < 27 do
while i < 27 do --Loop to check the current slot with all the other materials
if details.Slots[x+1].Name == materials[i] then --If the current slot contains any previous material
quantity[i] = quantity[i] + slot[x+1].Size --Add that slot size to the i quantity
else
materials[currentMaterials] = slot[x+1].Name --Assign the name of the current slot to the current material name in the array
quantity[currentMaterials] = slot[x+1].Size --Assign the quantity --II--
currentMaterials = currentMaterials + 1 --Increment the amount of current materials
end
i = i+1
end
x = x + 1
end
x=0
while x<27 do
monitor.setCursorPos(1,x)
monitor.clearLine()
monitor.write(materials[x]..": "..quantity[x])
x=x+1
end
end