Timer if pressed +5 seconds and max 30 seconds

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

Please i am new in godot, i watched many tutorial read alot coding but need Help.
(Please with script if possible)

I want to make a Simple Timer and want to Display it but fail very hard
It’s for a One Screen Mobile Game

If Start The Game there should be 30 seconds (it runs down) on the Timer (and never more than 30 seconds) and if you press the specific Button then the Timer should add +5 seconds until the Timer runs ou (Timeout = Game Over)

please help i am big noob :confused: this game my dream i need alot help

:bust_in_silhouette: Reply From: jgodfrey

Here’s one way.

First, create a new scene with this structure:


Add this script to the Control node:

extends Control

var maxTime = 30
var timeLeft = maxTime

func _process(delta):
	if timeLeft > 0:
		timeLeft -= delta
		$Label.text = str(timeLeft)
		timeLeft = 0
		$Label.text = "Game Over"

func _on_Button_pressed():
	if timeLeft > 0:
		timeLeft += 5
		if timeLeft > maxTime:
			timeLeft = maxTime

Finally, connect the Button's pressed event to the script’s _on_Button_pressed() method.

Thank you very much!!!

But another little problem.
The Timer count is 30.0000000
how can i make it on 30

Rayu | 2020-11-06 14:47

Something like this should work to format the value to a whole number:

$Label.text = "%d" % timeLeft

jgodfrey | 2020-11-06 15:07

you are awesome, thank you very much

Rayu | 2020-11-06 15:11