Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to add a if Power=false then ?

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

✓ Accepted answer

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.

6 comments

0

do you want me to post the full script its only a snip of the script

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.

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

0

What does "detect generator is off" mean?

0

if i turn the power genorator off and the value of power in the genorator =false then trigger the Ac Trouble Alarm

0

here is an example video of wha i mean https://youtu.be/B3DooEh4ero?t=4m45s

This discussion is preserved as it was. New answers, comments, and votes are closed.