Hi, very-new-to-Godot-and-scripting here!
I'm making a 2D platformer.
Short version; I have some variable data in one scene that I want to transfer to another.
More details:
Upon winning the game (critia is to collect 3 coins) I change the scene from Level1.tscn to YouWin.tscn.
In Level1.tscn I have a label for counting how long it took to collect the 3 coins in minutes and seconds, and another label counting how many times the player died before getting the 3 coins.
When the player collects the 3rd coin and gets send to the YouWin.tscn, I would like to display the data from Level1.tscn on how much time was spend and how many times they died.
Just to be clear; I don't want to save this data or store it for some later purpose. I just want to show what it was for that run.
Bonus:
If possible I would like to convert the time (as it is current just text) to a numeric value so I can make some calculation of the score. Like for example the score will be 10,000 minus 'time spend' times 'number of deaths' or something like that.
This is not necessary at all though, so I'm fine with not being able to do it.
(It's just a small project to troll my friends a bit, in case you're wondering why I would make it so weird.)
I have been searching around for a bit and found something about making save/load files but I don't think that will work for me, since the game is going to be uploaded to itch.io. Honestly, I have no idea if this might work for running the game online as well...
I have also attempted some Global singleton things but I haven't managed to make them work as intended.
Here are my scripts;
(I'm a total newbie so these are amalgations of bits and pieces I have found YT tutorials and other QAs)
HUD.gd
extends CanvasLayer
var coins = 0
var deaths = 0
signal game_won
func _ready():
$Coins.text = String(coins)
$Deaths.text = String(deaths)
func _on_coin_collected():
coins = coins + 1
_ready()
if coins == 3:
emit_signal("game_won")
get_tree().change_scene("res://YouWin.tscn")
func _on_Player1_PlayerDead():
deaths = deaths + 1
coins = coins * 0
_ready()
CounterTime.gd
extends Label
var time = 000
var timer_on = true
var time_passed
func _process(delta):
if(timer_on):
time += delta
var secs = fmod(time,60)
var mins = fmod(time, 60*60) / 60
var time_passed = "%02d : %02d" % [mins,secs]
text = time_passed
func _on_HUD_game_won():
print(text) #print proves that the timer stoppes correctly on 'game_won'-signal