Godot Version
3 version
Not working high score after exporting to html.Thats my first game so please help me.
3 version
Not working high score after exporting to html.Thats my first game so please help me.
This seems to be a file-accessing issue, please provide more information.
There was an error,when i started exportin and press debug button there was some errors i will send you
When did the error occur, and what then happened? The error message above in the image looks familiar to me, I usually reboot the engine.
This error appears when i click debug button in the export menu, then it was exporting my game everything was fine except my high score system.
Can you talk more about the high score system and how it got wrong?
Okay, when i start my game everything fine, my score goes for example 5 and when my player dies my high score still 0 no saving…
There is my high score system.
extends Node2D
const SPAWN_INTERVAL = 0.4 # Adjust spawn interval as needed
var spawn_timer = 0.0
var can_spawn_bullets = true
onready var deathsound = $Pop
var time_alive: float = 0.0
var running: bool = true
var highscore = 0
signal death_signal
func _ready() -> void:
print("Game started")
deathsound.connect("finished", self,"audio_finished")
highscore = load_highscore()
$Highscore.text = "рекорд: " + str(highscore)
$Timer1.text = str(int(time_alive))
connect("death_signal", self, "_on_Player_death")
set_process(true)
func _process(delta):
spawn_timer += delta
if spawn_timer >= SPAWN_INTERVAL:
spawn_bullet()
spawn_timer = 0.0
if running:
# Increment the time_alive by the time passed since the last frame
time_alive += delta
# Update the Label's text to show the elapsed time in seconds
$Timer1.text = str(int(time_alive))
# Check if high score needs to be updated
if time_alive > highscore:
$Highscore.text = "рекорд: " + str(int(time_alive))
signal fade_out
func spawn_bullet():
if not can_spawn_bullets:
return
var bullet_scene = preload("res://Scenes/Bullet.tscn")
var bullet_instance = bullet_scene.instance()
var viewport_width = get_viewport().size.x
bullet_instance.position.x = rand_range(0, viewport_width)
connect("fade_out", bullet_instance, "fade_out")
get_tree().root.add_child(bullet_instance)
func _on_Player_death():
# Get the current score from Timer1 label
var current_score = $Timer1.text.to_int()
print("Player died with score: ", current_score)
if current_score > highscore:
# Update the high score if the current score is higher
highscore = current_score
print("Updating highscore from ", highscore, " to ", current_score)
save_highscore(highscore)
$Highscore.text = "рекорд: " + str(highscore)
else:
print("No new highscore. Current highscore: ", highscore)
func playerDied(pop_effect_instance) -> void:
print("Player died")
if not deathsound.playing:
deathsound.play()
can_spawn_bullets = false # Stop spawning bullets
add_child(pop_effect_instance)
emit_signal("fade_out")
emit_signal("death_signal")
$AnimationPlayer.play_fade_out()
yield(get_tree().create_timer(3), "timeout")
Bridge.advertisement.show_interstitial()
if not Bridge.advertisement.is_connected("interstitial_state_changed", self, "_on_interstitial_state_changed"):
Bridge.advertisement.connect("interstitial_state_changed", self, "_on_interstitial_state_changed")
if not Bridge.advertisement.is_interstitial_open():
print("Ad not open, changing scene immediately")
get_tree().change_scene("res://Scenes/Menu.tscn")
func audio_finished() -> void:
print("Audio finished")
func save_highscore(highscore: float) -> void:
print("Saving highscore: ", highscore)
var file = File.new()
var err = file.open("user://savefile.dat", File.WRITE)
if err == OK:
file.store_float(highscore)
file.close()
print("Highscore saved successfully: ", highscore)
else:
print("Error saving highscore: ", err)
func load_highscore(default_value: float = 0.0) -> float:
var file = File.new()
if file.file_exists("user://savefile.dat"):
var err = file.open("user://savefile.dat", File.READ)
if err == OK:
var content = file.get_float()
file.close()
print("Loaded highscore: ", content)
return content
else:
print("Error loading highscore: ", err)
else:
print("Save file does not exist, returning default value.")
return default_value
func stop_timer():
running = false
So the high score is not even updated, but saving and loading are fine? Can you show the printed messages?
thanks for replying but i have already make it ! the problem was that i have used another code not this one but i forget so now i fixed it. Thanks for helping !
I’ve been making this kind of ridiculous mistake many times, but I thought you wouldn’t because the issue you talked about seems not to be caused by unnoticed code
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.