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

Lighthouse Sequence

Started by darvic, 14 October 2012 - 12:52 AM
darvic #1
Posted 14 October 2012 - 02:52 AM
I had this working, and it sort of works if I get rid of the Else part. It runs a lighthouse off two bundled cables. I have tried to set it to turn off during the day. I keep getting errors like 'end' expected and 'eof' expected. I have tried several rearrangements, but must be missing one.


function BundleRight()
rs.setBundledOutput("right", colors.combine( 0, alpha))
sleep(1.5)
alpha = alpha*2
end
function BundleBack()
rs.setBundledBack("back" , colors.combine(0, alpha))
sleep(1.5)
alpha = alpha*2
end
while rs.getInput("top)~=true do
alpha = 1
rs.setBundledOutput("right", colors.combine(0, 0))
rs.setBundledOutput("back", colors.combine(0, 0))
for count=1,9 do
  BundleRight()
end
rs.setBundledOutput("right", colors.combine(0, 0))
alpha = 1
for count=1,9 do
  BundleBack()
end
else
rs.setBundledOutput("right", colors.combine(0, 0))
rs.setBundledOutput("back", colors.combine(0, 0))
sleep(30)
end

Any help is appreciated.
JoshhT #2
Posted 14 October 2012 - 03:04 AM
Currently, this is your code, but I've taken all the shit from the middle.

while rs.getInput("top") ~= true do -- Your code says ("top), you should close that string otherwise it will always throw an error there.

else -- As far as I'm aware, you can't actually "else" a while loop.

end
remiX #3
Posted 14 October 2012 - 03:05 AM
while rs.getInput("top)~=true do
to
while rs.getInput("top") ~= true do
– You forgot the last "

The else on the 5 last line, what if does it correspond to?

EDIT: Ninja'd
darvic #4
Posted 14 October 2012 - 03:14 AM
That would be the issue, I was trying to use an else with while. Thanks for the help.

*edit* Still working out how to get the if statement to do what I want it to do.
JoshhT #5
Posted 14 October 2012 - 03:17 AM
If you need any more help, feel free to ask.
darvic #6
Posted 14 October 2012 - 03:34 AM
Ok. Yes.

This is the code to run the lights around the lighthouse.

alpha = 1
rs.setBundledOutput("right", colors.combine(0, 0))
rs.setBundledOutput("back", colors.combine(0, 0))
for count=1,9 do
  BundleRight()
end
rs.setBundledOutput("right", colors.combine(0, 0))
alpha = 1
for count=1,9 do
  BundleBack()
end

That works fine. I am not sure where to put the If statements around it though. I want to see if there is redstone signal from the Light Sensor is transmitting, if so I don't want to run the code. And I want it to check every 30 Seconds on that. My ideal plan was to run through the code for the lighthouse and check the sensor after a full rotation.
remiX #7
Posted 14 October 2012 - 04:15 AM
Ok. Yes.

This is the code to run the lights around the lighthouse.

alpha = 1
rs.setBundledOutput("right", colors.combine(0, 0))
rs.setBundledOutput("back", colors.combine(0, 0))
for count=1,9 do
  BundleRight()
end
rs.setBundledOutput("right", colors.combine(0, 0))
alpha = 1
for count=1,9 do
  BundleBack()
end

That works fine. I am not sure where to put the If statements around it though. I want to see if there is redstone signal from the Light Sensor is transmitting, if so I don't want to run the code. And I want it to check every 30 Seconds on that. My ideal plan was to run through the code for the lighthouse and check the sensor after a full rotation.

All you have to do is use a while true do loop with an if function to check for redstone signal.


local sLightSensor = "back" -- which ever side the redstone signal from lightsensor is coming from.

while true do
    if rs.getInput(sLightSensor) then
        print("Signal found")
        -- code if signal is found
    else
        alpha = 1
        rs.setBundledOutput("right", colors.combine(0, 0))
        rs.setBundledOutput("back", colors.combine(0, 0))
        for count=1,9 do
            BundleRight()
        end
        rs.setBundledOutput("right", colors.combine(0, 0))
        alpha = 1
        for count=1,9 do
            BundleBack()
        end
        print("Signal not found")
    end
    sleep(30)
end
darvic #8
Posted 14 October 2012 - 04:53 AM
Thank you, got it working by changing much of it to functions so it was easier to fix code. My issue now is startup.

I have this startup file on both the computer and a connected floppy drive

shell.run("lighthouse")

It returns the error

reboot:3: attempt to call nill
civilwargeeky #9
Posted 14 October 2012 - 05:25 AM
just curious, is the program actually called lighthouse, and is it on the root (as in not in a folder)?
darvic #10
Posted 14 October 2012 - 05:34 AM
Yes, all lowercase, and it is in the root directory.
JoshhT #11
Posted 14 October 2012 - 06:12 AM
Try,

os.run({}, "/lighthouse")

I'm not really familiar with shell.run() so I can't tell you the difference.

Also, could you please post the startup code?
darvic #12
Posted 14 October 2012 - 06:19 AM
That was my startup code…

It seems to work on a full server reset though, just not if I reboot
JoshhT #13
Posted 14 October 2012 - 06:33 AM
I'm a bit confused here. What doesn't work, the reboot, or the program after you reboot?
darvic #14
Posted 14 October 2012 - 04:42 PM
I just realized it is the reboot program that is failing. Not sure why.

Fails on the third line which is:

os.reboot()

with the error attempt to call nil

This is the default file in the rom directory, and no other files were made with the name reboot. But I don't actually need it to reboot as long as my startup file is working, which it is.

*edit* Ctrl-R works so I will just use that for testing.