Score and time at end of the level. help

Godot Version

4.3

Question

I have fully working UI with a singleton to keep information stored just I now to calculate at the end of the level the score, I can get it to transfer time left into the score, but it does it in one go, I want it to countdown the time left and at the same time add that to the score until the time reaches 0?

Here’s the UI code:

extends CanvasLayer

class_name UI


# References 
@onready var Lives = $LIVES
@onready var Score = $SCORE
@onready var Coins = $COINS
@onready var TimeNo = $TIMENO
@onready var WorldNo = $WORLDNO
@onready var Timenode = $Timer
@onready var total_time_seconds : int = 400

@export var WorldName: String

func _ready():
    WorldNo.text = WorldName
    TimeNo.text = str(total_time_seconds)
    total_time_seconds = LevelData.countdown_value


func _process(delta):
    LevelData.countdown_value = total_time_seconds
    update_coin_display(GameManager.coins)
    update_life_display(GameManager.lives)
    update_scored_display(GameManager.score)
    GameManager.gain_coins.connect(update_coin_display)
    GameManager.gain_life.connect(update_life_display)
    GameManager.gain_points.connect(update_scored_display)

    if GameManager.level_finished == true:
    	    finished_level(delta)
	    GameManager.level_finished = false
	    return

func update_scored_display(points_scored):
    Score.text = str(GameManager.score)

func update_coin_display(coins_gained):
    Coins.text = str(GameManager.coins)

func update_life_display(life_gained):
    Lives.text = str(GameManager.lives)

func reset_timer():
    total_time_seconds = 400

func _on_timer_timeout():
    total_time_seconds -= 1
    var m = int(total_time_seconds / 60)
    var s = total_time_seconds + m / 60

    TimeNo.text = "%03d" % s

func finished_level(delta):
    print("connected")
    var countup_score = total_time_seconds
    Timenode.stop()
    GameManager.on_points_scored(countup_score)

A timer is probably overcomplicating this.

const LEVEL_TIME = 400.0
var countdown = LEVEL_TIME
var level_finished = false
var accumulated_time = 0.0

func _process(delta):
    [...]
    if countdown < 0.0:
        # go to victory screen
    countdown -= delta

    if level_finished: # Stop action, score remaining time
        accumulated_time += delta
        if accumulated_time > 1.0:
            accumulated_time -= 1.0
            score += 1
    else: # Not finished, let player do stuff
        [...]

delta is the elapsed time in seconds (or parts thereof). If you want to do something that happens over successive frames, it’s just as easy to keep track of the passage of time in your _process() function.