Checking is signal emitted

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

I want to make a ,sleeping system" (I don’t know how to name it). It would work like this:

  • If player won’t go to bed before 12 AM he will pass out and label informing about this will appear.
  • If player go to sleep before 12 AM he will sleep normally and any label won’t appear.

I had the idea that it could be done using signals like this:

  • Player click the button that is responsible for going to sleep before 12 AM. Signal which confirms that player went to sleep is emitted so label won’t appear.

  • Player does not click the button so he pass out at 12 AM and label informing about it appears beacous signal isn’t emitted.

So that’s how I imagined it but there’s one problem. I don’t know how to make something that will check is an signal emitted. I thinked maybe it would be an if, but I still don’t know. So can someone tell how to do it or is it even possible? If it can’t be done with signals, how can I do it differently? And also, I use Control scene. Not a Area2D scene or 3D.

Thanks by the way.

:bust_in_silhouette: Reply From: exuin

What you need is a variable to store whether the signal has been emitted or not. Booleans are a type that can only hold two values: true and false. So make a variable like has_slept and initialize it to false. Set it to true if the player clicks the button. Then check that variable when the game reaches 12 AM and act accordingly.

Thank you do much!

NeiPodam | 2021-06-25 17:33