Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to add a if Power=false then ?

Asked by
turf23 0
9 years ago

hey guys i was worndering how to add a feature to a fire panel that when the genorator gets turned off the panel beeps and says AC power Trouble here is the panel script for a idea what i mean (the location of the genorator is workspace.Trafo

if not fTrouble then
    fTrouble = true
    coroutine.resume(coroutine.create(function()
        local T;
        if Type == "Panel" then T = "Panel" SetLcd("Panel Trouble! Press Ack to ack",2) end
        if Type == "Alarm" then T = "Alarm" SetLcd("Alarm Trouble! Press Ack to ack",2) end
        if Type == "AC" then T = "AC/POWER" SetLcd("AC/POWER Trouble! Press Ack to ack",2) end
        PanelLcd.Beep:Play()
        repeat
        Indicators.Trouble.BrickColor = BrickColor.new("New Yeller")
        wait(0.15)
        Indicators.Trouble.BrickColor = BrickColor.new("Sand red")
        wait(0.15)      
        until fTrouble == false
        Indicators.Trouble.BrickColor = BrickColor.new("New Yeller")
        SetLcd("System OK, "..T.." Trouble, Press Reset to clear",2)
    end))
end

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

First, tab your code correctly, and write multiple statements on multiple lines.

Next, you should probably just use spawn instead of coroutine.resume(coroutine.create( since it's briefer and clearer.

We have a bunch of code reuse:

        if Type == "Panel" then
            T = "Panel"
            SetLcd("Panel Trouble! Press Ack to ack",2)
        end
        if Type == "Alarm" then
            T = "Alarm"
            SetLcd("Alarm Trouble! Press Ack to ack",2)
        end
        if Type == "AC" then
            T = "AC/POWER"
            SetLcd("AC/POWER Trouble! Press Ack to ack",2)
        end

First, we can make it a little shorter by using elseif. But the bigger thing is by doing what you do later:

        if Type == "Panel" then
            T = "Panel"
        elseif Type == "Alarm" then
            T = "Alarm"
        elseif Type == "AC" then
            T = "AC/POWER"
        end
        SetLcd(T .. " Trouble! Press Ack to ack", 2)

This is a simple mapping from text to text, though, a dictionary might be more appropriate:

        local names = {Panel = "Panel", Alarm = "Alarm", AC = "AC/POWER"}
        local T = names[Type]

Actually, since T and Type are usually the same, we could shorten this, too:

    local names = {AC = "AC/POWER"}
    local T = names[Type] or Type

Your question itself doesn't make much sense. This is a fragment of a script that appears to respond to several types of problems, but we have no idea what causes them or what makes them stop.

It displays the appropriate text, as it is, and it does play a beep sound.

0
do you want me to post the full script its only a snip of the script turf23 0 — 9y
0
I would rather you explain an understandable question and what you have attempted to do so far, and post *all* the *relevant* portions of the full script. BlueTaslem 18071 — 9y
0
im trying to set up a Fire Alarm Panel So that If it Detects that the Genorator Is Off It Beeps And Sets The LCD to AC power Trouble turf23 0 — 9y
0
What does "detect generator is off" mean? BlueTaslem 18071 — 9y
View all comments (2 more)
0
if i turn the power genorator off and the value of power in the genorator =false then trigger the Ac Trouble Alarm turf23 0 — 9y
0
here is an example video of wha i mean https://youtu.be/B3DooEh4ero?t=4m45s turf23 0 — 9y
Ad

Answer this question