0 votes

This is maybe endemic to game development, but I seem to find a dozen articles about how to do everything but what I am trying to do with timers.

Right now my goal is just to get the timer to countdown and the text label to show that happening. I have a gamemager with the timer object and label that now holds a static value of x seconds.

In game manager script I have created the variable so:

onready var Timer : Label = get_node("TurnTimer/TurnTimerLabel")

And that currently static label is in the sidebar UI. I need eventually to have that reset at every end turn when it hits 0 or if the End Turn button is pressed.

But no tutorials I have looked at address this. If I can get this answer it may fill in some blanks about how this all fits together and I could move ahead.

Godot version v3.5.stable.official [991bb6ac7]
in Engine by (21 points)

1 Answer

+1 vote

script label so it gets time_left from timer and displays it in process, whenever timer is not is_stopped or paused.

connect timers timeout signal to the label, and lead it to resetting function on signal receival

connect end_turn button to the same method, so they both have the same effect, making timer stop or paused = true or change its display in label

by (7,447 points)

I appreciate the response it just leave me with more questions.

1 you mean the label gets its own script?

2 What is "process" in this context?

3 does the resetting function go in game manager script?

I have examples for updating labels at end of turn but no examples for continually running one.

If you know any articles I could read about how all of this type of thing connects I would be glad to read it, it seems it should not be this difficult or confusing.

1 and 2. It doesn't matter where it is scripted. The important thing is, that this part of code should be located in process()function. It will be easier to read if it is in solitary script.

3 To reset timer You just make it start() again. It will start counting from wait_time.
You can also pause it and restart it from paused time with paused = true and paused = false

Continual update must always be performed in some process()function. Just get a reference to your timer node, and get its time_left. With this info You can then $Label.text = str(timer.time_left)

If You haven't heard about signals yet, now is the good time to do this :). I recommend Godots documentation, just search for signals.

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.