–1 vote

I want a timer to have a countdown that changes the scene when it reaches 0

in Engine by (19 points)

3 Answers

0 votes

The question is? ;-)

I guess you a searching for a hint how to do it. Here it is:

There is a Timer node. Just use it. Put it in a scene that you load as a singleton. (See Project settings Autoload)

Just like you would do with background music that runs independent of scene changes.

If the question was "Do the all the programming for me, I don't want to read." then sorry, that this wasn't the answer.

by (3,350 points)

That was so sarcastically useful. signal aren't as trivial as an experimented user of godot might think. And using a singleton is even more complex for something as functionally simple as "change scene after a timer" (eg : a splash/title screen).

so i added an actual "i'll do your homework" (with code) answer, because this isn't a competition.

Sorry for being sarcastic at times. I just think that when people ask a favor of other people it might be justified to put some more effort in writing the question than just saying "I want".

I understand that englisch isn't the mother tongue of every writer (it isn't mine as well) and I understand that you sometimes need a pointer where to start.

Thank you for posting an answer with details & code. I also think (and forgot it beforehand) that this will be helpful for other people who are searching for an answer to that question.

Thank you for your understanding :)

Questions like this would certainly get a downvote if it was posted on StackOverflow.
Beginners need to learn how to spend some time and effort before asking a question.
I agree with your answer, as you have provided a high level solution to OP's question.

Aren't we glad this is not stackoverflow then ? :D
Considering the current state of godot, the simple fact that the OP is using it instead for unity is, imho, already a show of goodwill to learn.
If one wanted their homework done for them, they would unity because their homework has already been done and posted multiple time everywhere. That's what make unity the industry standard of indy game.

0 votes

Doing this will be simple!

Get the timer node

Connect the on timed out signal

and under the timed out function (from the signal ) put your line of code that changes the scene

by (709 points)
+1 vote

Since it have a good rank on google i'll answer it, the reference documentation doesn't have an exemple and it require to understand signaling.

extends Control

var timer = null

# Called when the node enters the scene tree for the first time.
func _ready():
    timer = Timer.new()
    timer.connect("timeout", self, "on_timeout")

func on_timeout():

in timer.connect() the first argument is the signal (the only signal Timer is emitting is "timeout". Self it the receiver of the signal, and ontimeout is a function name of your choice, i called it "ontimeout" but could have been anything.

And in this function call the change_scene code.

by (16 points)
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 Frequently asked questions and 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 [email protected] with your username.