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

I am trying to make a program to turn the lights on when it's day

Started by IEpicGamerz, 30 July 2015 - 08:10 PM
IEpicGamerz #1
Posted 30 July 2015 - 10:10 PM
Hi, i am new to coding with computer craft and i am currently trying to make a program to out a bundled cable output when it gets a different bundled cable input and i am wondering if anyone could help?

Here is my code

http://pastebin.com/P0M8NFb0

The error i am getting currently is

"bios:367: [string "nighttime"]:3: 'then' expected
RootSlayers #2
Posted 30 July 2015 - 10:48 PM
Hello !

At the line 3 it's a test, so you need the "==" instead of "=" ("==" is an operator and "=" is to define the variables).
And you need to close the "while true do" and the "if" with two "end".
HPWebcamAble #3
Posted 30 July 2015 - 11:41 PM
ComputerCraft is great for a lot of things, but you could achieve this with just a vanilla day light sensor


If you'd still like to try it this way, there are a few things you need to fix.

RootSlayer's suggestions were good, but there's one more thing.

Here is your code, fixed, with explanations:

while true do

  if rs.testBundledInput("bottom", colors.red) == false then --# This way, it checks every time the loop runs
    print("Night Time")
    rs.setBundledOutput("bottom",colors.yellow) --# See below for expalaination
  else
    print "Nope"
  end --# Closes the if-statement

  sleep(4) --# Pauses on this line for 4 seconds - Otherwise it would run the loop every game tick, 20 times a second!

end --# Closes the while-statement

rs.setBundledOutput() takes two arguments: side,output

The side is the side of the computer (its case sensitive):
"top", "bottom", "left", "right", "front", "back"

The output determines the colors that will be on:
Remember, 1 is white, 2 is orange, 4 is magenta, and so on.
So 'colors.white' is ONLY white (So it sets it to 1)
If you want white AND orange, its 3 (white + orange = 1+2 = 3)

If you want it to be just yellow, you do 'colors.yellow'.
You don't need 'true' (like rs.setOutput() does)