First game,localization bug,please help!

Godot Version

3

Hi,in my game my high score localization works bad this is code.

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
var leaderboard_name = "bestscore"

func _on_interstitial_state_changed(state):
	if state == "closed" or state == "failed":
		BgMusic.set_stream_paused(false)
		get_tree().change_scene("res://Scenes/Menu.tscn")
	elif state == "opened":
		BgMusic.set_stream_paused(true)
	else:
		BgMusic.set_stream_paused(false)
		
signal death_signal

func _ready() -> void:
	Bridge.platform.language = "ru"
	print("Game started")
	print(Bridge.platform.language)

	if Bridge.platform.language == "ru":
		print("Setting highscore label to Russian")
		$Highscore.text = "рекорд: " + str(highscore)
	elif Bridge.platform.language == "en":
		print("Setting highscore label to English")
		$Highscore.text = "highscore: " + str(highscore)	

	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")
	deathsound.connect("finished", self, "audio_finished")
	Bridge.game.connect("visibility_state_changed", self, "_on_visibility_state_changed")
	highscore = load_highscore()

	if Bridge.platform.language == "ru":
		print("Setting highscore label to Russian again after loading highscore")
		$Highscore.text = "рекорд: " + str(highscore)
	elif Bridge.platform.language == "en":
		print("Setting highscore label to English again after loading highscore")
		$Highscore.text = "highscore: " + str(highscore)

	$Timer1.text = str(int(time_alive))
	connect("death_signal", self, "_on_Player_death")
	set_process(true)

func _on_visibility_state_changed(state):
	if state == "hidden":
		BgMusic.set_stream_paused(true)
	else:
		BgMusic.set_stream_paused(false)	

func _process(delta):
	spawn_timer += delta
	if spawn_timer >= SPAWN_INTERVAL:
		spawn_bullet()
		spawn_timer = 0.0
	if running:
		time_alive += delta
		$Timer1.text = str(int(time_alive))

		if time_alive > highscore:
			if Bridge.platform.language == "ru":
				$Highscore.text = "рекорд: " + str(highscore)
			elif Bridge.platform.language == "en":
				$Highscore.text = "highscore: " + str(highscore)

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():
	var current_score = $Timer1.text.to_int()
	print("Player died with score: ", current_score)
	if current_score > highscore:
		highscore = current_score
		print("Updating highscore to: ", current_score)
		save_highscore(highscore)
		if Bridge.platform.language == "ru":
			$Highscore.text = "рекорд: " + str(highscore)
		elif Bridge.platform.language == "en":
			$Highscore.text = "highscore: " + 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
	add_child(pop_effect_instance)
	emit_signal("fade_out")
	emit_signal("death_signal")
	$AnimationPlayer.play_fade_out()
	yield(get_tree().create_timer(3), "timeout")
	emit_signal("player_died_signal")
	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

In console it prints “en” so it must be english but beside this there is more bug in my russian version there is no number next to my text “high score” .

I dont know why but the problem was in the godot there it appears with bugs but in the web platform everything works perfectly.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.