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

Running a program indefinetely

Started by The, 30 April 2012 - 09:37 PM
The #1
Posted 30 April 2012 - 11:37 PM
I wish to create a program that emits a redstone signal for a certain amount of time, stops for a certain amount of time, and then repeats this pattern until I turn off the computer. This will be used to control a builcraft pump. I do not know what one would call this type of program in coding nomenclature, maybe a loop?
Here is what I have so far, thanks in advance for your help!

print("Turning on the pump.")
clear
rs.setOutput("right", true)
sleep(10)
rs.setOutput("right", false)
I thought using the sleep command would be a reasonable way to keep signal going until I want signal to cease. This instead yields an error about '=' being expected on line 3. That is the syntax for the sleep command i have seen in other's programs.
cant_delete_account #2
Posted 01 May 2012 - 12:17 AM
It's:

shell.run("clear")
or

term.clear()
term.setCursorPos(1,1)
not

clear
Zalerinian #3
Posted 01 May 2012 - 12:40 AM
Now i'm not really an expert on this, so i can't guarantee it'll work, but try this:


while true do
term.clear()
term.setCursorPos(1,1)
print("Turning on the pump.")
rs.setOutput("right", true)
sleep(10)
print("Disabling pump")
rs.setOutput("right", false)
sleep(10)
end


To make it so that the program starts even after a sever restarts or you quit the game, attach the computer to a monitor and input the following code:

(Make sure to name the file "startup" without the quotes)

shell.run("pump")

Do note that you need to replace "pump" with whatever you are naming the program.





EDIT: Ok, so i fixed it! I put the fixed code above^^



(ORIGINAL (Failied) CODE)


function pump()
print("Turning on the pump.")
term.clear()
term.setCursorPos(1,1)
rs.setOutput("right", true)
sleep(10)
rs.setOutput("right", false)
pump()
end
Zalerinian #4
Posted 01 May 2012 - 01:15 AM

while true do
term.clear()
term.setCursorPos(1,1)
print("Turning on the pump.")
rs.setOutput("right", true)
sleep(10)
print("Disabling pump")
rs.setOutput("right", false)
sleep(10)
end

One little note, terminating the program with the pipe on will leave it active.