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

Please help to get my automatic solar array doors to work! :)

Started by Tom, 07 September 2012 - 11:12 PM
Tom #1
Posted 08 September 2012 - 01:12 AM
Hi im new to computercraft iv learned alot in the 2 days iv been using it but after these days of trawling tutorials and forums i still cant get my first real program to work i would greatly appreciate any help the pros's can offer.

What i am tying to accomplish is to have some redpower frame doors close over my solar arrays at night and open again during the day.

my day/night input is from a RP2 light sensor
i have wrote 2 simple programs to open and close the doors which both work when activated alone.

i have tryd 2 sets of code plz let me know which would/could work or if im totally off an example of how to do this would be nice

first code

loop = 1
while (loop == 1) do

input = rs.getInput ("top") – top is lightsensor true is day
if (input == "false") then
shell.run ("sdc") – doors close prog
loop = 2
else
shell.run ("sdo") – doors open prog
end
end

Second code

if rs.getInput ("top") == true then
shell.run ("sdo")
end

if rs.getinput ("top") == false then
shell.run ("sdc")
end

the second code works when i manually run it, so im thinking its my absolute noobishness when it comes to loops that is the problem
Lettuce #2
Posted 08 September 2012 - 01:30 AM
Yup. Noob. That's perfectly fine, we were all there once. Your first code is closest. I'm not very familiar with redstone in CC, but I know variables and loops, and that's where I see huge problems. I will pick at your program.

FIRST: The best infinite loop (what you seem to be trying to make) is:
while true do

SECOND: When you call variables do not enclose them in parenthesis.

if test = 3 then
print "Test was a success!"
end
is what you need.

THIRD: If sdo/sdc is a function, do not use shell.run. If it is not, make it one, it's much easier to troubleshoot. Since it's not an entirely different program with an entirely different purpose, set it as a function, as this program is used specifically to open the solar panels. Set that like so:

function test()
print "Test was a success!"
end
Be sure to end the function, it's kinda like a loop in that regard, Lua must know where it ends. (CC uses Lua, a versatile scripting language)
Call the test function by simply typing test().

Tell us how that goes when you make those changes, and post your whole code.
Preferably like this (no asterisks):
[*spoiler]
[*code]
– code goes here.
[*/code]
[*/spoiler]