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

[solved]my item counter prog break when it reach 60...

Started by virtualayu, 08 April 2012 - 05:37 PM
virtualayu #1
Posted 08 April 2012 - 07:37 PM
i made a little prog who count items when they pass in a item dtector (redpower). this work pretty well until he reach 60…
60 for all counting, if i just give dirt it go to 60 if i give dirt coal and cobble it go like 20 of each one …
and i really don't know why….

my code : http://pastebin.com/22fJssey

i try with all thing about the reading or writing the fille in comment and it do the same so the problem is'nt from that…

any ideas???
Luanub #2
Posted 08 April 2012 - 11:27 PM
Not sure if its part of your problem or not but you probably should break the while loop in the function loop prior to going on to the counting function


function loop()
while true do
event = os.pullEvent()
  if event == "redstone" then
  counting()
   break -- add this
  end
end
end

You can shorten this a little too..

function loop()
while true do
event = os.pullEvent("redstone")
  counting()
   break -- add this
end
end
virtualayu #3
Posted 09 April 2012 - 03:41 AM
i add the "break" but it do the same … and anyway i think if we call a function it will automaticly break the loop but i'm not sur… ^^

when the program stop it just write : 178 … i really don't know what it is… an error code?
virtualayu #4
Posted 09 April 2012 - 07:44 PM
nobody have an idea??? or a counter who already work for me (i will analize it, and maybe found an answer ^^)
Hawk777 #5
Posted 09 April 2012 - 10:12 PM
Your "counting" function is calling "loop" at the end. There's no reason for that, and it will build up a lot of stack frames which will never be freed (one per item passing the detectors). Just drop that call completely; when "counting" finishes running, you will return to "loop" and continue executing, which will spin around the "while" and wait for the next redstone event.
virtualayu #6
Posted 10 April 2012 - 01:03 AM
effectivelly ^^ i'm not very familliar with the "while true do" things ^^ i removed the calling of "loop()" and now it work perfectly ^^ Thanks a lot!!!

now i will add code for decrementing count when we take items in the chest…