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

[LUA] Counter not counting past 10!

Started by InfamousClyde, 02 June 2012 - 05:39 PM
InfamousClyde #1
Posted 02 June 2012 - 07:39 PM
In advance, sorry for the amateur level quality of the code. :)/>/>

To give an idea of the context for this code, what it does is sends pulses to a RedPower2 transposer which sends pork down a pipeline.
I'd just like to count the amount of pork flowing, though. I have the pork going through an "Item Detector" which sends out a pulse for each item that passes through it.
Only problem is, the counter program of mine doesn't iterate past 10! I'm racking my brain trying to figure it out!
Any help would be very much appreciated!


term.clear()

term.setCursorPos(1, 1)

textutils.slowPrint("Welcome to PorkSend")

print("")

textutils.slowPrint("	Would you like to receive pork?")

write("Enter (yes/no): ")

input = read()

if input == "no" then

os.shutdown()

elseif input == "yes" then

print("")

textutils.slowPrint("How much pork?")

write("Enter: ")

input2 = read()

input2 = tonumber(input2)

textutils.slowPrint("Sending...")

i = 0

while i < input2 do

rs.setOutput("back",true)

sleep(0.3)

rs.setOutput("back", false)

sleep(0.3)

i = i+1

end

end

x = 0

while x < input2 do

event = os.pullEvent()

if event == "redstone" and rs.getInput("right") then

term.clear()

term.setCursorPos(1, 1)

x = x + 1

print("Count: " .. x)

end



if x == input2 then
textutils.slowPrint("Sending complete.")

break

end

end

sleep(3)

os.shutdown()
Teraminer #2
Posted 02 June 2012 - 07:58 PM
You mean it can't send more than 10 pork?
InfamousClyde #3
Posted 02 June 2012 - 08:04 PM
Oh whoops, I think I should clarify.
It sends the pork absolutely fine, no problem.
I think the first half of the code is pretty bug-free. It sends any amount of pork, and that pork will arrive.

I'm having problem with the second half of the code, with the event handling and whatnot. It's supposed to be counting redstone pulses, but it can only count up to ten and no further!

For example, if I request my terminal for 20 Pork, the computer will send 20 pulses to the "sender of pork" so to speak. The computer then switches to counting mode to count the amount of pork as it comes in. The pork will come in, and each pork will emit a pulse as it travels through a detector.
The computer registers these pulses, but only 10 times. All 20 pieces of pork arrive, but the counter displays "10". Hope that helps!
D3matt #4
Posted 02 June 2012 - 10:38 PM
If you manually trigger the redstone pulses (IE with a button) will it keep counting past? I'm thinking it's probably something with your physical setup because I can see no reason why it shouldn't work by looking at the code.