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

Sorting room item counter

Started by Lukeblade123, 09 September 2012 - 09:11 PM
Lukeblade123 #1
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()
Mmmmmmmm #2
Posted 09 September 2012 - 11:41 PM
count = count + 1
You never initialised the variable count, but rather "iCount".
Lukeblade123 #3
Posted 10 September 2012 - 12:31 AM
Thank you that fixed the problem