I am making a mario game and i have it where you can load level 1 scene and can go into the 2 underground area scenes that i set but when the level starts the timer starts on the top counting down from 400 but once i go into a pipe it resets to 400 and when i leave that underground scene and go back to main part of the level it resets it aswell.
i need a way to make the timer start only once when level is loaded into from the world map and keep going until player reaches the end goal of the level even when going to the underground scenes aswell to keep ticking down? (and have this work with other levels once made.)
I take it the counter that displays the remaining time is a scene, and that both over- and under world use an instance of that counter scene? And that 400 is some sort of default value?
When you enter the pipe from the overworld into the underworld, you’re likely switching scenes. The former is unloaded, and the latter is loaded. You need to add code that can store the remaining time, and you need to edit the counter so that it can retrieve that stored time when the counter object enters the scene tree.
Make a new scene and set a Node as its root node. Rename the root node CountdownManager. Add this script to CountdownManager:
extends Node
@extends var countdown_value : int = 0
If you make that script an autoload, you can access it from any other scene. For instance, you can access it from the warp pipe scene. When the player goes down the warp pipe, simply get your current countdown value and store it in the autoload.
In your counter scene, simply get the data from the autoload on ready:
# counter.gd
func _ready()->void:
value = CountdownManager.countdown_value