Jump to content




Lighthouse Sequence


  • You cannot reply to this topic
13 replies to this topic

#1 darvic

  • New Members
  • 7 posts

Posted 14 October 2012 - 01: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.

#2 JoshhT

  • New Members
  • 64 posts
  • LocationAustralia

Posted 14 October 2012 - 02: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


#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 14 October 2012 - 02: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

#4 darvic

  • New Members
  • 7 posts

Posted 14 October 2012 - 02: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.

#5 JoshhT

  • New Members
  • 64 posts
  • LocationAustralia

Posted 14 October 2012 - 02:17 AM

If you need any more help, feel free to ask.

#6 darvic

  • New Members
  • 7 posts

Posted 14 October 2012 - 02: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.

#7 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 14 October 2012 - 03:15 AM

View Postdarvic, on 14 October 2012 - 02:34 AM, said:

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


#8 darvic

  • New Members
  • 7 posts

Posted 14 October 2012 - 03: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

#9 civilwargeeky

  • Members
  • 393 posts

Posted 14 October 2012 - 04:25 AM

just curious, is the program actually called lighthouse, and is it on the root (as in not in a folder)?

#10 darvic

  • New Members
  • 7 posts

Posted 14 October 2012 - 04:34 AM

Yes, all lowercase, and it is in the root directory.

#11 JoshhT

  • New Members
  • 64 posts
  • LocationAustralia

Posted 14 October 2012 - 05: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?

#12 darvic

  • New Members
  • 7 posts

Posted 14 October 2012 - 05:19 AM

That was my startup code...

It seems to work on a full server reset though, just not if I reboot

#13 JoshhT

  • New Members
  • 64 posts
  • LocationAustralia

Posted 14 October 2012 - 05:33 AM

I'm a bit confused here. What doesn't work, the reboot, or the program after you reboot?

#14 darvic

  • New Members
  • 7 posts

Posted 14 October 2012 - 03: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users