![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Suleymanov |
var best_file
var newBest
func _process(delta):
if get_tree().current_scene.name == "TRACK_1":
best_file = "user://best_1.txt"
if get_tree().current_scene.name == "TRACK_2":
best_file = "user://best_2.txt"
#and so on for all 10 tracks...
func _save_best():
var file = File.new()
file.open(best_file, File.WRITE)
file.store_var(newBest)
file.close()
func _load_best():
var file = File.new()
if file.file_exists(best_file):
file.open(best_file, File.READ)
newBest = file.get_var()
file.close()
else:
newBest = newBest
Basically, I want to use a single script for all the scenes and let it find out what scene it is and pick path accordingly. I thought the above written architecture would do the job, but it returns the following error: Invalid type in function "file_exists" in base "_File". Cannot convert argument 1 from Nil to String
.
Though when I make separate scripts with corresponding var best_file = "user://best_n.txt"
, one for each, it works perfectly.
Is there any way to make one script work in all scenes? It should check what scene it is and give the corresponding path.
Thank you for your time!