0 votes

I have "Track Record", "Current Lap", "Last Lap" and "Best Lap" labels. I got the Current Lap and Last Lap working correctly. But Last Lap (and Best Lap for that matter) gets back to zero once the level (or game) restarted. I need the Last Lap and Best Lap permanently stay there even after the game restarted. I would appreciate any solution you may suggest.

In case you need the script I have:

extends VBoxContainer
var CurrentLap = "Current Lap: "
var LastLap = "Last Lap: "
var BestLap = "Best Lap: "
var ms = 0
var s = 0
var m = 0
func process(delta):
if ms > 9:
s += 1
ms = 0
if s > 59:
m += 1
s = 0
$CurrentLap.set
text(str(CurrentLap) +str(m)+":" +str(s)+":" +str(ms))
func onTimertimeout():
ms += 1
func _on
finishlineareaentered(area):
$LastLap.set_text(str(LastLap) +str(m)+":" +str(s)+":" +str(ms))
m = 0
s = 0
ms = 0

asked Jun 2 in Engine by Suleymanov (55 points)

2 Answers

0 votes
Best answer

Hi,
Store the value in a Global variable.

See here

answered Jun 2 by deaton64 (1,205 points)
selected Jun 3 by Suleymanov

Thanks deaton64!

0 votes

You can save all variables you want with this: https://godotengine.org/qa/44278/need-help-to-figure-out-how-to-sa

answered Jun 7 by MaaaxiKing (291 points)

You are my hero, MaaaxKing! Mega thanks! :D

Nice to hear that ;D

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 How to use this Q&A? before posting your first questions.