Can't make a light switch work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AshTheKindra

So I want to make a FNAF fan game where turning off the power is a mechanic and it’s supposed to be done with a switch. However I can’t figure out how to make it work. I can’t show the code for the switch as I am not at my PC right now but I have gotten frustrated with trying to figure it out so I will do the second best thing to explain how it works in engine. So the Light-switch sprite is a textured button node that when pressed will make a darkened overlay visible indicating that the power is off. However once the power is off, it seems like you can’t click on it again. I have tried different signals, messed around with the settings of the textured button mode but it still didn’t work after one click or you can click it over and over again and have it do absolutely nothing. I don’t know what to do at this point. Should I make it a Kinematic Body instead or am I missing something?

:bust_in_silhouette: Reply From: CharlesMerriam

Hello. Bear with me, I’m guessing at your question.

I think you are saying you made a Button with Toggle Mode on. This allows you to click it once for down, click again for up, a bit like a light switch. You need to connect some code to the toggled() signal, instead of the usual pressed signal. The function you connect to will take a parameter, sort of like:

func on_Lightswitch_toggled(is_on: bool):
     if is_on:
           DarkenedOverlay.hide()   # Lights are on, easy to see
     else:
           DarkenedOverlay.show()  # No lights, look through the shadows

I hope this help. If it does, reply and let me know. Otherwise, please add some code to your question.

Thank you so much! I tried.it out and it worked perfectly!

AshTheKindra | 2022-05-26 10:42