Jump to content




Need help for a simple alarm system


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

#1 PixelMiner

  • Members
  • 7 posts

Posted 01 May 2013 - 09:55 AM

Title: Need help for a simple alarm system

Hello guys :)

First I need to say that I literaly started using ComputerCraft 2 days ago, so I'm a complete noob (applies to LUA as well) :)

On the subject.

I have multiple combustion engines constantly running, but for some reason (don't know if it's a bug or not) after a while the water stops flowing and eventually they just blow up, destroying all my work. After a while I figured that the only way to restore the water flow is by restarting the server. So to prevent my engines from from blowing my place, I started using redstone waterproof pipes. When there's a water in the pipe, it emits redstone signal that powers the engine. As soon as it empites, the engine stops. So far, so good. The thing is that I can't watch them all the time, so I need some sort of an alarm, that will "tell" me when an engine has stopped, so I can restart the server.

I did some googling, watched a crapload of tutorials and found a few codes, that if combined they'd do the job. But due to my "knowledge" in ComputerCraft, I couldn't make it work :/

Here's what I need:

Basically, It's a lamp, that starts flashing as soon as the computer stops recieving redstone signal from the pipe. Additionally, if for some reson the water flow starts again w/out restarting the server, the program goes back to "monitoring" state.

Posted Image


The code
Posted Image


And the error message I get
Posted Image


Thanks in advance and please excuse my crappy English

#2 BigSHinyToys

  • Members
  • 1,001 posts

Posted 01 May 2013 - 11:03 AM

Your pictures haven't worked correctly but this code should do it.

Spoiler


#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 01 May 2013 - 11:06 AM

Code picture is broken.

#4 PixelMiner

  • Members
  • 7 posts

Posted 01 May 2013 - 11:17 AM

Don't know why the pics fail for you guys. They work just fine for me..

Anyways, here's the direct links:

http://s13.postimg.o...01_17_10_55.png
http://s13.postimg.o...01_17_12_34.png
http://s13.postimg.o...01_17_12_58.png

Thanks for the code, Lua God (mine is not even close to this [lol?]). Gonna try it right away :)

#5 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 01 May 2013 - 11:48 AM

The first and last pictures are fine, the middle one (Code one) is broken)

PS: His name isn't Lua God, that's his title. His name is BigSHinyToys

Your code:
while rs.getInput("back") == true do
    rs.setOutput("right", false)
else
    print("some warning message")
    rs.setOutput("right", true)
    sleep(2)
    rs.setOutput("right", false)
    sleep(2)
end -- while
end

Few problems:
- a while loop has no else block for it
- 1 too many end

What you wanted was this?
Infinite loop that checks the redstone state of the back input. If it is on, it turns it off. If it is off, it prints "some warning message", puts right signal on and puts it off after 2 seconds?

while true do                                            -- infinite loop
    if rs.getInput("back") then                    -- if statement: if <condition> then do this else do that. Same thing as doing if rs.getInput("back") == true
        rs.setOutput("back", false)              -- turn back redstone signal off
    else
        print("Some warning message")      -- print
        rs.setOutput("right", true)                -- set right redstone true
        sleep(2)                                           -- sleep
        rs.setOutput("right", false)               -- set right redstone false
        sleep(2)
    end                                                      -- end if
end                                                          -- end while


#6 PixelMiner

  • Members
  • 7 posts

Posted 01 May 2013 - 12:00 PM

View PostremiX, on 01 May 2013 - 11:48 AM, said:

The first and last pictures are fine, the middle one (Code one) is broken)

Here's the code (don't laugh :D/>)

while rs.getInput ("back") == true do
rs.setOutput ("right", false)
else
rs.setOutput ("right", true)
sleep(2)
rs.setOutput ("right", false)
sleep(2)
end--while
end



View PostremiX, on 01 May 2013 - 11:48 AM, said:

PS: His name isn't Lua God, that's his title. His name is BigSHinyToys
Sorry about that :D

@BigSHinyToys, the code worked partially (I guess). The lamp starts flashing when there's no rs signal, but it won't stop flashing when the rs signal is restored

#7 PixelMiner

  • Members
  • 7 posts

Posted 01 May 2013 - 12:21 PM

View PostremiX, on 01 May 2013 - 11:48 AM, said:

...
What you wanted was this?
Infinite loop that checks the redstone state of the back input....

Yes
If the back input is ON, then the right output is OFF.
If the back input is OFF, then the right output starts flashing (ON/OFF loop) along with a printed message (optional)
If the back input comes ON again, then the right output goes OFF and the back input starts checking the rs state again

#8 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 01 May 2013 - 12:24 PM

View PostPixelMiner, on 01 May 2013 - 12:21 PM, said:

View PostremiX, on 01 May 2013 - 11:48 AM, said:

...
What you wanted was this?
Infinite loop that checks the redstone state of the back input....

Yes
If the back input is ON, then the right output is OFF.
If the back input is OFF, then the right output starts flashing (ON/OFF loop) along with a printed message (optional)
If the back input comes ON again, then the right output goes OFF and the back input starts checking the rs state again

View PostPixelMiner, on 01 May 2013 - 12:21 PM, said:

View PostremiX, on 01 May 2013 - 11:48 AM, said:

...
What you wanted was this?
Infinite loop that checks the redstone state of the back input....

Yes
If the back input is ON, then the right output is OFF.
If the back input is OFF, then the right output starts flashing (ON/OFF loop) along with a printed message (optional)
If the back input comes ON again, then the right output goes OFF and the back input starts checking the rs state again

You can edit your posts by the way :P

Check my code below that?

#9 PixelMiner

  • Members
  • 7 posts

Posted 01 May 2013 - 12:40 PM

Yeah, sorry about the doule post :/

Tried your code and it acts the same way as BigSHinyToys' one. It makes the lamp flashing when there's no rs signal on the back input. But when the rs signal is restored, the lamp wont stop flashing

#10 BigSHinyToys

  • Members
  • 1,001 posts

Posted 01 May 2013 - 01:01 PM

try this
Spoiler
also are you using RP or real readstone might make a difference not shore

#11 PixelMiner

  • Members
  • 7 posts

Posted 01 May 2013 - 01:19 PM

View PostBigSHinyToys, on 01 May 2013 - 01:01 PM, said:

try this
Spoiler
also are you using RP or real readstone might make a difference not shore

Nope, doesn't work. Now the back input is always ON even if the pipe is OFF (no water in it). The lamp doesn't work either.

P.S. ummm.... I'm using red alloy wiring, if that's what you mean by RP

#12 BigSHinyToys

  • Members
  • 1,001 posts

Posted 01 May 2013 - 01:37 PM

what side is what device on ??

#13 BigSHinyToys

  • Members
  • 1,001 posts

Posted 01 May 2013 - 01:43 PM

ok i worked out the probblem
Spoiler


#14 PixelMiner

  • Members
  • 7 posts

Posted 01 May 2013 - 01:52 PM

Back side is connected to a redstone waterproof pipe. The right side is connected to a red lamp.

While the pipe is full of water, it emits a redstone signal and it powers a combustion engine. If there's a water flow failure, the pipe gets empty and it stops emiting redstone signal, and so the engine stops. Now all I need is the back side to do a constant monitoring to that pipe, so when it stop emmiting rs signal, the red lamp on the right side should start flashing. When the pipe gets full again, the lamp should stop flashing.

In a few words - back side is used ONLY to check for rs signal. And when it detects that there's no signal, it should trigger the flashing red lamp, which is connected to the right side. When the rs signal is restored to the back side, the lamp should go off.

Sorry, can't explain it better :/

EDIT:

View PostBigSHinyToys, on 01 May 2013 - 01:43 PM, said:

ok i worked out the probblem
Spoiler

I love you! Exactly what I need! :)
Thankies!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users