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
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.