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

Program Help

Started by Silent_Potato, 15 July 2012 - 06:12 AM
Silent_Potato #1
Posted 15 July 2012 - 08:12 AM
I just recently started making a ComputerCraft script on tekkit to shutdown my nuclear reactor via redstone current. My setup was to make a Thermal Monitor input a redstone signal and then output a signal through the back for "monitorsetheatvalue divided by 500 times 32". This is how long it takes evaporate all heat in reactor. Now, i have my reactor monitor set for 11000, so the time it would take after shutdown to completely cool it is 664 seconds (11 minutes). Now im making the program to do this. It will accept in redstone power then output it the first time, but won't do it afterwards. Due to the fact i was testing the script out on a creative world, I set the sleep to 10 seconds instead of 664 seconds. I know the problem must be related to "Loopin" but since ComputerCraft isn't bringing up errors, i can't figure out whats wrong or what i need to add. Here is my script i made.

function pass()
if redstone.getInput("front", true) then
redstone.setOutput("back", true)
sleep(10)
redstone.setOutput("back", false)
pass()
end
end
pass()


I've also tried variations of "Loops" such as "while true do" but they STILL only do it once and then quit.
Can someone please help? I'd be most grateful! :P/>/>
P.S. Don't say figure it out yourself. I've been screwing around with it for 4 hours now and can't figure it out.
Lyqyd #2
Posted 15 July 2012 - 08:39 AM
So, run this:


while true do
    print("Looping!")
    if redstone.getInput("front", true) then
	    redstone.setOutput("back", true)
	    sleep(1)
	    redstone.setOutput("back", false)
	    pass()
    else
	    sleep(0)
    end
end

Let me know how many times it says that it's looping.
Silent_Potato #3
Posted 15 July 2012 - 09:04 AM
It looped an infinite amount of times, but when i went to check machine, it still only ran my actual script once. Any ideas?
Edit: Afterwards, i looked at it and it brang up this: startup:6: attempt to call nil
Silent_Potato #4
Posted 15 July 2012 - 09:05 AM
by that, i mean that it wrote looping an infintite amount of times (or till i stopped it) but it DIDN'T loop the actual program.
LucasUK #5
Posted 15 July 2012 - 02:01 PM
You cant call pass() from within pass!, otherwise when u run pass(), it will run a pass(), which will also run a pass(), and so on until so many are running it will cash.



Ive edited your code (not tested) to hopefully make it work without calling itself, your function pass() will run instantly (but take 664 seconds to run if the reactor needs to be deactivated!), the while true will make it run your function every second.


function pass()
if redstone.getInput("front", true) then
redstone.setOutput("back", true)
sleep(664)
redstone.setOutput("back", false)
end
end

while true do
pass()
sleep(1)
end
Silent_Potato #6
Posted 15 July 2012 - 06:46 PM
Okay, so the script is FINALLY working, but with a minor flaw. Theres two ways for me to correct the flaw though. The flaw is is that as long as the input has power, it won't start the sleep(664) command, thus meaning it will have to wait till the output is done, but with the reactor im making (MK 3) it has a good chance of going to 11000 then proceeding to 12000 before the computer boots in. This means that it would take another 2 full minutes + 11 minutes to complete cooldown. Now, what i want is for the input to be taken in and registered once after the other redstone is triggered. Although i know this version is safer, it would be helpful to do make this work. =P
Any suggestions?

Oh and thanks lucas for your help! =P

Edit:Okay, just realized my setup has wrong sleep time for cooldown. I now set it to sleep(702)
Lyqyd #7
Posted 15 July 2012 - 08:52 PM
by that, i mean that it wrote looping an infintite amount of times (or till i stopped it) but it DIDN'T loop the actual program.

This is incorrect. If it printed that it was looping, it has to have made it all the way through the loop. What behavior made you think it wasn't looping?