How to save and load audio on/off setting?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tehgaming

Hi all. I am trying to create an audio on and off option for my game. I managed to figure out how to code the options but no idea how to save/load them so that the setting is retained when the player closes the game and reopens it. I actually also need help on how to save/load show() and hide() of the on and off buttons (so that the on button is hidden after it is pressed and the off button is shown instead).

Appreciate you help. Thanks! :slight_smile:

I have used that successfully for saving other things like highscore but the reason why I am asking here is because I don’t quite get how to save show() hide() audio off calls. Sorry, I should have also explained that I am not a programmer and I am a newbie in this.

tehgaming | 2022-02-13 08:49

:bust_in_silhouette: Reply From: rossunger

Create a global variable that keeps track of whether audio is on or off, and then when you load the game you check that variable and call hide or show as needed

Thanks. I thought of another idea and it works as well. I hope it’s not bad practice;

audio = true
#save audio boolean value

func _ready():
#load audio boolean value

if audioon == true:
#master_sound on
audioon_button.hide() 		
audiooff_button.show() 	
else: 		    
#master_sound off   
audioon_button.show() 		
audiooff_button.hide()

tehgaming | 2022-02-14 04:03