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

Actively Aware Program

Started by Bigjakk, 26 December 2012 - 01:50 PM
Bigjakk #1
Posted 26 December 2012 - 02:50 PM
Hello I have never posted on forums as these so I apologize in advance if anything is wrong on how I post it. I currently play Tekkit, and I started using Computer Craft to simply control all the lights in my compound from one terminal. I would like however to control different items using one terminal, but there is a certain way I wish to do this. I would like to use bundled cable behind walls linked to different buttons to do different things. The thing I need is a way to make a program to actively look for a redstone input from a certain color on the bundled cable. Then depending on which input it will execute a certain program. Afterwards returning to actively looking for redstone input. Is something like this possible with lua? I do more than someone just starting out on programming, im just a little stuck on this one.
NDFJay #2
Posted 26 December 2012 - 03:34 PM
to actively check for a bundled color input you need it in a forever loop - sample code as a reference



while true do
sleep(.1)
if rs.testBundledInput(side, color) then
 --do something
elseif rs.testBundledInput(side, color 2) then
--do something else
end
end

Bigjakk #3
Posted 26 December 2012 - 03:45 PM
The loop wasn't what was the problem for me, it was then using that program to execute a separate program then going back to the first program in a loop. If that makes sense. I wish to keep the programs separate so I can use them on disks, so I may use them for future things not all compiled into one program.
Edited on 26 December 2012 - 02:50 PM
BustedEarLobes #4
Posted 26 December 2012 - 03:53 PM
Yup, that's possible. Using shell.run("<program Dir>"), you can run the program, and when you exit that program it will return to the program in which you called shell.run()

Ex:

Program [p1]:
shell.run("p2")

print("Hello!")


Program[p2]:
print("Goodbye!")



Will output:
Goodbye!
Hello!
Bigjakk #5
Posted 26 December 2012 - 03:58 PM
Ah thank you very much.