Posted 09 September 2012 - 11:11 PM
I am trying to make an item counter for my sorting room by having the items pass through seprate red power 2 item detectors and having the computer count the redstone pulses and display the item count on a monitor. This is partially my code i modified it to work with my setup. If someone could please tell me what I am doing wrong that would be great. (I am new to lua) Here is the error code i get:counter: 13 : attempt to perform arithmetic __add on nil and number
local iCount = 0
local hMonitor = peripheral.wrap("back")
-- Monitor is on the back of the computer
term.redirect(hMonitor) --redirect console output to monitor
while true do
event = os.pullEvent()
--if an redstone event is pulled and the input from
--the pressure plate (left) is TRUE, increase count
if event == "redstone" and rs.getInput("left") then
count = count + 1
term.clear()
print("Count: " .. count)
end
--if the input from the reset button (right) is TRUE,
--reset count
if event == "redstone" and rs.getInput("right") then
count = 0
term.clear()
print("Count reset")
end
end
--this doesn't get called because there is no abort
--condition, but term.restore() will reset the console
--output to the computer screen itself
term.clear()
term.restore()