Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | mori_ |
Hello, I am still a complete beginner in Godot and I have this problem. I have a global variable “volume” which will be the one to update the hslider value of my music settings. In my start game scene, I have created a file and a function which will save any change in the music settings.
const SAVE_MUSIC = "user://savemusicsettings.save"
func save_settings():
var save_data = File.new()
save_data.open(SAVE_MUSIC, File.WRITE)
save_data.store_var(Global.volume)
save_data.close()
So I have two music settings, one in the start game scene, and one in the main scene. My goal is that the value of any volume change that happened on the music settings of the start scene will be updated and passed to the music settings of the main scene when it starts. So I also created a load_settings function
func load_settings():
var save_data = File.new()
#need to check if save file exist
if save_data.file_exists(SAVE_MUSIC):
save_data.open(SAVE_MUSIC, File.READ)
Global.volume = save_data.get_var()
save_data.close()
To check if the value of “volume” is updated, I print it in the ready function of the main scene and it is updated but it is not passed on the hslider value of the music settings in the main scene.
func _ready():
load_settings()
$ColorRect/HSlider.value = Global.volume
What could be the problem? Thank you.