0 votes

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.

Godot version 3.3.2
in Engine by (20 points)

1 Answer

+1 vote

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.

by (7,190 points)

Thank you do much!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.