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

redstone.setOutput loop only running once?

Started by chardo440, 05 December 2013 - 05:00 PM
chardo440 #1
Posted 05 December 2013 - 06:00 PM
So I'm trying to make a loop for my auto smelter but it only runs once then quits it's not actually looping?


print("How many ingots would you like to smelt?")
num = tonumber(io.read())
term.clear()
term.setCursorPos(1,1)
print("Ok, Smelting " ..(num).." ingots.")

for i=1, num do
rs.setOutput("top",true)
sleep(2)
rs.setOutput("top",false)
end

print("finished making your ingots")
print(" restarting…")
sleep(2)


it only does this once. so even if I type 500 it does the loop "once" then stops. Could anybody possibly tell me what I'm doing wrong?
Kingdaro #2
Posted 05 December 2013 - 06:03 PM
The issue is at the end of that loop, when you set the top output to false, it instantly restarts and sets it to true again. Your auto smelter doesn't have enough time to see that the input was turned off because it turned off and back on so quickly. Just put another sleep after the second setOutput:

for i=1, num do
rs.setOutput("top",true)
sleep(2)
rs.setOutput("top",false)
sleep(0.1)
end
Edited on 05 December 2013 - 05:03 PM
chardo440 #3
Posted 05 December 2013 - 06:12 PM
works now thanks man! I can't believe I missed that.