score snake
Kandif
plain_text
3 years ago
863 B
27
Indexable
extends Node const SAVE_FILE_PATH = "user://savedata.save" const score_text = "SCORE: " const high_score_text = "HIGH SCORE: " var highscore = 0 func _ready(): load_score() func load_score(): var load_data = File.new() if load_data.file_exists(SAVE_FILE_PATH): load_data.open_encrypted_with_pass(SAVE_FILE_PATH,File.READ,"cokolwiek") var content = load_data.get_as_text() highscore = int(content) load_data.close() $HighScore.text = high_score_text+str(highscore) func save_score(): var save_data = File.new() save_data.open_encrypted_with_pass(SAVE_FILE_PATH,File.WRITE,"cokolwiek") save_data.store_string(str(highscore)) save_data.close() func update_score(score): $Score.text = score_text+str(score) func check_highscore(score): if score>highscore: highscore = score save_score() $HighScore.text = high_score_text+str(score)
Editor is loading...