Godot Version
Godot Engine 4.5
Question
Hello everyone. I can’t figure out how to save the settings to a file, with these settings loaded at the start of the game. Settings by type of screen resolution, full screen mode, and music volume.
I am attaching the script code:
extends Control
var settings = ConfigFile.new()
var resolution_index = 0
var current_display_mode = DisplayServer.WINDOW_MODE_FULLSCREEN
var music_volume_value = -25
var main_theme_index = 0
Called when the node enters the scene tree for the first time.
func _ready() → void:
resolution_index = settings.get_value(“Graphic”,“Resolution”)
current_display_mode = settings.get_value(“Graphic”,“Fullscreen”)
music_volume_value = settings.get_value(“Graphic”,“Resolution”)
get_node(“StartButton”).set_visible(1)
get_node(“MainMenuGroup”).set_visible(0)
pass # Replace with function body.
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _process(_delta: float) → void:
pass
#Блок с кнопкой “Играть”
func _on_play_pressed() → void:
get_tree().change_scene_to_file(“res://TSCN/start.tscn”)
pass # Replace with function body.
#Блок с кнопкой “Настройки”
func _on_settings_pressed() → void:
get_node(“MainMenuGroup”).set_visible(0)
get_node(“SettingsGroup”).set_visible(1)
pass # Replace with function body.
func _on_resolution_item_selected(resolution_index: int) → int:
match resolution_index:
0 :
DisplayServer.window_set_size(Vector2i(2560,1440))
1 :
DisplayServer.window_set_size(Vector2i(1920,1080))
2 :
DisplayServer.window_set_size(Vector2i(1280,720))
return resolution_index # Replace with function body.
func _on_fullscreen_toggled(current_display_mode: bool) → int:
if current_display_mode == false:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
print(“WINDOWED”)
elif current_display_mode == true:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
print(“FULLSCREEN”)
return current_display_mode
func _on_music_slider_value_changed(music_volume_value: int) → int:
get_node(“SettingsGroup/Sound/AudioStreamPlayer”).set_volume_db(music_volume_value)
if music_volume_value <= -40:
get_node(“SettingsGroup/Sound/AudioStreamPlayer”).set_stream_paused(true)
if music_volume_value > -40: get_node(“SettingsGroup/Sound/AudioStreamPlayer”).set_stream_paused(false)
return music_volume_value # Replace with function body.
func _on_main_theme_b_item_selected() → int:
print(“hello world”)
return main_theme_index # Replace with function body.
func _on_back_fs_pressed() → void:
# Сохраните некоторые значения.
settings.set_value(“Graphic”,“Fullscreen”,current_display_mode)
settings.set_value(“Graphic”,“Resolution”,resolution_index)
settings.set_value(“Sound”,“MusicVolume”,music_volume_value)
# Сохраните его в файле (перезапишите, если он уже существует).
settings.save(“res://SAVES/settings.cfg”)
get_node("SettingsGroup").set_visible(0)
get_node("MainMenuGroup").set_visible(1)
pass # Replace with function body.
#Блок с кнопкой “Об авторах”
func _on_about_pressed() → void:
get_node(“MainMenuGroup”).set_visible(0)
get_node(“AboutGroup”).set_visible(1)
pass # Replace with function body.
func _on_back_fa_pressed() → void:
get_node(“MainMenuGroup”).set_visible(1)
get_node(“AboutGroup”).set_visible(0)
pass # Replace with function body.
#Остальные кнопки
func _on_language_pressed() → void:
pass # Replace with function body.
func _on_exit_pressed() → void:
get_tree().quit()
pass # Replace with function body.
func _on_start_button_pressed() → void:
get_node(“StartButton”).set_visible(0)
get_node(“MainMenuGroup”).set_visible(1)
pass # Replace with function body.
(I’m sorry in advance for the stupid moments in the code, I’m just starting my way in programming)



